automator_pro_schedule_trigger
Fires when a scheduled trigger action is about to be executed within Automator Pro, passing the trigger and recipe details.
add_action( 'automator_pro_schedule_trigger', $callback, 10, 2 );
Description
Fires when a scheduled trigger is being processed for a recipe. Developers can use this hook to perform custom actions or modify trigger behavior before it executes. It provides the trigger object and the associated recipe ID for context.
Usage
add_action( 'automator_pro_schedule_trigger', 'your_function_name', 10, 2 );
Parameters
-
$trigger(mixed) - This parameter contains the specific trigger object that initiated the schedule.
-
$recipe_id(mixed) - This parameter contains the specific trigger object that initiated the schedule execution.
Examples
// Example function to handle the automator_pro_schedule_trigger hook
function my_automator_pro_schedule_trigger_handler( $trigger, $recipe_id ) {
// Check if the trigger is of a specific type we want to handle, e.g., 'specific_date'
if ( isset( $trigger['type'] ) && 'specific_date' === $trigger['type'] ) {
// Get the scheduled date from the trigger's settings
$scheduled_date = isset( $trigger['settings']['date'] ) ? $trigger['settings']['date'] : null;
// If a scheduled date exists, we might want to log it or perform some action
if ( $scheduled_date ) {
// For demonstration, let's log that a specific date trigger is being scheduled for a recipe
error_log( sprintf(
'Uncanny Automator Pro: Specific date trigger scheduled for Recipe ID %d on %s.',
$recipe_id,
date( 'Y-m-d H:i:s', strtotime( $scheduled_date ) ) // Format the date for logging
) );
// You could also:
// - Add a custom meta field to the recipe or user.
// - Trigger another internal process based on this scheduled date.
// - Send a notification to an administrator.
}
} elseif ( isset( $trigger['type'] ) && 'recurring_trigger' === $trigger['type'] ) {
// Handle recurring triggers if needed
$recurring_frequency = isset( $trigger['settings']['frequency'] ) ? $trigger['settings']['frequency'] : 'unknown';
error_log( sprintf(
'Uncanny Automator Pro: Recurring trigger scheduled for Recipe ID %d with frequency: %s.',
$recipe_id,
$recurring_frequency
) );
}
// Add more conditions here to handle other types of schedule triggers if necessary.
}
// Hook into the automator_pro_schedule_trigger action
// The priority is 10, and it accepts 2 arguments: $trigger and $recipe_id
add_action( 'automator_pro_schedule_trigger', 'my_automator_pro_schedule_trigger_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/schedule/helpers/schedule-helpers.php:46
uncanny-automator-pro/src/integrations/schedule/helpers/schedule-helpers.php:307
public function schedule_recipe( $post_id, $recipe_id, $post_status, $return ) {
if ( ! isset( $return['recipes_object'] ) ) {
return;
}
if ( empty( $return['recipes_object'] ) || ! isset( $return['recipes_object'][ $recipe_id ] ) ) {
return;
}
$recipe_object = $return['recipes_object'][ $recipe_id ];
if ( false === $this->has_schedule_trigger( $recipe_object ) ) {
return;
}
$trigger = $this->get_schedule_trigger( $recipe_object );
do_action( 'automator_pro_schedule_trigger', $trigger, $recipe_id );
}
Internal Usage
Found in uncanny-automator-pro/src/integrations/schedule/triggers/trigger-specific-date.php:24:
add_action( 'automator_pro_schedule_trigger', array( $this, 'maybe_schedule_trigger' ), 10, 4 );
Found in uncanny-automator-pro/src/integrations/schedule/triggers/recurring-trigger.php:23:
add_action( 'automator_pro_schedule_trigger', array( $this, 'maybe_schedule_trigger' ), 10, 4 );
Found in uncanny-automator-pro/src/integrations/schedule/triggers/recurring-weekday.php:24:
add_action( 'automator_pro_schedule_trigger', array( $this, 'maybe_schedule_trigger' ), 10, 4 );