Action
Since 5.7
uncanny-automator
automator_recipe_schedule_remove_from_action
Fires when a recipe schedule action is removed. Fires when a recipe schedule action is removed, providing the post and recipe IDs.
add_action( 'automator_recipe_schedule_remove_from_action', $callback, 10, 2 );
Description
Fires after a specific recipe schedule action is successfully removed from a WordPress post. Developers can leverage this hook to perform cleanup tasks, log the removal, or trigger other related actions. It provides the post ID, recipe ID, and a return array containing recipe data.
Usage
add_action( 'automator_recipe_schedule_remove_from_action', 'your_function_name', 10, 2 );
Parameters
-
$post_id(mixed) - - **$recipe_id** `mixed`
-
$return(mixed)
Examples
add_action( 'automator_recipe_schedule_remove_from_action', 'my_automator_recipe_schedule_removed_handler', 10, 3 );
/**
* Handles the removal of a recipe schedule action.
*
* This function demonstrates how to hook into the 'automator_recipe_schedule_remove_from_action'
* action to perform custom logic when a recipe schedule is removed.
*
* @param int|WP_Post $post_id The ID or WP_Post object of the item associated with the schedule removal.
* @param int $recipe_id The ID of the recipe whose schedule is being removed.
* @param array $return The array of data being returned by the original function.
*/
function my_automator_recipe_schedule_removed_handler( $post_id, $recipe_id, $return ) {
// Ensure $post_id is an integer for consistent handling.
if ( $post_id instanceof WP_Post ) {
$post_id = $post_id->ID;
}
// Log the event for debugging or auditing purposes.
if ( WP_DEBUG ) {
error_log( sprintf(
'Automator: Recipe schedule removed. Post ID: %d, Recipe ID: %d, Return Data: %s',
$post_id,
$recipe_id,
json_encode( $return )
) );
}
// Example: If the schedule was removed for a specific recipe (e.g., recipe ID 123),
// you might want to update a meta field on the related post.
if ( 123 === $recipe_id ) {
$meta_key = 'last_schedule_removal_for_recipe_123';
$meta_value = current_time( 'mysql' );
update_post_meta( $post_id, $meta_key, $meta_value );
}
// Example: Send a notification to an administrator if a critical recipe schedule is removed.
// This is a simplified example; in a real scenario, you'd check $recipe_id against a list of critical recipes.
if ( 456 === $recipe_id ) {
$admin_email = get_option( 'admin_email' );
$post_title = get_the_title( $post_id );
if ( $admin_email && $post_title ) {
wp_mail(
$admin_email,
sprintf( __( 'Critical Recipe Schedule Removed: %s', 'text-domain' ), $post_title ),
sprintf(
__( 'The schedule for recipe ID %d associated with post "%s" (ID: %d) has been removed. Please review.', 'text-domain' ),
$recipe_id,
$post_title,
$post_id
)
);
}
}
// This is an action hook, so no return value is strictly required for the hook itself.
// However, you can modify the $return array if you wish to pass additional data back
// to the original function, though it's less common for action hooks.
// Example: Add a custom message to the return array.
// $return['custom_message'] = 'Schedule removal processed by custom handler.';
// return $return; // If you modified $return and it was intended to be passed back.
}
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:1493
public function remove_schedule( WP_REST_Request $request ) {
// Make sure we have all the data
if ( $request->get_param( 'recipeId' ) && $request->has_param( 'actionId' ) ) {
Utilities::log( 'Removing schedule $request: ' . var_export( $request, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$post_id = (int) $request->get_param( 'actionId' );
$recipe_id = (int) $request->get_param( 'recipeId' );
$return = array();
delete_post_meta( $post_id, 'async_mode' );
delete_post_meta( $post_id, 'async_delay_unit' );
delete_post_meta( $post_id, 'async_delay_number' );
delete_post_meta( $post_id, 'async_schedule_time' );
delete_post_meta( $post_id, 'async_schedule_date' );
delete_post_meta( $post_id, 'async_sentence' );
delete_post_meta( $post_id, 'async_custom' );
$return['success'] = true;
$return['post_ID'] = $post_id;
$return['action'] = 'remove_schedule';
$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 removed.
*
* @since 5.7
*/
do_action( 'automator_recipe_schedule_remove_from_action', $post_id, $recipe_id, $return );
return new WP_REST_Response( $return, 200 );
}
$return['success'] = false;
$return['message'] = 'Failed to remove schedule';
$return['action'] = 'show_error';
return new WP_REST_Response( $return, 200 );
}