-
Notifications
You must be signed in to change notification settings - Fork 93
gpeb-remove-fields-on-edit.php
: Added logic to remove pages on GPEB edit.
#1147
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughIntroduces a conditionalLogic assignment for page-type fields marked with gpeb-remove-on-edit, while retaining the existing behavior of setting such fields’ visibility to administrative. Only page fields with the class gain a dummy conditional rule; other fields remain unchanged. Changes
Sequence Diagram(s)sequenceDiagram
participant Renderer as Form Renderer
participant Field as Field (iterated)
Renderer->>Field: Check class "gpeb-remove-on-edit"
alt Field has class
Renderer->>Field: Set visibility = "administrative"
alt Field type == "page"
Renderer->>Field: Set conditionalLogic = dummy rule (never matches)
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 1
🧹 Nitpick comments (3)
gp-entry-blocks/gpeb-remove-fields-on-edit.php (3)
35-35
: Minor typo in comment"It's" is the correct contraction for "it is".
- // For pages, we add conditional logic if its marked for removal. + // For pages, add conditional logic if it's marked for removal.
30-37
: Avoid duplicate class lookups and make class matching saferYou’re calling strpos on cssClass twice. Cache it and match with word boundaries to avoid partial matches. Also safely handle potential unset/empty cssClass and use strict comparison for type.
- foreach ( $form['fields'] as &$field ) { - if ( strpos( $field->cssClass, 'gpeb-remove-on-edit' ) !== false ) { - $field->visibility = 'administrative'; - } + foreach ( $form['fields'] as &$field ) { + $css_class = isset( $field->cssClass ) ? (string) $field->cssClass : ''; + $remove_on_edit = strpos( " $css_class ", ' gpeb-remove-on-edit ' ) !== false; + + if ( $remove_on_edit ) { + $field->visibility = 'administrative'; + }And below:
- if ( $field->type == 'page' && strpos( $field->cssClass, 'gpeb-remove-on-edit' ) !== false ) { + if ( $field->type === 'page' && $remove_on_edit ) {Also applies to: 36-36
6-6
: Update header docs to reflect page removal behaviorThe snippet now also hides pages. Update comments to align with current behavior and usage.
- * Remove fields from the Entry Blocks edit form by automatically setting the field's visibility to "administrative". + * Remove fields and pages from the Entry Blocks edit form by automatically setting the field's visibility to "administrative" + * and hiding marked pages via conditional logic. - * 2. Add the "gpeb-remove-on-edit" class to the Custom CSS Class field setting for any field you want to remove from - * the edit form. + * 2. Add the "gpeb-remove-on-edit" class to the Custom CSS Class field setting for any field or page you want to remove from + * the edit form.Also applies to: 13-15
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled
You can enable these settings in your CodeRabbit configuration.
📒 Files selected for processing (1)
gp-entry-blocks/gpeb-remove-fields-on-edit.php
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: PHPCS (Files Changed)
gp-entry-blocks/gpeb-remove-fields-on-edit.php
[failure] 46-46:
Each array item in a multi-line array declaration must end in a comma
[failure] 45-45:
Each array item in a multi-line array declaration must end in a comma
[failure] 44-44:
Each array item in a multi-line array declaration must end in a comma
🪛 GitHub Actions: PHP Lint (PR)
gp-entry-blocks/gpeb-remove-fields-on-edit.php
[error] 44-44: PHPCS error: WordPress.Arrays.CommaAfterArrayItem.NoComma - Each array item in a multi-line array declaration must end in a comma.
🔇 Additional comments (2)
gp-entry-blocks/gpeb-remove-fields-on-edit.php (2)
35-48
: Confirm safety of referencing a non-existent fieldId in conditional logicUsing a dummy fieldId (9999) should evaluate to false and hide the page as intended. However, please verify across supported GF versions that this does not trigger JS console errors in conditional logic evaluation on the edit form.
Verification checklist:
- Open a GPEB edit form with a page marked gpeb-remove-on-edit.
- Confirm the page is hidden.
- Check browser console for errors related to conditional logic.
- Submit the edit to ensure server-side processing (gform_pre_process) isn’t affected.
35-48
: Concept ACK: solid approach for removing pages on editUsing page-level conditional logic with a never-true rule to hide pages during GPEB edit is a pragmatic solution that avoids broader form-level side effects.
'value' => 'hide' | ||
) | ||
) |
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.
Fix trailing commas to satisfy PHPCS and unblock the pipeline
PHPCS is failing with "Each array item in a multi-line array declaration must end in a comma" for these lines. Add trailing commas after the last items in the nested arrays.
Apply this diff:
- 'value' => 'hide'
- )
- )
+ 'value' => 'hide',
+ ),
+ ),
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
'value' => 'hide' | |
) | |
) | |
'value' => 'hide', | |
), | |
), |
🧰 Tools
🪛 GitHub Check: PHPCS (Files Changed)
[failure] 46-46:
Each array item in a multi-line array declaration must end in a comma
[failure] 45-45:
Each array item in a multi-line array declaration must end in a comma
[failure] 44-44:
Each array item in a multi-line array declaration must end in a comma
🪛 GitHub Actions: PHP Lint (PR)
[error] 44-44: PHPCS error: WordPress.Arrays.CommaAfterArrayItem.NoComma - Each array item in a multi-line array declaration must end in a comma.
🤖 Prompt for AI Agents
In gp-entry-blocks/gpeb-remove-fields-on-edit.php around lines 44 to 46 the
multi-line array items are missing trailing commas which fails PHPCS; add
trailing commas after the last items in the nested arrays (e.g., after 'hide'
and after the closing parent array entries) so each multi-line array element
ends with a comma and the PHPCS rule is satisfied.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/3032041282/87642
Summary
Remove pages when using the snippet. Just add the same class
gpeb-remove-on-edit
on the page field.Demo and discussion:
https://www.loom.com/share/4d1b5f0cca3a4d9ba8eedc28e4ff34e0