Filter uncanny-automator

automator_action_log_error

Filters the error message logged for an Automator action, allowing modification before storage.

add_filter( 'automator_action_log_error', $callback, 10, 2 );

Description

Fires when an Automator action log entry records an error. Developers can modify the error message or request data before it's saved to the database. This is useful for sanitizing or enriching error details.


Usage

add_filter( 'automator_action_log_error', 'your_function_name', 10, 2 );

Parameters

$error_message (mixed)
This parameter contains the error message that was generated during the execution of an action within the Automator plugin.
$request (mixed)
This parameter contains the error message that has been generated.

Return Value

The filtered value.


Examples

/**
 * Appends additional debugging information to the error message if the request object
 * contains specific user meta keys, useful for diagnosing user-related automator issues.
 *
 * @param mixed $error_message The original error message.
 * @param mixed $request       The request object or array containing details about the action.
 *
 * @return string The potentially modified error message with appended user meta.
 */
add_filter( 'automator_action_log_error', function ( $error_message, $request ) {
	// Check if the request is an array and contains user data
	if ( is_array( $request ) && isset( $request['user_id'] ) && is_numeric( $request['user_id'] ) ) {
		$user_id = $request['user_id'];
		$user_info = get_user_meta( $user_id );

		if ( $user_info ) {
			// Append relevant user meta for better debugging
			$debug_info = "nnUser Meta Debug:n";
			if ( isset( $user_info['automator_plan_id'] ) ) {
				$debug_info .= "Plan ID: " . esc_html( implode( ', ', $user_info['automator_plan_id'] ) ) . "n";
			}
			if ( isset( $user_info['automator_credits'] ) ) {
				$debug_info .= "Credits: " . esc_html( implode( ', ', $user_info['automator_credits'] ) ) . "n";
			}
			// Add more user meta keys as needed for specific debugging scenarios

			return $error_message . $debug_info;
		}
	}

	// If no specific user meta to append, return the original error message
	return $error_message;
}, 10, 2 );

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/admin/api-log/class-api-log-table.php:321
src/core/admin/admin-logs/wp-list-table/class-logs-list-table.php:902

'recipe_date_time'  => $recipe_date_completed,
				'recipe_run_number' => $recipe_run_number,
				'display_name'      => $user_name,
				'request'           => var_export( $request, true ), // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
				'time_spent'        => $time_spent,
				'status'            => $status,
				'completed'         => $completed,
				'error_message'     => apply_filters( 'automator_action_log_error', $error_message, $request ),
				'balance'           => $balance,
				'price'             => empty( $price ) ? 0 : $price,
				'actions'           => join( ' ', $buttons ),
				'endpoint'          => $request->endpoint,
			);
		}


Internal Usage

Found in src/core/admin/api-log/class-api-log-table.php:44:

add_filter( 'automator_action_log_error', array( Logs_List_Table::class, 'format_all_upgrade_links' ), 10, 2 );

Found in src/core/admin/admin-logs/wp-list-table/class-logs-list-table.php:59:

add_filter( 'automator_action_log_error', array( self::class, 'format_all_upgrade_links' ), 10, 2 );
Scroll to Top