Filter
uncanny-automator-pro
automator_pro_async_action_updated_field_value
Filters the value of a field that has been updated in an asynchronous action.
add_filter( 'automator_pro_async_action_updated_field_value', $callback, 10, 5 );
Description
Fires after an asynchronous action's field value is updated, allowing developers to modify the new value before it's saved. Useful for sanitizing, transforming, or conditionally altering field data during background processing. Developers receive the new value, field key, action code, action ID, and the full action object.
Usage
add_filter( 'automator_pro_async_action_updated_field_value', 'your_function_name', 10, 5 );
Parameters
-
$new_value(mixed) - The new value of the field that has been updated.
-
$key(mixed) - This parameter contains the new value of a field that has been updated within an asynchronous action.
-
$action_code(mixed) - This parameter represents the unique key or identifier for the field that has been updated within the action.
-
$action_id(mixed) - This parameter contains the unique code that identifies the specific action being processed.
-
$action(mixed) - This parameter contains the entire action object being processed, which holds all of its data and settings.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Modify a specific field's value in an async action before it's saved.
*
* This callback intercepts the 'automator_pro_async_action_updated_field_value'
* filter to conditionally change the value of a field named 'discount_code'
* if it contains the word 'SALE'. It appends '-APPLIED' to the discount code.
*
* @param mixed $new_value The fetched new value for the field.
* @param mixed $key The meta key of the field being updated.
* @param mixed $action_code The unique code of the action.
* @param mixed $action_id The ID of the action post.
* @param array $action The full action data array.
*
* @return mixed The potentially modified new value for the field.
*/
add_filter( 'automator_pro_async_action_updated_field_value', 'my_automator_modify_discount_code', 10, 5 );
function my_automator_modify_discount_code( $new_value, $key, $action_code, $action_id, $action ) {
// Check if we are dealing with a specific discount code field in a specific action
if ( 'discount_code' === $key && 'apply_discount_code' === $action_code ) {
// Check if the new value contains the word 'SALE' (case-insensitive)
if ( stripos( $new_value, 'SALE' ) !== false ) {
// Append '-APPLIED' to the discount code
return $new_value . '-APPLIED';
}
}
// If not the field/action we care about, or the condition isn't met, return the original new value
return $new_value;
}
?>
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:1041
public function fetch_updated_fields( $action_code, $action ) {
// Action ID
$action_id = absint( $action['action_data']['ID'] );
foreach ( $action['action_data']['meta'] as $key => $value ) {
if ( ! in_array( $key, $this->actions_and_fields[ $action_code ], true ) ) {
continue;
}
// Fetch new value from the action meta
$new_value = get_post_meta( $action_id, $key, true );
// Update existing value with the new value
$action['action_data']['meta'][ $key ] = apply_filters( 'automator_pro_async_action_updated_field_value', $new_value, $key, $action_code, $action_id, $action );
// Store the old value, just-in-case
$action['action_data']['meta'][ $key . '_scheduled_value' ] = $value;
}
return $action;
}