-
Notifications
You must be signed in to change notification settings - Fork 92
gw-search-by-form-id.php: Added new snippet.
#1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughAdds a Gravity Forms filter that lets the form list search accept numeric form IDs: when the search query is numeric, the code fetches the matching form via GFAPI and appends a minimal form object to the results if it isn't already present. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (2)
gravity-forms/gw-search-by-form-id.php (2)
20-20: Consider using strict comparison.While type juggling isn't a practical issue here since both values are integers, using
in_array( $search_id, $form_ids, true )follows best practices.🔎 Proposed fix
- if ( ! in_array( $search_id, $form_ids ) ) { + if ( ! in_array( $search_id, $form_ids, true ) ) {
25-27: Improve array/object handling.The ternary pattern
isset( $form['id'] ) ? $form['id'] : $form->idassumes that if it's not an array with the key, it must be an object with the property. If$formis an array without the expected key, accessing$form->idwill trigger a PHP notice.Consider a more defensive approach that handles both array and object types explicitly.
🔎 Proposed fix
- $form_obj->id = isset( $form['id'] ) ? $form['id'] : $form->id; - $form_obj->title = isset( $form['title'] ) ? $form['title'] : $form->title; - $form_obj->is_active = isset( $form['is_active'] ) ? $form['is_active'] : $form->is_active; + $form_obj->id = is_array( $form ) ? $form['id'] : $form->id; + $form_obj->title = is_array( $form ) ? $form['title'] : $form->title; + $form_obj->is_active = is_array( $form ) ? $form['is_active'] : $form->is_active;
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gravity-forms/gw-search-by-form-id.php
🧰 Additional context used
🪛 GitHub Actions: PHP Lint (PR)
gravity-forms/gw-search-by-form-id.php
[warning] 24-24: Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space (source: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
[warning] 25-25: Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space (source: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
[warning] 26-26: Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space (source: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
[warning] 27-27: Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space (source: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
[warning] 29-29: Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space (source: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
[warning] 30-30: Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space (source: Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
[error] 1-1: PHPCS: Command failed. ./vendor/bin/phpcs --report=checkstyle --standard=phpcs.xml gravity-forms/gw-search-by-form-id.php
🪛 GitHub Check: PHPCS (Files Changed)
gravity-forms/gw-search-by-form-id.php
[warning] 30-30:
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space
[warning] 29-29:
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
[warning] 27-27:
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
[warning] 26-26:
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
[warning] 25-25:
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space
[warning] 24-24:
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space
🔇 Additional comments (3)
gravity-forms/gw-search-by-form-id.php (3)
1-8: LGTM!The file header and documentation clearly describe the snippet's purpose.
9-13: LGTM!The early return logic correctly filters out non-numeric search queries. The use of
is_numeric()appropriately handles string-based numeric input from search forms.
34-34: LGTM!The return statement correctly returns the augmented forms array.
Context
💬 Slack: https://gravitywiz.slack.com/archives/D053MA45RRA/p1766491895791489
Summary
This snippet adds the ability to search by form ID when searching forms in the admin area.