-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathgpeb-process-feeds-on-edit.php
51 lines (42 loc) · 1.77 KB
/
gpeb-process-feeds-on-edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Gravity Perks // Entry Blocks // Process Feeds on Edit
* https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
*
* By default, some feeds (such as asynchronous feeds) may not be processed when editing entries. This snippet will
* disable async feed processing and then loop through all of the registered add-ons and process their feeds.
*
* Note, delayed feeds will still not be processed.
*/
add_filter( 'gform_entry_post_save', function( $entry, $form ) {
// Array of feed ids to exclude for processing, if you want all feeds to be process use an empty array.
$excluded_feed_ids = array( 103, 104 );
if ( ! function_exists( 'gp_entry_blocks' ) ) {
return $entry;
}
if ( ! gp_entry_blocks()->block_edit_form->has_submitted_edited_entry() ) {
return $entry;
}
/**
* Disable asynchronous feed process on edit otherwise async feeds will not be re-ran due to a check in
* class-gf-feed-processor.php that checks `gform_get_meta( $entry_id, 'processed_feeds' )` and there isn't
* a way to bypass it.
*/
$filter_priority = rand( 100000, 999999 );
add_filter( 'gform_is_feed_asynchronous', '__return_false', $filter_priority );
add_filter( 'gform_addon_pre_process_feeds', function( $feeds, $entry, $form ) use ( $excluded_feed_ids ) {
$feeds = array_filter( $feeds, function( $feed ) use ( $excluded_feed_ids ) {
return ! in_array( $feed['id'], $excluded_feed_ids );
} );
return $feeds;
}, 10, 3 );
$addons = \GFAddon::get_registered_addons();
foreach ( $addons as $addon ) {
$addon = call_user_func( array( $addon, 'get_instance' ) );
if ( $addon instanceof \GFFeedAddOn ) {
$addon->maybe_process_feed( $entry, $form );
}
}
remove_filter( 'gform_is_feed_asynchronous', '__return_false', $filter_priority );
return $entry;
}, 10, 2 );