Action
Since 6.0
uncanny-automator-pro
automator_pro_delayed_action_run_now
Fires after a successful API request. Fires after Automator Pro successfully processes a delayed action, passing action and log IDs.
add_action( 'automator_pro_delayed_action_run_now', $callback, 10, 2 );
Description
Fires immediately after a delayed Automator Action completes a successful API request. Developers can use this hook to perform custom actions, log additional data, or trigger further processes based on the success of the API call, utilizing the action and log IDs.
Usage
add_action( 'automator_pro_delayed_action_run_now', 'your_function_name', 10, 2 );
Parameters
-
$action_id(mixed) - - **$action_log_id** `mixed`
-
$return(mixed)
Examples
/**
* Example of how to hook into the 'automator_pro_delayed_action_run_now' action.
* This function will log the details of a delayed action that has just run.
*
* @param int|string $action_id The ID of the Uncanny Automator action.
* @param int|string $action_log_id The ID of the specific log entry for this action run.
* @param array $return The return array from the action run, typically containing a 'success' key.
*/
function my_automator_pro_delayed_action_logged( $action_id, $action_log_id, $return ) {
// Check if the action was successful before logging.
if ( ! empty( $return['success'] ) && true === $return['success'] ) {
// In a real-world scenario, you might want to store this information
// in a custom database table, send a notification, or trigger another process.
// For this example, we'll just log it to the WordPress debug log.
error_log(
sprintf(
'Uncanny Automator Pro: Delayed action "%s" (Log ID: "%s") ran successfully.',
esc_html( $action_id ),
esc_html( $action_log_id )
)
);
} else {
// Log if the action did not run successfully.
$error_message = ! empty( $return['error_message'] ) ? $return['error_message'] : 'Unknown error';
error_log(
sprintf(
'Uncanny Automator Pro: Delayed action "%s" (Log ID: "%s") failed to run. Error: "%s"',
esc_html( $action_id ),
esc_html( $action_log_id ),
esc_html( $error_message )
)
);
}
}
add_action( 'automator_pro_delayed_action_run_now', 'my_automator_pro_delayed_action_logged', 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
uncanny-automator-pro/src/core/classes/async-actions.php:215
public function async_run_now( WP_REST_Request $request ) {
// Make sure we have a recipe ID and the newOrder
if ( ! $request->has_param( 'item_log_id' ) || ! $request->has_param( 'item_id' ) ) {
$return['success'] = false;
$return['message'] = esc_html_x( 'Action or Action Log ID is empty', 'Automator', 'uncanny-automator-pro' );
return new WP_REST_Response( $return, 400 );
}
$action_log_id = absint( $request->get_param( 'item_log_id' ) );
$action_id = absint( $request->get_param( 'item_id' ) );
$async_job_id = (int) Automator()->db->action->get_meta( $action_log_id, 'async_job_id' );
$job_details = self::get_action_scheduler_action_details( $async_job_id );
if ( false === $job_details ) {
$return['success'] = false;
$return['message'] = esc_html_x( 'Could not find the delayed action details.', 'Automator', 'uncanny-automator-pro' );
return new WP_REST_Response( $return, 400 );
}
if ( 'automator_async_run_with_hash' !== $job_details['hook'] ) {
$return['success'] = false;
$return['message'] = esc_html_x( 'The action is not a delayed action.', 'Automator', 'uncanny-automator-pro' );
return new WP_REST_Response( $return, 400 );
}
if ( empty( $job_details['args'] ) ) {
$return['success'] = false;
$return['message'] = esc_html_x( 'Could not find the delayed action arguments.', 'Automator', 'uncanny-automator-pro' );
return new WP_REST_Response( $return, 400 );
}
$hash = array_shift( $job_details['args'] );
try {
$this->run_with_hash( $hash );
} catch ( Exception $e ) {
$return['success'] = false;
$return['message'] = $e->getMessage();
return new WP_REST_Response( $return, 400 );
}
$return['message'] = esc_html_x( 'The request has been successfully sent.', 'Automator', 'uncanny-automator-pro' );
$return['success'] = true;
/**
* Fires after a successful API request.
*
* @since 6.0
*/
do_action( 'automator_pro_delayed_action_run_now', $action_id, $action_log_id, $return );
return new WP_REST_Response( $return, 200 );
}