Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Gravity Connect // Google Sheets // Process Feed when a New Entry is Created via Gravity Flow Form Connector.
*
* Instruction Video: https://www.loom.com/share/7c5b3b5e286648538bf4a2326333f4d7
*
* 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.

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

gc_google_sheets()->maybe_process_feed( $new_entry, $new_form );
gf_feed_processor()->save()->dispatch();
}
}, 10, 4 );
Loading