Action
uncanny-automator
automator_updated_option
Fires when a core Automator option is updated with its key and new value.
add_action( 'automator_updated_option', $callback, 10, 2 );
Description
Fired after an option is successfully updated in the AutomatorWP settings. Developers can use this hook to perform custom actions based on the updated option key and its new value. This is useful for triggering further automations or integrating with other plugins when specific settings change.
Usage
add_action( 'automator_updated_option', 'your_function_name', 10, 2 );
Parameters
-
$key(mixed) - The `$key` parameter represents the unique identifier of the option being updated.
-
$value(mixed) - This parameter contains the unique identifier or name of the option being updated.
Examples
/**
* Example of using the 'automator_updated_option' action hook.
* This function logs the key and value of an option that has been updated.
*
* @param mixed $key The option key that was updated.
* @param mixed $value The new value of the option.
*/
function my_automator_log_option_update( $key, $value ) {
// Ensure we have a valid key.
if ( ! empty( $key ) ) {
// Log the update for debugging or auditing purposes.
// In a real scenario, you might store this in a custom log table,
// send an email notification, or trigger other automator workflows.
error_log( sprintf( 'Automator option updated: Key="%s", Value="%s"', $key, print_r( $value, true ) ) );
}
}
// Add the action hook with the callback function.
// The 'automator_updated_option' hook passes two arguments: $key and $value.
// Therefore, we specify '2' as the number of accepted arguments.
add_action( 'automator_updated_option', 'my_automator_log_option_update', 10, 2 );
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/classes/class-automator-options.php:392
public function update_option( string $key, $value, bool $autoload = true ) {
$key = $this->validate_key( $key );
if ( false === $key ) {
return false;
}
// Check if option exists and value is unchanged.
$exists = $this->query->option_exists( $key );
if ( true === $exists ) {
$current = $this->get_option( $key );
if ( $current === $value ) {
// Value unchanged - this is a successful no-op
return true;
}
}
$encoded_value = Automator_Option_Formatter::encode_value( $value );
$serialized_value = maybe_serialize( $encoded_value );
// Upsert to database.
if ( false === $this->query->upsert_option( $key, $serialized_value, $autoload ) ) {
return false;
}
// Delete existing cache entries.
$this->cache->delete( $key );
// Update cache with new value.
$this->cache->set( $key, $value, $serialized_value, $autoload );
do_action( "automator_update_option_{$key}", $key, $value );
do_action( 'automator_updated_option', $key, $value );
return true;
}