Filter uncanny-automator

automator_option_integer_field

Filters the integer field value before it's saved or displayed, allowing modification of the input.

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

Description

Filters the integer field options before they are processed by Automator. Use this hook to modify the value or attributes of integer fields, such as setting default values or changing validation rules. It fires after initial sanitization.


Usage

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

Parameters

$option (mixed)
This parameter holds the value of the integer field.

Return Value

The filtered value.


Examples

// Example: Ensure that any integer field value is not negative and has a minimum value of 1.
add_filter( 'automator_option_integer_field', function( $option ) {
    // Check if the $option is an array and contains 'value' and 'input_type'.
    if ( is_array( $option ) && isset( $option['value'] ) && 'int' === $option['input_type'] ) {
        $current_value = (int) $option['value'];

        // If the value is less than 1, set it to 1.
        if ( $current_value < 1 ) {
            $option['value'] = 1;
        }
    }

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

public function integer_field( $option_code = 'INT', $label = null, $description = null, $placeholder = null ) {
		if ( defined( 'AUTOMATOR_DEBUG_MODE' ) && true === AUTOMATOR_DEBUG_MODE ) {
			_doing_it_wrong( 'Automator()->helpers->recipe->field->integer_field()', 'Use Automator()->helpers->recipe->field->int() instead.', '3.0' );
		}
		$option = array(
			'option_code' => $option_code,
			'label'       => $label,
			'description' => $description,
			'placeholder' => $placeholder,
			'input_type'  => 'int',
			'required'    => true,
		);

		$option = $this->int( $option );
		$option = apply_filters_deprecated( 'uap_option_integer_field', array( $option ), '3.0', 'automator_option_integer_field' );

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


Scroll to Top