Skip to content

Commit 15e45f9

Browse files
authored
gpep-edit-entry.php: Added new process_feeds parameter to process feeds when editing. Set to true to reprocess all feeds or use an array such as [ 'gravityformswebhooks' ] to reprocess specific feeds.
1 parent 16a94ed commit 15e45f9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

gp-easy-passthrough/gpep-edit-entry.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct( $options ) {
2727
$this->form_id = rgar( $options, 'form_id' );
2828
$this->delete_partial = rgar( $options, 'delete_partial', true );
2929
$this->refresh_token = rgar( $options, 'refresh_token', false );
30+
$this->process_feeds = rgar( $options, 'process_feeds', false );
3031

3132
add_filter( "gpep_form_{$this->form_id}", array( $this, 'capture_passed_through_entry_ids' ), 10, 3 );
3233
add_filter( "gform_entry_id_pre_save_lead_{$this->form_id}", array( $this, 'update_entry_id' ), 10, 2 );
@@ -40,6 +41,8 @@ public function __construct( $options ) {
4041

4142
add_filter( "gpi_query_{$this->form_id}", array( $this, 'exclude_edit_entry_from_inventory' ), 10, 2 );
4243

44+
// If we need to reprocess any feeds on 'edit'.
45+
add_filter( 'gform_entry_post_save', array( $this, 'process_feeds' ), 10, 2 );
4346
}
4447

4548
public function capture_passed_through_entry_ids( $form, $values, $passed_through_entries ) {
@@ -241,11 +244,35 @@ public function exclude_edit_entry_from_inventory( $query, $field ) {
241244
return $query;
242245
}
243246

247+
public function process_feeds( $entry, $form ) {
248+
if ( ! $this->process_feeds ) {
249+
return $entry;
250+
}
251+
252+
/**
253+
* Disable asynchronous feed process on edit otherwise async feeds will not be re-ran due to a check in
254+
* class-gf-feed-processor.php that checks `gform_get_meta( $entry_id, 'processed_feeds' )` and there isn't
255+
* a way to bypass it.
256+
*/
257+
$filter_priority = rand( 100000, 999999 );
258+
add_filter( 'gform_is_feed_asynchronous', '__return_false', $filter_priority );
259+
260+
foreach ( GFAddOn::get_registered_addons( true ) as $addon ) {
261+
if ( method_exists( $addon, 'maybe_process_feed' ) && ( $this->process_feeds === true || strpos( $this->process_feeds, $addon->get_slug() ) !== false ) ) {
262+
$addon->maybe_process_feed( $entry, $form );
263+
}
264+
}
265+
266+
remove_filter( 'gform_is_feed_asynchronous', '__return_false', $filter_priority );
267+
return $entry;
268+
}
269+
244270
}
245271

246272
// Configurations
247273
new GPEP_Edit_Entry( array(
248274
'form_id' => 123, // Set this to the form ID.
249275
'delete_partial' => false, // Set this to false if you wish to preserve partial entries after an edit is submitted.
250-
'refresh_token' => true, // Set this to true to generate a fresh Easy Passthrough token after updating an entry.
276+
'refresh_token' => false, // Set this to true to generate a fresh Easy Passthrough token after updating an entry.
277+
'process_feeds' => false, // Set this to true to process all feed addons on Edit Entry, or provide a comma separated list of addon slugs like 'gravityformsuserregistration', etc.
251278
) );

0 commit comments

Comments
 (0)