Filter uncanny-automator-pro

automator_pro_maybe_update_action_fields

Filters action fields to conditionally update them before they are saved in Automator Pro.

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

Description

Fires before an action's fields are considered modifiable. Developers can filter this to dynamically include or exclude specific fields for modification based on the action code. This allows for fine-grained control over which action fields can be updated during automation execution.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of how to use the automator_pro_maybe_update_action_fields filter.
 * This example adds a new action code 'MYCUSTOMACTION' and defines
 * its modifiable fields as 'CUSTOMFIELD1' and 'CUSTOMFIELD2'.
 * It also modifies the existing 'SENDEMAIL' action to include 'EMAILATTACHMENT'.
 *
 * @param array $actions_and_fields An array of action codes and their modifiable fields.
 * @return array The modified array of action codes and fields.
 */
add_filter( 'automator_pro_maybe_update_action_fields', function( $actions_and_fields ) {

    // Define a new custom action code and its fields
    $actions_and_fields['MYCUSTOMACTION'] = array(
        'CUSTOMFIELD1',
        'CUSTOMFIELD2',
    );

    // Add a new field to an existing action code
    if ( isset( $actions_and_fields['SENDEMAIL'] ) ) {
        $actions_and_fields['SENDEMAIL'][] = 'EMAILATTACHMENT';
    }

    // Return the modified array
    return $actions_and_fields;

}, 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

uncanny-automator-pro/src/core/classes/async-actions.php:999

public function is_modifiable_action( $action_code ) {

		// Add a filter to include more action_code => fields
		$this->actions_and_fields = apply_filters(
			'automator_pro_maybe_update_action_fields',
			array(
				'SENDEMAIL' => array(
					'EMAILFROM',
					'EMAILFROMNAME',
					'EMAILTO',
					'REPLYTO',
					'EMAILCC',
					'EMAILBCC',
					'EMAILSUBJECT',
					'EMAILBODY',
				),
			)
		);

		return array_key_exists( $action_code, $this->actions_and_fields );
	}

Scroll to Top