Action
Since 5.7
uncanny-automator
automator_recipe_schedule_action_scheduled
Fires when a recipe schedule action is scheduled. Fires when a recipe's schedule action is successfully scheduled with recipe and post IDs.
add_action( 'automator_recipe_schedule_action_scheduled', $callback, 10, 2 );
Description
Fires after a recipe's scheduled action has been successfully set. Developers can use this hook to perform custom actions when a schedule is confirmed, such as logging, triggering external notifications, or modifying the scheduled data. It's important to note that this hook fires *after* the schedule is established and the $return data is prepared.
Usage
add_action( 'automator_recipe_schedule_action_scheduled', 'your_function_name', 10, 2 );
Parameters
-
$post_id(mixed) - - **$recipe_id** `mixed`
-
$return(mixed)
Examples
// This example adds a custom log entry when a recipe schedule action is successfully scheduled.
add_action( 'automator_recipe_schedule_action_scheduled', 'my_custom_automator_schedule_log', 10, 3 );
/**
* Logs a custom message when an Automator recipe action is scheduled.
*
* @param int $post_id The ID of the post where the recipe is being applied.
* @param int $recipe_id The ID of the Automator recipe.
* @param array $return The return data from the scheduling process.
*/
function my_custom_automator_schedule_log( $post_id, $recipe_id, $return ) {
// Check if the schedule was successful based on the return data.
// The exact structure of $return might vary, but typically success is indicated.
// We'll assume $return['success'] exists and is true for this example.
if ( isset( $return['success'] ) && true === $return['success'] ) {
// Use WordPress's built-in error logging for a realistic approach.
error_log( sprintf(
'Automator Recipe Scheduled: Recipe ID %d for Post ID %d. Additional data: %s',
absint( $recipe_id ),
absint( $post_id ),
json_encode( $return ) // Log relevant return data for debugging.
) );
}
}
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/automator-post-types/uo-recipe/class-recipe-post-rest-api.php:1444
public function schedule_action( WP_REST_Request $request ) {
// Make sure we have all the data
if ( $request->get_param( 'recipeId' ) && $request->has_param( 'actionId' ) && $request->has_param( 'asyncMode' ) ) {
$post_id = (int) $request->get_param( 'actionId' );
$recipe_id = (int) $request->get_param( 'recipeId' );
$return = array();
update_post_meta( $post_id, 'async_mode', $request->get_param( 'asyncMode' ) );
if ( $request->has_param( 'delayNumber' ) && ! empty( $request->get_param( 'delayNumber' ) ) && $request->has_param( 'delayUnit' ) ) {
update_post_meta( $post_id, 'async_delay_number', $request->get_param( 'delayNumber' ) );
update_post_meta( $post_id, 'async_delay_unit', $request->get_param( 'delayUnit' ) );
$return['success'] = true;
}
if ( $request->has_param( 'scheduleDate' ) && $request->has_param( 'scheduleTime' ) ) {
update_post_meta( $post_id, 'async_schedule_time', $request->get_param( 'scheduleTime' ) );
update_post_meta( $post_id, 'async_schedule_date', $request->get_param( 'scheduleDate' ) );
$return['success'] = true;
}
if ( $request->has_param( 'scheduleSentence' ) ) {
update_post_meta( $post_id, 'async_sentence', $request->get_param( 'scheduleSentence' ) );
}
if ( $request->has_param( 'customValue' ) ) {
update_post_meta( $post_id, 'async_custom', $request->get_param( 'customValue' ) );
$return['success'] = true;
}
if ( $return['success'] ) {
Automator()->cache->remove( Automator()->cache->recipes_data );
$return['post_ID'] = $post_id;
$return['action'] = 'schedule_action';
$return['recipes_object'] = Automator()->get_recipes_data( true, $recipe_id );
$return['_recipe'] = Automator()->get_recipe_object( $recipe_id );
/**
* Fires when a recipe schedule action is scheduled.
*
* @since 5.7
*/
do_action( 'automator_recipe_schedule_action_scheduled', $post_id, $recipe_id, $return );
return new WP_REST_Response( $return, 200 );
}
}
$return['success'] = false;
$return['message'] = 'Failed to schedule action';
$return['action'] = 'show_error';
return new WP_REST_Response( $return, 200 );
}