automator_pro_magic_button_triggered
Fires automator_pro_magic_button_triggered action when a magic button is triggered. Fires when a Magic Button is triggered in Automator PRO, passing along save meta and execution results for custom actions.
add_action( 'automator_pro_magic_button_triggered', $callback, 10, 1 );
Description
Fired after a Magic Button is successfully triggered in Uncanny Automator Pro. This hook provides access to the saved metadata and the trigger's result array, allowing developers to execute custom actions, log data, or modify the outcome of the automation in response to the button click.
Usage
add_action( 'automator_pro_magic_button_triggered', 'your_function_name', 10, 1 );
Parameters
-
$save_meta(array) - - **$result** `array`
Examples
<?php
/**
* Example callback function for the 'automator_pro_magic_button_triggered' action hook.
*
* This function demonstrates how to access and process the $save_meta and $result
* parameters when a Uncanny Automator Pro Magic Button is triggered.
* It logs the received data to the WordPress debug log.
*
* @param array $save_meta An array containing meta information about the triggered button.
* @param array $result An array containing the result of the magic button trigger.
*/
function my_custom_automator_magic_button_handler( $save_meta, $result ) {
// Check if the WordPress debug log is enabled.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
// Log the received $save_meta data.
error_log( 'Uncanny Automator Pro Magic Button Triggered - $save_meta: ' . print_r( $save_meta, true ) );
// Log the received $result data.
error_log( 'Uncanny Automator Pro Magic Button Triggered - $result: ' . print_r( $result, true ) );
// Example of conditional logic based on the trigger.
if ( isset( $result['user_id'] ) && $result['user_id'] > 0 ) {
$user_info = get_userdata( $result['user_id'] );
if ( $user_info ) {
error_log( 'Magic button triggered by user: ' . $user_info->user_login );
}
}
// Example of modifying data before it's finalized (though this is an action, not a filter).
// In a real scenario, you might use this to update user meta or send notifications.
// For demonstration, we'll just log.
if ( ! empty( $save_meta ) && isset( $save_meta['meta_key'] ) && $save_meta['meta_key'] === 'automator_button_post_title' ) {
error_log( 'Button post title detected: ' . $save_meta['meta_value'] );
}
}
}
add_action( 'automator_pro_magic_button_triggered', 'my_custom_automator_magic_button_handler', 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
uncanny-automator-pro/src/integrations/magic-button/triggers/magic-button-magic-button.php:179
uncanny-automator-pro/src/integrations/magic-button/triggers/magic-button-anon-magic-button-clicked.php:157
* Fires automator_pro_magic_button_triggered action when a magic button is triggered.
*
* @param array $save_meta
* @param array $result
*
* @return void
*/
do_action( 'automator_pro_magic_button_triggered', $save_meta, $result );
}
if ( automator_filter_has_var( 'automator_button_post_title', INPUT_POST ) ) {
$save_meta['meta_key'] = 'automator_button_post_title';
$save_meta['meta_value'] = Automator()->uap_sanitize( automator_filter_input( 'automator_button_post_title', INPUT_POST ) );
Automator()->insert_trigger_meta( $save_meta );
}