Filter uncanny-automator

automator_option_int_field

Filters the integer value of an automation option field before it's saved or displayed.

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

Description

Fires after an integer input field's arguments are processed and before the field is created. Developers can use this filter to modify the field's arguments, such as setting minimum/maximum values, controlling token support, or excluding default tokens. The `$this` parameter represents the current field instance.


Usage

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

Parameters

$this (mixed)
This parameter contains an array of arguments that customize the behavior and appearance of the integer field in the Uncanny Automator recipe builder.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Modify the default behavior of an integer field for a specific recipe step.
 *
 * This example demonstrates how to use the 'automator_option_int_field' filter
 * to enforce a maximum value for an integer field used in a custom recipe step.
 * We'll assume this field is for setting a delay in seconds for a specific action.
 */
add_filter(
	'automator_option_int_field',
	function ( $field_args ) {
		// Check if this is the specific integer field we want to modify.
		// Replace 'your_unique_field_code' with the actual option_code of your field.
		// You can find this code in the context where the field is being created.
		if ( isset( $field_args['option_code'] ) && 'your_unique_field_code' === $field_args['option_code'] ) {
			// Set a maximum value for the delay, for example, 300 seconds (5 minutes).
			// This prevents users from setting excessively long delays.
			$field_args['max_number'] = 300;

			// Optionally, you could also update the label or description to inform the user.
			$field_args['label'] = __( 'Action Delay (seconds, max 5 minutes)', 'your-text-domain' );
		}

		// Always return the modified (or unmodified) arguments.
		return $field_args;
	},
	10, // Priority: Default is 10.
	1   // Accepted arguments: The filter passes $field_args by default.
);

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-field.php:94

public function int( $args = array() ) {

		$defaults = array(
			'option_code'           => 'INT',
			'label'                 => esc_attr__( 'Number', 'uncanny-automator' ),
			'description'           => '',
			'placeholder'           => esc_attr__( 'Example: 1', 'uncanny-automator' ),
			'required'              => true,
			'input_type'            => 'int',
			'default'               => '',
			'token_name'            => '',
			'min_number'            => null,
			'max_number'            => null,
			'supports_tokens'       => true,
			'exclude_default_token' => false,
		);
		$args     = wp_parse_args( $args, $defaults );

		return apply_filters( 'automator_option_int_field', $this->create_field( $args ) );
	}


Scroll to Top