Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saifsultanc
Copy link
Contributor

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

Copy link

coderabbitai bot commented Aug 14, 2025

Walkthrough

Introduces 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

Cohort / File(s) Summary
Entry Blocks removal logic update
gp-entry-blocks/gpeb-remove-fields-on-edit.php
Retains setting visibility to administrative for fields with class gpeb-remove-on-edit. Adds conditionalLogic to page-type fields with that class using a never-matching dummy rule (fieldId 9999, operator "is", value "hide", actionType "show", logicType "all").

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
Loading

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch saif/add/87642-add-remove-pages-gpeb

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

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

Generated by 🚫 dangerJS against d3236d4

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

🧹 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 safer

You’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 behavior

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58314e5 and d3236d4.

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

Using 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 edit

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

Comment on lines +44 to +46
'value' => 'hide'
)
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
'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.

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.

1 participant