Filter
uncanny-automator
automator_option_select_field_args
Filters the arguments used to render an option select field within the Automator plugin's core functionality.
add_filter( 'automator_option_select_field_args', $callback, 10, 1 );
Description
Filters arguments for option select fields within the Automator core. This hook allows developers to modify the `$field_args` array, enabling customization of select field labels, descriptions, and other parameters before they are rendered. It fires during the creation of form fields for Automator recipes.
Usage
add_filter( 'automator_option_select_field_args', 'your_function_name', 10, 1 );
Parameters
-
$field_args(mixed) - This parameter contains an array of arguments that will be used to configure a select field within the Automator recipe creation process.
Return Value
The filtered value.
Examples
/**
* Example of how to use the 'automator_option_select_field_args' filter.
* This filter allows modification of arguments passed to an option select field
* used within the Automator plugin's recipe creation interface.
*
* In this example, we'll add a custom class to the select element for styling
* purposes, and potentially change the default description if a specific
* option is selected.
*/
add_filter( 'automator_option_select_field_args', function( $field_args ) {
// Ensure $field_args is an array before proceeding.
if ( ! is_array( $field_args ) ) {
return $field_args;
}
// Add a custom CSS class to the select element for advanced styling.
// This could be used in your theme's CSS to style specific fields differently.
if ( isset( $field_args['attributes'] ) && is_array( $field_args['attributes'] ) ) {
$field_args['attributes']['class'] = isset( $field_args['attributes']['class'] ) ? $field_args['attributes']['class'] . ' automator-custom-select' : 'automator-custom-select';
} else {
$field_args['attributes']['class'] = 'automator-custom-select';
}
// Example: If a specific option is selected by default,
// change its custom description to be more informative.
// Let's assume there's an option with a 'value' of 'custom_post_type'.
if ( ! empty( $field_args['options'] ) && is_array( $field_args['options'] ) ) {
foreach ( $field_args['options'] as &$option ) {
if ( isset( $option['value'] ) && 'custom_post_type' === $option['value'] ) {
// If the option is for selecting a custom post type,
// provide a more detailed description on how to select it.
$option['custom_value_description'] = __( 'Select a post type from your WordPress installation. You can start typing to filter the list.', 'your-text-domain' );
break; // Stop searching once the option is found.
}
}
unset( $option ); // Unset the reference to avoid unexpected behavior.
}
// You can also modify other arguments like 'label', 'description', 'options', etc.
// For instance, if you wanted to add a tooltip to the main field description:
if ( isset( $field_args['description'] ) ) {
$field_args['description'] .= ' <span class="automator-tooltip" data-tooltip="' . esc_attr__( 'This field is crucial for defining the action.', 'your-text-domain' ) . '">?</span>';
}
// Return the modified $field_args array.
return $field_args;
}, 10, 1 ); // Priority 10, accepts 1 argument.
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:407
// default: ''
$field_args['custom_value_description'] = isset( $args['custom_value_description'] ) ? $args['custom_value_description'] : '';
}
}
$field_args = apply_filters_deprecated( 'uap_option_select_field_args', array( $field_args ), '3.0', 'automator_option_select_field_args' );
return apply_filters( 'automator_option_select_field_args', $field_args );
}
/**
* @param $args
*
* @return mixed|void
*/