GravityView: How to trigger feeds after editing an entry
Saving an entry on GravityView’s Edit Entry screen doesn’t run the form’s add-on feeds, such as Zapier or Slack. To send the edited entry to those services, add one of the code snippets below. Gravity Forms also runs each feed only once per entry, so these snippets allow a feed that has already run to run again.
Each save runs the feeds again, so a feed that creates something creates it again on every edit. Notifications and workflows have their own guides: How to send or skip a notification when an entry is edited and restarting a Gravity Flow workflow. For inline edits, follow GravityEdit: How to trigger feeds after editing an entry.
Run every feed on the form #
This snippet runs each active feed whose conditions match the entry. It also runs anything else hooked to gform_entry_post_save.
/**
* Runs all of a form's add-on feeds again after an entry is edited in GravityView.
*
* @param array $form The form the entry belongs to.
* @param int $entry_id The ID of the entry that was edited.
*/
add_action( 'gravityview/edit_entry/after_update', function ( $form, $entry_id ) {
// Change 100 to your form's ID.
if ( 100 !== (int) $form['id'] ) {
return;
}
// Load the form and entry again to get the values that were just saved.
$form = GFAPI::get_form( $form['id'] );
$entry = GFAPI::get_entry( $entry_id );
// Gravity Forms runs a feed once per entry unless told otherwise.
add_filter( 'gform_allow_feed_reprocessing', '__return_true', 1294873 );
// Run the feeds now, not in the background.
add_filter( 'gform_is_feed_asynchronous', '__return_false', 1294873 );
gf_apply_filters( array( 'gform_entry_post_save', $form['id'] ), $entry, $form );
remove_filter( 'gform_allow_feed_reprocessing', '__return_true', 1294873 );
remove_filter( 'gform_is_feed_asynchronous', '__return_false', 1294873 );
}, 10, 2 );Note: To add this code to your site, follow Adding custom PHP code snippets to your website.
Run one add-on’s feeds #
This snippet runs the feeds of one add-on and leaves the others alone. It’s written for Zapier. For another add-on, replace GF_Zapier in both places with its class name:
/**
* Runs one add-on's feeds again after an entry is edited in GravityView.
*
* @param array $form The form the entry belongs to.
* @param int $entry_id The ID of the entry that was edited.
*/
add_action( 'gravityview/edit_entry/after_update', function ( $form, $entry_id ) {
// Change 100 to your form's ID.
if ( 100 !== (int) $form['id'] ) {
return;
}
// Change GF_Zapier in the next line and in the get_instance() line below.
if ( ! class_exists( 'GF_Zapier' ) ) {
return;
}
// Load the form and entry again to get the values that were just saved.
$form = GFAPI::get_form( $form['id'] );
$entry = GFAPI::get_entry( $entry_id );
// Gravity Forms runs a feed once per entry unless told otherwise.
add_filter( 'gform_allow_feed_reprocessing', '__return_true', 1294873 );
// Run the feeds now, not in the background.
add_filter( 'gform_is_feed_asynchronous', '__return_false', 1294873 );
GF_Zapier::get_instance()->maybe_process_feed( $entry, $form );
remove_filter( 'gform_allow_feed_reprocessing', '__return_true', 1294873 );
remove_filter( 'gform_is_feed_asynchronous', '__return_false', 1294873 );
}, 10, 2 );Note: To add this code to your site, follow Adding custom PHP code snippets to your website.
Run one feed #
This snippet runs a single feed, and it runs that feed whatever the feed’s conditional logic says. To find the feed’s ID, open the feed in the form’s settings and look at the address in your browser: the ID is the value after fid=.
/**
* Runs one feed again after an entry is edited in GravityView.
*
* @param array $form The form the entry belongs to.
* @param int $entry_id The ID of the entry that was edited.
*/
add_action( 'gravityview/edit_entry/after_update', function ( $form, $entry_id ) {
// Change 100 to your form's ID.
if ( 100 !== (int) $form['id'] ) {
return;
}
// Change GFMailChimp to the add-on's class name.
if ( ! class_exists( 'GFMailChimp' ) ) {
return;
}
// Change 150 to your feed's ID.
$feed = GFAPI::get_feed( 150 );
if ( is_wp_error( $feed ) ) {
return;
}
// Load the form and entry again to get the values that were just saved.
$form = GFAPI::get_form( $form['id'] );
$entry = GFAPI::get_entry( $entry_id );
GFMailChimp::get_instance()->process_feed( $feed, $entry, $form );
}, 10, 2 );Note: To add this code to your site, follow Adding custom PHP code snippets to your website.
In the first two snippets, 1294873 is a priority that other code is unlikely to use, so removing the filters afterward leaves anyone else’s filters in place.