Action
Since 5.7
uncanny-automator
automator_recipe_webhook_request_replayed
Fires when a webhook request is replayed. Fires when a webhook request is successfully replayed, providing access to the request and response.
add_action( 'automator_recipe_webhook_request_replayed', $callback, 10, 1 );
Description
Fired after a webhook request is successfully replayed for a WordPress Automator recipe. This action provides access to the original API request's item log ID and the replay response. Developers can use this hook to log replay details, trigger additional actions based on replay success, or perform post-replay cleanup.
Usage
add_action( 'automator_recipe_webhook_request_replayed', 'your_function_name', 10, 1 );
Parameters
-
$api_request(mixed) - - **$response** `mixed`
Examples
add_action( 'automator_recipe_webhook_request_replayed', function( $item_log_id, $response ) {
// This example logs the webhook replay event and the API response to the WordPress debug log.
// This can be useful for debugging issues with replayed webhook requests.
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
return; // Only log if WP_DEBUG is enabled
}
// Convert the response to a readable string format.
// This might involve json_encode for API responses or simple string conversion.
$readable_response = '';
if ( is_array( $response ) || is_object( $response ) ) {
$readable_response = json_encode( $response, JSON_PRETTY_PRINT );
} else {
$readable_response = (string) $response;
}
error_log( sprintf(
'Automator: Webhook request replayed for Item Log ID %s. Response: %s',
esc_html( $item_log_id ),
esc_html( $readable_response )
) );
}, 10, 2 ); // Priority 10, accepts 2 arguments
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:1838
protected function replay_as_webhook( $api_request ) {
$success = true;
$message = esc_html_x( 'The request has been successfully resent', 'Webhooks', 'uncanny-automator' );
if ( ! isset( $api_request->request ) || ! isset( $api_request->params ) ) {
$success = false;
$message = esc_html_x( 'Invalid data. Property "request" or "params" is missing.', 'Webhooks', 'uncanny-automator' );
}
$params = (array) maybe_unserialize( $api_request->params );
$request = (array) maybe_unserialize( $api_request->request );
try {
if ( ! isset( $request['http_url'] ) || ! isset( $params['method'] ) ) {
throw new Exception( 'Invalid data. Cannot find "http_url" or "method".', 400 );
}
Response_Validator::validate_webhook_response(
Automator_Send_Webhook::call_webhook( $request['http_url'], $params, $params['method'] )
);
} catch ( Exception $e ) {
$this->log_api_retry_response(
$api_request->item_log_id,
Automator_Status::get_class_name( Automator_Status::COMPLETED_WITH_ERRORS ),
$e->getMessage()
);
return new WP_REST_Response(
array(
'success' => false,
'message' => $e->getMessage(),
),
200
);
}
$response = array(
'success' => $success,
'message' => $message,
);
$this->log_api_retry_response(
$api_request->item_log_id,
Automator_Status::get_class_name( Automator_Status::COMPLETED ),
$message
);
/**
* Fires when a webhook request is replayed.
*
* @since 5.7
*/
do_action( 'automator_recipe_webhook_request_replayed', $api_request->item_log_id, $response );
return new WP_REST_Response( $response, 200 );
}