-
Notifications
You must be signed in to change notification settings - Fork 92
gcgs-process-feed-on-gravityflowformconnector-new-entry.php
: Added snippet to process GCGS Feeds post Gravity Flow Form Connector New Entry.
#1121
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
Conversation
…snippet to process GCGS Feeds post Gravity Flow Form Connector New Entry.
WalkthroughA 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
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
✨ Finishing Touches
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. 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)
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: 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 toadd_action
instead.
13-14
: Limit dispatch to Google Sheets feeds only
Callinggf_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
📒 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' ) { |
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.
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.
$new_entry = GFAPI::get_entry( $new_entry_id ); | ||
$new_form = GFAPI::get_form( $new_entry['form_id'] ); |
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.
🛠️ 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.
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.
Nice Loom video / explanation 😍
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