automator_recipe_marked_complete
Fires after a recipe has been successfully marked as complete in the database. This hook allows developers to perform additional operations when a recipe is marked complete, such as logging, notifications, or triggering other processes. Fires after a recipe is marked complete, providing the recipe log ID and completion status for further actions.
add_action( 'automator_recipe_marked_complete', $callback, 10, 2 );
Description
Fires after a recipe log's status is updated to complete or completed with errors. This action allows developers to extend functionality, such as sending custom notifications, updating external systems, or initiating follow-up processes based on the recipe's completion status and log ID.
Usage
add_action( 'automator_recipe_marked_complete', 'your_function_name', 10, 2 );
Parameters
-
$recipe_log_id(int) - The recipe log ID that was marked complete.
-
$completed(int) - The completion status.
Examples
// Update a custom meta field for the user associated with the completed recipe.
add_action( 'automator_recipe_marked_complete', 'update_user_meta_on_recipe_completion', 10, 2 );
function update_user_meta_on_recipe_completion( $recipe_log_id, $completed ) {
// Only proceed if the recipe completed successfully.
if ( 1 === $completed ) {
// Retrieve the recipe log details to get user information.
// Assuming there's a function or method to get recipe log details.
// Replace 'automator_get_recipe_log' with the actual function/method.
$recipe_log = automator_get_recipe_log( $recipe_log_id );
if ( $recipe_log && isset( $recipe_log->user_id ) && $recipe_log->user_id > 0 ) {
$user_id = $recipe_log->user_id;
$user_meta_key = 'last_recipe_completed_id'; // Example meta key
$new_meta_value = $recipe_log_id;
// Update the user's meta data.
update_user_meta( $user_id, $user_meta_key, $new_meta_value );
// Optionally, log confirmation.
error_log( "Updated user {$user_id} meta '{$user_meta_key}' to {$new_meta_value} for recipe log {$recipe_log_id}." );
}
}
}
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/lib/utilities/db/class-automator-db-handler-recipes.php:175
public function mark_complete( $recipe_log_id, $completed ) {
$updated = $this->update(
array(
'date_time' => current_time( 'mysql' ),
'completed' => $completed,
),
array(
'ID' => $recipe_log_id,
),
array(
'%s',
'%d',
),
array(
'%d',
)
);
if ( $updated ) {
/**
* Fires after a recipe has been successfully marked as complete in the database.
*
* This hook allows developers to perform additional operations when a recipe
* is marked complete, such as logging, notifications, or triggering other processes.
*
* @since 6.7.0
*
* @param int $recipe_log_id The recipe log ID that was marked complete.
* @param int $completed The completion status.
*
* @example
* // Hook into the recipe completion event
* add_action( 'automator_recipe_marked_complete', 'my_custom_recipe_complete_handler', 10, 2 );
*
* function my_custom_recipe_complete_handler( $recipe_log_id, $completed ) {
* if ( 1 === $completed ) {
* // Recipe completed successfully
* error_log( "Recipe log {$recipe_log_id} completed successfully" );
* } elseif ( 2 === $completed ) {
* // Recipe completed with errors
* error_log( "Recipe log {$recipe_log_id} completed with errors" );
* }
* }
*/
do_action( 'automator_recipe_marked_complete', $recipe_log_id, $completed );
}
}
Internal Usage
Found in src/core/lib/utilities/db/class-automator-db-handler-recipes.php:163:
* add_action( 'automator_recipe_marked_complete', 'my_custom_recipe_complete_handler', 10, 2 );