Skip to content

Conversation

@matty0501
Copy link
Contributor

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.

@coderabbitai
Copy link

coderabbitai bot commented Dec 23, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds 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

Cohort / File(s) Summary
Gravity Forms Search Enhancement
gravity-forms/gw-search-by-form-id.php
Adds add_filter( 'gform_form_list_forms', ... , 10, 6 ) anonymous callback that, for numeric search_query, resolves the absolute int ID, checks current results, fetches the form via GFAPI::get_form, builds a minimal stdClass (id, title, is_active, entry_count, view_count) and appends it to $forms when found.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • saifsultanc

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a new snippet file with a descriptive name.
Description check ✅ Passed The description includes the required Context and Summary sections from the template and explains the functionality clearly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05f95f8 and cf07b18.

📒 Files selected for processing (1)
  • gravity-forms/gw-search-by-form-id.php

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 23, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.
Messages
📖 Merlin would give this scroll the highest of praises. Cheers for adding this new snippet to the library! 🪄

Generated by 🚫 dangerJS against cf07b18

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: 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->id assumes that if it's not an array with the key, it must be an object with the property. If $form is an array without the expected key, accessing $form->id will 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

📥 Commits

Reviewing files that changed from the base of the PR and between dc7ece6 and 05f95f8.

📒 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.

@saifsultanc saifsultanc merged commit d1227ba into master Dec 27, 2025
2 of 4 checks passed
@saifsultanc saifsultanc deleted the matty0501-patch-2 branch December 27, 2025 11:10
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