Filter uncanny-automator

automator_default_options_array

Filters the default options array before it is saved to the database.

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

Description

Fires when default options for a recipe trigger or action are being built. Developers can filter this array to modify existing default options or add new ones, specifying `option_code`, `label`, `input_type`, and `options`. This hook is essential for customizing the default configurations of recipe elements.


Usage

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

Parameters

$option_code (mixed)
This parameter, `$option_code`, is used to uniquely identify a default option within an array of options for an Automator recipe.

Return Value

The filtered value.


Examples

// Add a new default option for a specific input type when creating a recipe.
add_filter(
	'automator_default_options_array',
	function ( $default_options, $option_code, $label ) {
		// Check if we are dealing with a specific option code, for example, 'POST_TITLE'.
		if ( 'POST_TITLE' === $option_code ) {
			// Modify the default options for this specific input type.
			$default_options['input_type'] = 'text';
			$default_options['label']      = __( 'Post Title', 'your-text-domain' );
			$default_options['required']   = false; // Make it optional for this specific case.
		} elseif ( 'USER_ROLE' === $option_code ) {
			// Example for another custom option.
			$default_options['input_type'] = 'select';
			$default_options['label']      = __( 'User Role', 'your-text-domain' );
			$default_options['options']    = array(
				'administrator' => __( 'Administrator', 'your-text-domain' ),
				'editor'        => __( 'Editor', 'your-text-domain' ),
				'author'        => __( 'Author', 'your-text-domain' ),
			);
		}

		return $default_options;
	},
	10, // Priority
	3  // Accepted args: $default_options, $option_code, $label
);

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:1065

public function build_default_options_array( $label = 'Sample label', $option_code = 'SAMPLE' ) {
		return apply_filters(
			'automator_default_options_array',
			array(
				'option_code' => $option_code,
				'label'       => $label,
				'input_type'  => '',
				'required'    => true,
				'options'     => array(),
			)
		);
	}


Scroll to Top