Action Since 6.0 uncanny-automator-pro

automator_pro_delayed_action_cancelled

Fires after a successful API request. Fires when a scheduled Automator Pro delayed action is successfully cancelled by the system.

add_action( 'automator_pro_delayed_action_cancelled', $callback, 10, 2 );

Description

Fires when a scheduled delayed action is successfully cancelled. Developers can use this hook to perform cleanup or log cancellation events, receiving the action and log IDs. This hook fires after the cancellation API request is confirmed.


Usage

add_action( 'automator_pro_delayed_action_cancelled', 'your_function_name', 10, 2 );

Parameters

$action_id (mixed)
- **$action_log_id** `mixed`
$return (mixed)

Examples

add_action( 'automator_pro_delayed_action_cancelled', function ( $action_id, $action_log_id, $return_data ) {
    // Log the cancellation of a delayed Automator Pro action.
    // This could be used for auditing, debugging, or triggering further actions
    // when a delayed action is explicitly cancelled before execution.

    // Ensure the $return_data is an array before attempting to access its keys.
    if ( ! is_array( $return_data ) ) {
        error_log( 'automator_pro_delayed_action_cancelled: Invalid $return_data provided.' );
        return;
    }

    if ( isset( $return_data['success'] ) && $return_data['success'] === true ) {
        // If the cancellation was successful, we can perform additional logging.
        $log_message = sprintf(
            'Uncanny Automator Pro: Delayed action (ID: %d) associated with log (ID: %d) was successfully cancelled.',
            $action_id,
            $action_log_id
        );
        // You might want to store this in a custom log table, send a notification,
        // or update a user meta field depending on your specific needs.
        // For this example, we'll just use WordPress's error_log.
        error_log( $log_message );

        // Example: If you have a custom database table for storing automation events,
        // you could insert a record here.
        // global $wpdb;
        // $wpdb->insert(
        //     $wpdb->prefix . 'automator_events',
        //     array(
        //         'action_id'   => $action_id,
        //         'log_id'      => $action_log_id,
        //         'event_type'  => 'delayed_action_cancelled',
        //         'timestamp'   => current_time( 'mysql' ),
        //     )
        // );

    } else {
        // Handle cases where the cancellation might not have been marked as successful.
        $log_message = sprintf(
            'Uncanny Automator Pro: Delayed action (ID: %d) associated with log (ID: %d) encountered an issue during cancellation.',
            $action_id,
            $action_log_id
        );
        error_log( $log_message );
    }

}, 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:255

public function async_cancel_action( 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' ) );

		try {
			self::cancel_job( $action_log_id, $action_id );
		} catch ( Exception $e ) {
			$return['success'] = false;
			$return['message'] = $e->getMessage();

			return new WP_REST_Response( $return, 400 );
		}

		$return['message'] = esc_html_x( 'Action successfully cancelled.', 'Automator', 'uncanny-automator-pro' );
		$return['success'] = true;

		/**
		 * Fires after a successful API request.
		 *
		 * @since 6.0
		 */
		do_action( 'automator_pro_delayed_action_cancelled', $action_id, $action_log_id, $return );

		return new WP_REST_Response( $return, 200 );
	}

Scroll to Top