Filter uncanny-automator-pro

automator_pro_gf_user_submits_matching_value_cron

Filters entry data when a Gravity Forms submission matches a specific value during a cron job.

add_filter( 'automator_pro_gf_user_submits_matching_value_cron', $callback, 10, 3 );

Description

This filter allows developers to control whether a Gravity Forms submission triggers a cron job for the "User submits a form" trigger. By default, cron jobs are disabled. Return `true` to enable cron scheduling for this specific submission. This hook fires after a form is submitted and before Uncanny Automator processes it further.


Usage

add_filter( 'automator_pro_gf_user_submits_matching_value_cron', 'your_function_name', 10, 3 );

Parameters

$entry (mixed)
This parameter controls whether the Gravity Forms submission should be processed immediately or scheduled as a cron job.
$form (mixed)
This parameter contains the Gravity Forms entry object, which holds all the data submitted by the user in the form.
$this (mixed)
This parameter represents the Gravity Forms form object associated with the submission.

Return Value

The filtered value.


Examples

add_filter( 'automator_pro_gf_user_submits_matching_value_cron', 'my_automator_pro_gf_user_submits_matching_value_cron', 10, 4 );

/**
 * Example function to conditionally enable cron for Gravity Forms submissions.
 *
 * This function demonstrates how to hook into 'automator_pro_gf_user_submits_matching_value_cron'
 * to conditionally enable or disable cron processing for Gravity Forms submissions
 * based on specific criteria. In this example, we'll enable cron if the form ID
 * is greater than 5 and if a specific field in the entry contains the value 'enable_cron'.
 *
 * @param bool  $cron_enabled  The current cron enabled status (default is false).
 * @param array $entry         The Gravity Forms entry array.
 * @param array $form          The Gravity Forms form array.
 * @param object $this         The Uncanny Automator GF subfield trigger object.
 *
 * @return bool Returns true to enable cron, false to keep it disabled.
 */
function my_automator_pro_gf_user_submits_matching_value_cron( $cron_enabled, $entry, $form, $trigger_object ) {

	// Check if the form ID is greater than 5
	if ( isset( $form['id'] ) && $form['id'] > 5 ) {

		// Check if a specific field in the entry contains 'enable_cron'
		// Assuming field_id 10 is a text field where the user might type 'enable_cron'
		if ( isset( $entry[10] ) && strtolower( trim( $entry[10] ) ) === 'enable_cron' ) {
			return true; // Enable cron for this submission
		}
	}

	// Otherwise, keep the default behavior (cron disabled)
	return $cron_enabled;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

uncanny-automator-pro/src/integrations/gravity-forms/triggers/gf-subfield.php:124

public function schedule_gform_submit( $entry, $form ) {

		$cron_enabled = apply_filters( 'automator_pro_gf_user_submits_matching_value_cron', false, $entry, $form, $this );

		// Default, cron is disabled by default
		if ( false === $cron_enabled ) {
			// Immediately run gform_submit if cron not enabled.
			$this->validate( $entry, $form );

			return;
		}

		if ( as_has_scheduled_action( 'uoa_gf_gform_after_submission', array( $entry, $form ) ) ) {
			return;
		}

		// Scheduling for 10 sec so that all tax/terms are stored
		return as_schedule_single_action(
			apply_filters( 'automator_pro_gf_schedule_post_submission_time', time() + 10, $entry, $form, $this ),
			'uoa_gf_gform_after_submission',
			array(
				$entry,
				$form,
			)
		);
	}


Scroll to Top