Skip to content

Conversation

@saifsultanc
Copy link
Contributor

…ch Child Entries to Parent when Editing via GP Entry Blocks.
@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Introduces a PHP snippet that hooks into gpnf_set_parent_entry_id to set the Nested Forms child entry’s parent ID from the edit_entry request parameter when editing via GP Entry Blocks. If edit_entry is present, it overrides the parent ID; otherwise, the original ID passes through.

Changes

Cohort / File(s) Summary of Changes
GPNF auto-attach via GP Entry Blocks
gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php
Adds a filter callback to gpnf_set_parent_entry_id that reads rgget('edit_entry') and conditionally overrides the parent entry ID before returning it.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant GP Entry Blocks
  participant GPNF
  participant Snippet

  User->>GP Entry Blocks: Submit child form (with edit_entry)
  GP Entry Blocks->>GPNF: Process child entry
  GPNF->>Snippet: gpnf_set_parent_entry_id(parentId)
  Snippet->>Snippet: Check rgget('edit_entry')
  alt edit_entry present
    Snippet-->>GPNF: Return edit_entry as parentId
  else
    Snippet-->>GPNF: Return original parentId
  end
  GPNF->>GP Entry Blocks: Attach child to parent entry
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested reviewers

  • veryspry
✨ 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/87427-add-gpeb-gpnf

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.

@github-actions
Copy link

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

Generated by 🚫 dangerJS against 79436ec

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: 2

🧹 Nitpick comments (2)
gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php (2)

12-17: Consider setting an explicit filter priority to ensure final override

If other code also filters gpnf_set_parent_entry_id, bumping priority slightly helps this run after defaults.

Apply this diff:

-} );
+}, 20 );

2-11: Docblock: call out Entry Blocks requirement and docs link

Minor clarity improvement for future readers scanning the snippet.

Apply this diff:

 /**
  * Gravity Perks // Nested Forms // Auto-attach Child Entries to Parent when Editing via GP Entry Blocks.
  * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
  *
  * By default, when adding a new child entry to a Nested Form field while editing a parent entry via GP Entry Blocks, the
  * child entry is saved to the session and will not be attached to the parent entry unless you click "Update" on the
  * parent entry form.
  *
  * Use this snippet to automatically attach the child entry to the parent as soon as the child form is submitted.
+ * Requires: Gravity Perks Entry Blocks (GP Entry Blocks).
+ * Docs: https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 453ad6a and 79436ec.

📒 Files selected for processing (1)
  • gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php (1 hunks)
🔇 Additional comments (1)
gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php (1)

1-17: LGTM functionally — minimal snippet achieves the intended behavior

The approach mirrors existing patterns in the library and should attach child entries immediately during Entry Blocks edits.

Comment on lines +12 to +17
add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
if ( rgget( 'edit_entry' ) ) {
$parent_entry_id = rgget( 'edit_entry' );
}
return $parent_entry_id;
} );
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Sanitize and type-cast edit_entry; avoid double rgget to prevent accidental 0 parent IDs

Cast to int once and reuse. This prevents non-numeric values from coercing to 0 and unintentionally overriding the parent ID.

Apply this diff:

-add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
-	if ( rgget( 'edit_entry' ) ) {
-		$parent_entry_id = rgget( 'edit_entry' );
-	}
-	return $parent_entry_id;
-} );
+add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
+	$edit_entry = absint( rgget( 'edit_entry' ) );
+	if ( $edit_entry ) {
+		$parent_entry_id = $edit_entry;
+	}
+	return $parent_entry_id;
+} );
📝 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
add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
if ( rgget( 'edit_entry' ) ) {
$parent_entry_id = rgget( 'edit_entry' );
}
return $parent_entry_id;
} );
add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
$edit_entry = absint( rgget( 'edit_entry' ) );
if ( $edit_entry ) {
$parent_entry_id = $edit_entry;
}
return $parent_entry_id;
} );
🤖 Prompt for AI Agents
In gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php around lines 12 to
17, the current code calls rgget('edit_entry') twice and does not
sanitize/type-cast the value; change it to read rgget('edit_entry') once into a
variable, check if it is non-empty, cast it to (int) and then assign to
$parent_entry_id only when the cast result is > 0 to avoid accidentally
overriding a valid parent ID with 0 from non-numeric input.

💡 Verification agent

🧩 Analysis chain

Verify “edit_entry” is the correct GP Entry Blocks param across this repo

Double-check consistency with existing snippets (e.g., gpeb-remove-fields-on-edit.php) and usages to avoid mismatched query params.

Run this script to confirm:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Searching for existing snippets referencing edit_entry…"
rg -n "rgget\(\s*'edit_entry'\s*\)" -A 2 || true

echo
echo "Locating gpeb-remove-fields-on-edit.php (if present) and printing its contents…"
fd -i -a gpeb-remove-fields-on-edit.php | while read -r f; do
  echo "---- $f ----"
  sed -n '1,200p' "$f"
done

echo
echo "Search for query param name patterns possibly used by Entry Blocks:"
rg -n "(edit_entry|edit\-entry|entry_id|entry-id|eid)" -A 2 || true

Length of output: 96754


Standardize on the GP Entry Blocks query parameter

The only occurrence of rgget('edit_entry') is in gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php, but all other Entry Blocks snippets expect the standard gpeb_entry_id parameter. Update this hook to read the correct param (or support both for backward compatibility).

Locations to update:

  • gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php (lines 12–17)

Proposed change:

 add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
-   if ( rgget( 'edit_entry' ) ) {
-       $parent_entry_id = rgget( 'edit_entry' );
-   }
+   // Use the standard GP Entry Blocks parameter
+   $entry_id = rgget( 'gpeb_entry_id' ) ?: rgget( 'edit_entry' );
+   if ( $entry_id ) {
+       $parent_entry_id = $entry_id;
+   }
    return $parent_entry_id;
} );
📝 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
add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
if ( rgget( 'edit_entry' ) ) {
$parent_entry_id = rgget( 'edit_entry' );
}
return $parent_entry_id;
} );
add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) {
// Use the standard GP Entry Blocks parameter
$entry_id = rgget( 'gpeb_entry_id' ) ?: rgget( 'edit_entry' );
if ( $entry_id ) {
$parent_entry_id = $entry_id;
}
return $parent_entry_id;
} );
🤖 Prompt for AI Agents
In gp-nested-forms/gpnf-gpeb-auto-attach-child-entries.php around lines 12 to
17, the hook currently reads rgget('edit_entry') but other Entry Blocks use the
standard gpeb_entry_id param; change the logic to read gpeb_entry_id first and
fall back to edit_entry for backward compatibility (i.e., if
rgget('gpeb_entry_id') is present use that, otherwise use rgget('edit_entry')),
then return the resolved parent_entry_id.

@saifsultanc saifsultanc merged commit ae58d74 into master Aug 21, 2025
3 of 4 checks passed
@saifsultanc saifsultanc deleted the saif/add/87427-add-gpeb-gpnf branch August 21, 2025 04:58
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.

2 participants