Filter
uncanny-automator
automator_option_float_field
Filters the value of a float field before it is saved to the database.
add_filter( 'automator_option_float_field', $callback, 10, 1 );
Description
This filter hook allows developers to modify the arguments of a float field used in Automator recipes. It fires when a float field is being created, enabling customization of properties like minimum/maximum values, token support, and default token exclusion. Use it to fine-tune field behavior for specific integrations or recipe steps.
Usage
add_filter( 'automator_option_float_field', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter contains the instance of the `Automator_Recipe_Helpers_Field` class itself, providing access to its methods and properties.
Return Value
The filtered value.
Examples
<?php
/**
* Example of using the 'automator_option_float_field' filter to modify
* the default arguments for a float field.
*
* In this example, we're setting a default maximum value for any float field
* unless it's explicitly overridden, and also disabling token support by default
* for this specific field type.
*/
add_filter(
'automator_option_float_field',
function ( $field_args ) {
// Ensure $field_args is an array, though the hook usually passes an array.
if ( ! is_array( $field_args ) ) {
return $field_args;
}
// Set a default max number if not already set.
if ( ! isset( $field_args['max_number'] ) || null === $field_args['max_number'] ) {
$field_args['max_number'] = 1000; // Example: Set a default maximum of 1000
}
// Disable token support by default for this field type in this context.
$field_args['supports_tokens'] = false;
// Return the modified arguments array.
return $field_args;
},
10, // Priority: default
1 // Accepted args: $field_args
);
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:147
src/core/lib/helpers/class-automator-recipe-helpers-field.php:175
public function float( $args = array() ) {
$defaults = array(
'option_code' => 'FLOAT',
'label' => esc_attr__( 'Number', 'uncanny-automator' ),
'description' => '',
'placeholder' => esc_attr__( 'Example: 1.1', 'uncanny-automator' ),
'required' => true,
'input_type' => 'float',
'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_float_field', $this->create_field( $args ) );
}