Filter uncanny-automator

automator_option_number_of_times

Filters the number of times a specific automator action can be run, allowing for custom limitations or unlimited usage.

add_filter( 'automator_option_number_of_times', $callback, 10, 1 );

Description

Filters the default, minimum, and required settings for the "Number of times" option in AutomatorWP recipes. Use this hook to customize the allowable range or mark the field as optional, influencing how users configure trigger frequency.


Usage

add_filter( 'automator_option_number_of_times', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

// Example: Limit the 'number of times' option to a maximum of 5 in a recipe.
add_filter( 'automator_option_number_of_times', function( $option ) {
	// Ensure the option array has the expected structure before modification.
	if ( is_array( $option ) && isset( $option['default_value'] ) && isset( $option['min_number'] ) ) {
		// Set a new maximum value for the number of times a recipe can run.
		$option['max_number'] = 5;

		// You might also want to adjust the default value if the new max is lower.
		if ( $option['default_value'] > $option['max_number'] ) {
			$option['default_value'] = $option['max_number'];
		}
	}
	return $option;
}, 10, 1 );

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

src/core/lib/helpers/class-automator-recipe-helpers.php:736

public function number_of_times( $label = null, $description = null, $placeholder = null ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Number of times', 'uncanny-automator' );
		}

		if ( ! $description ) {
			$description = '';
		}

		if ( ! $placeholder ) {
			$placeholder = esc_attr__( 'Example: 1', 'uncanny-automator' );
		}

		$option = array(
			'option_code'            => 'NUMTIMES',
			'label'                  => $label,
			'show_label_in_sentence' => false,
			'description'            => $description,
			'placeholder'            => $placeholder,
			'input_type'             => 'int',
			'default_value'          => 1,
			'min_number'             => 1,
			'required'               => true,
		);

		$option = apply_filters_deprecated( 'uap_option_number_of_times', array( $option ), '3.0', 'automator_option_number_of_times' );

		return apply_filters( 'automator_option_number_of_times', $option );
	}


Scroll to Top