automator_trigger_saved
Fires after an Automator recipe trigger is successfully saved.
add_action( 'automator_trigger_saved', $callback, 10, 3 );
Description
Fires after a trigger has been successfully saved via the API. Developers can use this action to perform post-save operations, such as updating related metadata or logging trigger information. It provides the recipe ID, the saved trigger ID, and the trigger code.
Usage
add_action( 'automator_trigger_saved', 'your_function_name', 10, 3 );
Parameters
-
$recipe_id(mixed) - The ID of the recipe that the trigger is associated with.
-
$saved_trigger_id(mixed) - The recipe ID to which the saved trigger is associated.
-
$trigger_code(mixed) - This parameter contains the ID of the trigger that was just saved.
Examples
add_action( 'automator_trigger_saved', 'my_custom_trigger_saved_handler', 10, 3 );
/**
* Handles the automator_trigger_saved action hook.
*
* This function is triggered whenever a trigger is successfully saved within Uncanny Automator.
* It logs the saved trigger information for debugging or auditing purposes.
*
* @param int $recipe_id The ID of the recipe the trigger belongs to.
* @param int $saved_trigger_id The ID of the trigger that was just saved.
* @param string $trigger_code The unique code identifying the type of trigger.
*/
function my_custom_trigger_saved_handler( $recipe_id, $saved_trigger_id, $trigger_code ) {
// Example: Log the event for debugging or auditing.
// In a real-world scenario, you might perform other actions like
// sending a notification, updating a custom database table, or
// performing complex data manipulation based on the saved trigger.
error_log( sprintf(
'Uncanny Automator: Trigger saved. Recipe ID: %d, Trigger ID: %d, Trigger Code: %s',
$recipe_id,
$saved_trigger_id,
$trigger_code
) );
// You could also fetch more details about the trigger if needed.
// For example, using Uncanny Automator's internal API if available.
// $trigger_data = Automator()->get_recipe_trigger_meta( $saved_trigger_id );
// error_log( print_r( $trigger_data, true ) );
}
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/api/services/trigger/services/class-trigger-crud-service.php:303
src/api/services/trigger/services/class-trigger-crud-service.php:443
src/api/services/trigger/services/class-trigger-crud-service.php:668
// consumer) uses these to run side effects and enrich the response —
// the CRUD service stays oblivious to what they do.
$saved_trigger_id = $saved_trigger->get_trigger_id()
? (int) $saved_trigger->get_trigger_id()->get_value()
: 0;
if ( $saved_trigger_id > 0 ) {
do_action( 'automator_trigger_saved', $recipe_id, $saved_trigger_id, $trigger_code );
$response = apply_filters( 'automator_trigger_response', $response, $recipe_id, $saved_trigger_id, $trigger_code );
}
return $response;
} catch ( Throwable $e ) {
return new WP_Error(
Internal Usage
Found in uncanny-automator-pro/src/core/webhook/class-webhook-url-handler.php:54:
add_action( 'automator_trigger_saved', array( $this, 'on_trigger_saved' ), 10, 3 );