Action
Since 5.7
uncanny-automator
automator_recipe_title_updated
Fires when a recipe title is updated. Fires when a recipe's title is updated in the Automator plugin, passing the post ID and new title.
add_action( 'automator_recipe_title_updated', $callback, 10, 2 );
Description
Fires immediately after a WordPress recipe's title has been successfully updated via the REST API. Developers can leverage this hook to perform actions dependent on the recipe title change, such as clearing import warnings or synchronizing data. It passes the recipe's post ID, the new title, and the REST API response array.
Usage
add_action( 'automator_recipe_title_updated', 'your_function_name', 10, 2 );
Parameters
-
$post_id(mixed) - - **$post_title** `mixed`
-
$return(mixed)
Examples
/**
* Logs a message to the WordPress debug log whenever a recipe title is updated.
*
* This function demonstrates how to hook into the 'automator_recipe_title_updated'
* action and access the provided parameters.
*
* @param int $post_id The ID of the recipe post.
* @param string $post_title The new title of the recipe.
* @param array $return The array of data being returned by the REST API.
*/
function my_automator_recipe_title_updated_logger( $post_id, $post_title, $return ) {
// Ensure the debug log is enabled before attempting to write.
if ( WP_DEBUG === true && WP_DEBUG_LOG === true ) {
// Format a log message with the relevant information.
$log_message = sprintf(
'Automator Recipe Title Updated: Recipe ID %1$d has been updated to "%2$s". Response data: %3$s',
$post_id,
esc_html( $post_title ), // Sanitize the title before logging.
json_encode( $return ) // Encode the return array for readability in the log.
);
// Use WordPress's built-in error logging function.
error_log( $log_message );
}
}
add_action( 'automator_recipe_title_updated', 'my_automator_recipe_title_updated_logger', 10, 3 );
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:1070
public function change_post_title( WP_REST_Request $request ) {
// Make sure we have a post ID and a post status
if ( $request->has_param( 'post_ID' ) && $request->has_param( 'post_title' ) ) {
$post_title = sanitize_text_field( $request->get_param( 'post_title' ) );
$post_id = absint( $request->get_param( 'post_ID' ) );
if ( $post_id ) {
$post = array(
'ID' => $post_id,
'post_title' => $post_title,
);
$updated = wp_update_post( $post );
if ( $updated ) {
Automator()->cache->clear_automator_recipe_part_cache( $post_id );
$return['message'] = 'Updated!';
$return['success'] = true;
$return['action'] = 'updated_post';
$return['recipes_object'] = Automator()->get_recipes_data( true, $post_id );
$return['_recipe'] = Automator()->get_recipe_object( $post_id, 'JSON' );
/**
* Fires when a recipe title is updated.
*
* @since 5.7
*/
do_action( 'automator_recipe_title_updated', $post_id, $post_title, $return );
return new WP_REST_Response( $return, 200 );
}
}
}
$return['message'] = 'Failed to update';
$return['success'] = false;
$return['action'] = 'show_error';
return new WP_REST_Response( $return, 200 );
}
Internal Usage
Found in src/core/admin/class-import-recipe.php:91:
add_action( 'automator_recipe_title_updated', array( $this, 'clear_imported_recipe_warning' ), 10, 3 );