Skip to content

Conversation

saifsultanc
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/2960107602/84668

Summary

Using Gravity Flow Form Connector to create entries on Form A when Form B is submitted.

Form A also has a GCGS feed, however, when entries are created using Gravity Flow, the GCGS feed is not running.

This snippet adds support for that.

Demo:
https://www.loom.com/share/7c5b3b5e286648538bf4a2326333f4d7

…snippet to process GCGS Feeds post Gravity Flow Form Connector New Entry.
Copy link

coderabbitai bot commented Jun 10, 2025

Walkthrough

A new PHP script is added to integrate Google Sheets feed processing with the Gravity Flow Form Connector. It hooks into the event triggered after a new entry is created, checks conditions, and then processes the relevant Google Sheets feed using the entry and form data.

Changes

File(s) Change Summary
gc-google-sheets/gcgs-process-feed-on-gravityflowformconnector-new-entry.php Introduced a script that hooks into the new entry event from Gravity Flow Form Connector to process Google Sheets feeds.

Sequence Diagram(s)

sequenceDiagram
    participant GravityFlowFormConnector
    participant HookedCallback
    participant GoogleSheetsIntegration

    GravityFlowFormConnector->>HookedCallback: gravityflowformconnector_post_new_entry($new_entry_id, $entry, $form, $step)
    HookedCallback->>HookedCallback: Check if gc_google_sheets exists and step type is 'new_entry'
    alt Conditions Met
        HookedCallback->>GoogleSheetsIntegration: maybe_process_feed($entry, $form)
        HookedCallback->>GoogleSheetsIntegration: feed_processor->save()
        HookedCallback->>GoogleSheetsIntegration: feed_processor->dispatch()
    end
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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 caf4e29

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 (3)
gc-google-sheets/gcgs-process-feed-on-gravityflowformconnector-new-entry.php (3)

1-8: Add comprehensive PHPDoc block
The file‐level docblock is missing standard tags like @package, @since, and @link to align with WordPress PHPDoc conventions.


9-9: Avoid anonymous callback for hook
Using an anonymous function makes it impossible to unhook or test in isolation. Define a named function and pass its name to add_action instead.


13-14: Limit dispatch to Google Sheets feeds only
Calling gf_feed_processor()->save()->dispatch() will process all feeds. Instead, dispatch only the Google Sheets feed to avoid duplicate or unintended feed executions.

Example diff:

-		gc_google_sheets()->maybe_process_feed( $new_entry, $new_form );
-		gf_feed_processor()->save()->dispatch();
+		$integration = gc_google_sheets();
+		$integration->maybe_process_feed( $new_entry, $new_form );
+
+		// Dispatch only Google Sheets feeds
+		$feed_ids = wp_list_pluck( $integration->get_feeds(), 'id' );
+		gf_feed_processor()
+			->save()
+			->set_feed_ids( $feed_ids )
+			->dispatch();
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 072a5c4 and caf4e29.

📒 Files selected for processing (1)
  • gc-google-sheets/gcgs-process-feed-on-gravityflowformconnector-new-entry.php (1 hunks)

* Process Google Sheet feeds when a new entry is created.
*/
add_action( 'gravityflowformconnector_post_new_entry', function ( $new_entry_id, $entry, $form, $step ) {
if ( function_exists( 'gc_google_sheets' ) && $step->get_type() == 'new_entry' ) {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use strict comparison & guard feed-processor
Replace == with === when comparing step types, and verify gf_feed_processor exists before invoking it to prevent fatal errors.

Diff:

-	if ( function_exists( 'gc_google_sheets' ) && $step->get_type() == 'new_entry' ) {
+	if (
+		function_exists( 'gc_google_sheets' )
+		&& function_exists( 'gf_feed_processor' )
+		&& $step->get_type() === 'new_entry'
+	) {
🤖 Prompt for AI Agents
In gc-google-sheets/gcgs-process-feed-on-gravityflowformconnector-new-entry.php
at line 10, replace the loose equality operator (==) with a strict equality
operator (===) when comparing the step type to 'new_entry'. Additionally, add a
check to ensure that the variable or function gf_feed_processor exists before
calling it to avoid potential fatal errors.

Comment on lines +11 to +12
$new_entry = GFAPI::get_entry( $new_entry_id );
$new_form = GFAPI::get_form( $new_entry['form_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

Handle potential WP_Error from GFAPI calls
GFAPI::get_entry and GFAPI::get_form can return WP_Error. Add guards and bail early on error to avoid PHP notices or fatal errors.

Diff:

-		$new_entry = GFAPI::get_entry( $new_entry_id );
-		$new_form  = GFAPI::get_form( $new_entry['form_id'] );
+		$new_entry = GFAPI::get_entry( $new_entry_id );
+		if ( is_wp_error( $new_entry ) ) {
+			return;
+		}
+		$new_form = GFAPI::get_form( $new_entry['form_id'] );
+		if ( is_wp_error( $new_form ) ) {
+			return;
+		}
🤖 Prompt for AI Agents
In gc-google-sheets/gcgs-process-feed-on-gravityflowformconnector-new-entry.php
at lines 11-12, the calls to GFAPI::get_entry and GFAPI::get_form may return
WP_Error objects. Add checks after each call to detect if the result is a
WP_Error, and if so, handle the error appropriately by logging or returning
early to prevent PHP notices or fatal errors from accessing properties on an
error object.

Copy link
Contributor

@veryspry veryspry left a comment

Choose a reason for hiding this comment

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

Nice Loom video / explanation 😍

@saifsultanc saifsultanc merged commit b7a1074 into master Jun 13, 2025
3 of 4 checks passed
@saifsultanc saifsultanc deleted the saif/add/84668-process-gcgs-post-gf-new-entry branch June 13, 2025 16:24
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