Action
Since 5.7
uncanny-automator
automator_recipe_app_request_resent
Fires after a successful API request. Fires after a successful API request is resent by the Automator plugin.
add_action( 'automator_recipe_app_request_resent', $callback, 10, 1 );
Description
Fires after an API request for an Automator recipe action is successfully resent. Developers can use this hook to perform actions after a retry, such as logging or notifying, passing the `$item_log_id` and `$return` of the request.
Usage
add_action( 'automator_recipe_app_request_resent', 'your_function_name', 10, 1 );
Parameters
-
$item_log_id(mixed) - - **$return** `mixed`
Examples
// Example of how to hook into the 'automator_recipe_app_request_resent' action.
// This function will be called after a successful API request within the Automator plugin.
// It logs the item log ID and the return value of the request to the WordPress debug log.
add_action( 'automator_recipe_app_request_resent', 'my_automator_log_resent_request', 10, 2 );
/**
* Logs details of a resent API request for an Automator recipe.
*
* @param mixed $item_log_id The ID of the item log associated with the request.
* @param mixed $return The return value from the API request.
*/
function my_automator_log_resent_request( $item_log_id, $return ) {
// Check if WP_DEBUG is enabled to avoid unnecessary logging in production.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
// Use error_log for logging to the debug.log file.
error_log( 'Automator Recipe App Request Resent - Item Log ID: ' . print_r( $item_log_id, true ) . ', Return: ' . print_r( $return, true ) );
}
// No return statement is needed for action hooks.
}
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:1769
public function resend_api_request( WP_REST_Request $request ) {
// Make sure we have a recipe ID and the newOrder
if ( ! $request->has_param( 'item_log_id' ) ) {
$return['success'] = false;
$return['message'] = esc_html__( 'Action Log ID is empty', 'uncanny-automator' );
return new WP_REST_Response( $return, 400 );
}
$item_log_id = absint( $request->get_param( 'item_log_id' ) );
$api_request = Automator()->db->api->get_by_log_id( 'action', $item_log_id );
if ( empty( $api_request->params ) ) {
$return['success'] = false;
$return['message'] = esc_html__( 'Missing action params', 'uncanny-automator' );
}
$params = maybe_unserialize( $api_request->params );
$params['resend'] = true;
if ( 'internal:webhook' === $api_request->endpoint ) {
return $this->replay_as_webhook( $api_request );
}
try {
$response = Api_Server::api_call( $params );
} catch ( Exception $e ) {
$return['success'] = false;
$return['message'] = $e->getMessage();
automator_log( $e->getMessage() );
// Log the response for retries.
if ( true === $params['resend'] ) {
$this->log_api_retry_response(
$item_log_id,
Automator_Status::get_class_name( Automator_Status::COMPLETED_WITH_ERRORS ),
$return['message']
);
}
return new WP_REST_Response( $return, $e->getCode() );
}
$return['message'] = esc_html__( 'The request has been successfully resent', 'uncanny-automator' );
$return['success'] = true;
// Log the success response for retries.
if ( true === $params['resend'] ) {
$this->log_api_retry_response(
$item_log_id,
Automator_Status::get_class_name( Automator_Status::COMPLETED ),
$return['message']
);
}
/**
* Fires after a successful API request.
*
* @since 5.7
*/
do_action( 'automator_recipe_app_request_resent', $item_log_id, $return );
return new WP_REST_Response( $return, 200 );
}