gform_is_feed_asynchronous

Description

The gform_is_feed_asynchronous filter can be used to enable or disable background processing of feeds. This feature prevents feed processing from impacting form submission performance.

See the Add-On Support for Background Feed Processing article for a list of add-ons that support or already have background processing enabled.

Background feed processing might not be suitable for all add-ons. For example, if the add-on needs to change or make data available to the confirmation.

Usage

The gform_is_feed_asynchronous filter applies to all feed-based add-ons that extend the GFFeedAddOn class.

add_filter( 'gform_is_feed_asynchronous', 'your_function_name', 10, 4 );

Parameters

  • $is_asynchronous bool
    Indicates if background (async) feed processing is enabled or disabled.
  • $feed Feed Object
    The feed to be processed.
  • $entry Entry Object
    The entry currently being processed.
  • $form Form Object
    The form currently being processed.

Examples

Turn off background processing for the specified feed name

This example uses the feed name to limit the scope of the snippet.

add_filter( 'gform_is_feed_asynchronous', function ( $is_asynchronous, $feed ) {
	GFCommon::log_debug( __METHOD__ . '(): running.' );
	$feed_name  = rgars( $feed, 'meta/feedName' );
	// Run only for this feed name.
	if ( $feed_name === 'Your feed name here' ) {
		GFCommon::log_debug( __METHOD__ . '(): Disabling background processing for feed: ' . $feed_name );
		$is_asynchronous = false;
	}
	return $is_asynchronous;
}, 10, 2 );

Enable background processing for specific add-ons

These examples check the add-on slug from the $feed to enable background processing for specific add-ons.

See the Gravity Forms Add-On Slugs article for a list of slugs for official Gravity Forms add-ons.

If you want to use this filter with a third-party add-on, please check with the add-on developer to confirm it extends the GFFeedAddOn class and what the slug is.

Single add-on

add_filter( 'gform_is_feed_asynchronous', function ( $is_asynchronous, $feed ) {
	$target_slug = 'the-slug-goes-here';
	if ( rgar( $feed, 'addon_slug' ) === $target_slug ) {
		$is_asynchronous = true;
	}

	return $is_asynchronous;
}, 10, 2 );

Multiple add-ons

add_filter( 'gform_is_feed_asynchronous', function ( $is_asynchronous, $feed ) {
	$target_slugs = array(
		'slug1',
		'slug2',
	);

	if ( in_array( rgar( $feed, 'addon_slug' ), $target_slugs ) ) {
		$is_asynchronous = true;
	}

	return $is_asynchronous;
}, 10, 2 );

Disable for User Registration Auto Login

This example shows how background feed processing can be disabled for the User Registration add-on when using older versions of the Auto Login perk. It is not required for versions 2.2.3 and greater, which automatically disable background processing when auto login is enabled on the feed.

add_filter( 'gform_is_feed_asynchronous', function ( $is_asynchronous, $feed ) {
	if ( ! $is_asynchronous || ! class_exists( 'GP_Auto_Login' ) || rgar( $feed, 'addon_slug' ) !== 'gravityformsuserregistration' ) {
		return $is_asynchronous;
	}

	return GP_Auto_Login::get_instance()->is_auto_login_enabled( $feed ) ? false : $is_asynchronous;
}, 10, 2 );

If you’re enabling auto login via custom code, you can use the following approach instead.

add_filter( 'gform_is_feed_asynchronous', function ( $is_asynchronous, $feed ) {
	if ( ! $is_asynchronous || rgar( $feed, 'addon_slug' ) !== 'gravityformsuserregistration' ) {
		return $is_asynchronous;
	}

	return gf_user_registration()->is_update_feed( $feed ) ? $is_asynchronous : false;
}, 10, 2 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in class-gf-feed-addon.php.