Skip to content

Conversation

@SebastianWiz
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/3146079791/93861

Summary

This is a user submitted snippet by Dennis Hunink. The snippet automatically filters posts by the current WPML language.

@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces a new PHP filter for Gravity Forms Populate Anything that restricts input choices to those matching the current WPML language when a field has the CSS class wpml-limit-to-current-language. Includes early-return guards for when WPML is unavailable, the class is absent, or current language isn't determined.

Changes

Cohort / File(s) Change Summary
WPML Language Filtering for GPPA
gp-populate-anything/gppa-wpml-current-language-choices.php
New filter hook hb_wpml_limit_gppa_choices_to_current_language added and attached via add_filter('gppa_input_choices', ...). Function checks WPML availability, looks for the wpml-limit-to-current-language CSS class on the field, obtains the current WPML language, resolves each choice's post_id/post_type (from $objects or choice value), determines each element's language via WPML APIs, and returns only choices matching the active language.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify WPML API calls (icl_object_id, wpml_current_language, wpml_element_type, wpml_element_language_code) are used correctly.
  • Confirm iteration handles both post objects in $objects and fallback post ID resolution.
  • Ensure early-return guards prevent filtering when WPML or CSS marker is absent.

Suggested reviewers

  • veryspry

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: automatically filtering posts by current WPML language in the new GPPA snippet.
Description check ✅ Passed The description includes the required Context section with a Help Scout ticket and a Summary section explaining the snippet's purpose, though the Notion and Slack sections are appropriately omitted.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e62f3ad and 07d4914.

📒 Files selected for processing (1)
  • gp-populate-anything/gppa-wpml-current-language-choices.php (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

Fails
🚫

Pull request title does match the correct format. The Pull Request title should match our Snippet Library Pull Request Title Guidelines in Notion.

🚫

Commit message 'gppa-wpml-current-language-choices.php: Automatically filter posts by current WPML language.' does match the correct format. See our Snippet Library Commit Messages Guidelines in Notion.

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against e62f3ad

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf09632 and e62f3ad.

📒 Files selected for processing (1)
  • gp-populate-anything/gppa-wpml-current-language-choices.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-30T13:53:21.893Z
Learnt from: veryspry
Repo: gravitywiz/snippet-library PR: 1077
File: gravity-forms/gw-require-alt-text-description-post-image.php:23-32
Timestamp: 2025-05-30T13:53:21.893Z
Learning: In Gravity Forms snippets, use 'gravityforms' as the translation domain for internationalization functions instead of creating custom domains, to maintain consistency with the related plugin.

Applied to files:

  • gp-populate-anything/gppa-wpml-current-language-choices.php
🪛 GitHub Actions: PHP Lint (PR)
gp-populate-anything/gppa-wpml-current-language-choices.php

[error] 36-36: PHPCS: Short array syntax is not allowed. Generic.Arrays.DisallowShortArraySyntax.Found.

🪛 GitHub Check: PHPCS (Files Changed)
gp-populate-anything/gppa-wpml-current-language-choices.php

[failure] 67-67:
Short array syntax is not allowed


[failure] 36-36:
Short array syntax is not allowed

🪛 PHPMD (2.15.0)
gp-populate-anything/gppa-wpml-current-language-choices.php

18-18: Avoid unused parameters such as '$field_values'. (undefined)

(UnusedFormalParameter)

🔇 Additional comments (6)
gp-populate-anything/gppa-wpml-current-language-choices.php (6)

1-15: Clear documentation and instructions.

The header documentation clearly explains the snippet's purpose and provides actionable setup instructions for users.


16-16: Hook registration looks correct.

The filter is properly registered with the appropriate callback, priority, and parameter count.


18-22: Good defensive check for WPML availability.

The early return when WPML is not active prevents errors. The unused $field_values parameter flagged by PHPMD is acceptable since it's part of the hook signature.


24-28: Correct CSS class detection with proper early return.

The use of strpos with strict comparison === false correctly handles all edge cases for string position checking.


30-34: Proper WPML language detection with safety check.

Using the wpml_current_language filter is the correct approach, and the early return handles cases where language detection might fail.


83-83: Clean return of filtered results.

The function correctly returns the filtered choices array.

@saifsultanc saifsultanc merged commit 98ac90e into master Dec 5, 2025
1 of 3 checks passed
@saifsultanc saifsultanc deleted the SebastianWiz-patch-1 branch December 5, 2025 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants