Action Since 7.0.0 uncanny-automator

automator_agent_after_execute

Fires after action execution. Fires after an API action has been executed, providing details about the action, fields, user, and result.

add_action( 'automator_agent_after_execute', $callback, 10, 4 );

Description

Fires after an Automator API action has finished executing. Developers can use this hook to perform custom tasks based on the action code, provided field values, user context, and the execution result. This hook offers fine-grained control over post-action logic within API integrations.


Usage

add_action( 'automator_agent_after_execute', 'your_function_name', 10, 4 );

Parameters

$action_code (string)
The action code.
$fields (array)
Field values provided.
$user_id (int)
User ID context.
$result (array)
Execution result.

Examples

// Hook into the automator_agent_after_execute action to log a summary of the action execution.
add_action( 'automator_agent_after_execute', 'my_automator_log_action_execution', 10, 4 );

/**
 * Logs a summary of an automator action execution.
 *
 * @param string $action_code The action code that was executed.
 * @param array  $fields      The field values provided for the action.
 * @param int    $user_id     The user ID context for the execution.
 * @param array  $result      The result of the action execution.
 */
function my_automator_log_action_execution( $action_code, $fields, $user_id, $result ) {

	// Check if the execution was successful.
	if ( $result['success'] ) {
		$message = sprintf(
			'Automator Action "%s" for User ID %d executed successfully. Fields: %s',
			$action_code,
			$user_id,
			json_encode( $fields ) // Log fields for debugging, but be mindful of sensitive data.
		);
		// Use WordPress's debug log or a custom logging function.
		error_log( $message );
	} else {
		$error_message = isset( $result['error_message'] ) ? $result['error_message'] : 'Unknown error';
		$message = sprintf(
			'Automator Action "%s" for User ID %d failed. Error: %s. Fields: %s',
			$action_code,
			$user_id,
			$error_message,
			json_encode( $fields )
		);
		// Log errors for immediate attention.
		error_log( 'Automator Error: ' . $message );
	}

	// You could also perform other actions here, like:
	// - Updating user meta based on the result.
	// - Sending notifications if the action was critical.
	// - Triggering another automation.
}

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/api/application/sub_tooling/class-action-executor.php:177

* @param string $action_code The action code.
		 * @param array  $fields      Field values provided.
		 * @param int    $user_id     User ID context.
		 * @param array  $result      Execution result.
		 *
		 * @since 7.0.0
		 */
		do_action( 'automator_agent_after_execute', $action_code_str, $fields, $user_id, $result );

		$this->log(
			$result['success'] ? 'info' : 'error',
			sprintf(
				'Execution %s (%.2fms)',
				$result['success'] ? 'succeeded' : 'failed',
				$result['execution_time_ms']


Scroll to Top