Filter uncanny-automator-pro

automator_pro_update_async_action_fields

Filters whether to update action fields asynchronously when saving an Automator Pro action.

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

Description

Filters whether the fields of an asynchronous action should be updated when the action is saved. Developers can use this to prevent field updates, ensuring existing data isn't overwritten unexpectedly, especially for complex or custom action configurations.


Usage

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

Parameters

$action (mixed)
This parameter controls whether the action's fields should be updated during an asynchronous action process.

Return Value

The filtered value.


Examples

add_filter( 'automator_pro_update_async_action_fields', 'my_automator_conditional_field_update', 10, 2 );

/**
 * Conditionally prevent specific Uncanny Automator action fields from being updated.
 *
 * This callback demonstrates how to check the action type and a specific field
 * to decide whether the action's fields should be updated. For example, we might
 * want to prevent the "Email subject" field from being updated if the action is
 * an "Email" action and the subject is already set to a specific value.
 *
 * @param bool $allow_update  The default value (true) indicating fields should be updated.
 * @param array $action       The current action data being processed.
 *
 * @return bool Whether the action fields should be updated. Returning false will prevent the update.
 */
function my_automator_conditional_field_update( $allow_update, $action ) {

    // Ensure we have valid action data and it's an array
    if ( ! is_array( $action ) || empty( $action['ID'] ) || empty( $action['meta'] ) ) {
        return $allow_update; // Return original value if data is invalid
    }

    // Example: Prevent updates for the 'Send email' action (replace with actual action code if known)
    // and if the 'Email subject' field (replace with actual meta key) is already set to "Important Announcement".
    if ( isset( $action['code'] ) && 'SEND_EMAIL_ACTION_CODE' === $action['code'] ) { // Replace 'SEND_EMAIL_ACTION_CODE' with the actual code
        if ( isset( $action['meta']['email_subject']['value'] ) && 'Important Announcement' === $action['meta']['email_subject']['value'] ) {
            // If the subject is "Important Announcement", we don't want to update it.
            return false; // Prevent the update
        }
    }

    // For all other actions or conditions, allow the update.
    return $allow_update;
}

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

public function maybe_update_parts_of_action( $action ) {
		// Filter to allow users to not update fields
		if ( false === apply_filters( 'automator_pro_update_async_action_fields', true, $action ) ) {
			return $action;
		}

		// Find action code
		$action_code = $this->get_action_code_from_action( $action );
		if ( empty( $action_code ) ) {
			return $action;
		}

		// Is action modifiable during delayed execution?
		if ( false === $this->is_modifiable_action( $action_code ) ) {
			return $action;
		}

		// Modify fields and return action
		return $this->fetch_updated_fields( $action_code, $action );
	}

Scroll to Top