Filter uncanny-automator

automator_api_log_error

Filters the API error log entry before it's saved, allowing modification of the request data.

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

Description

Filters the error message logged for API requests. Developers can modify the error message string or return an empty string to suppress it. This hook fires when an API request fails and its error message is being prepared for logging.


Usage

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

Parameters

$request (mixed)
This parameter contains the error message associated with the API request.
$request (mixed)
This parameter represents the error message logged for an API request.

Return Value

The filtered value.


Examples

/**
 * Filters the error message logged in the Automator API log.
 * This example sanitizes the error message by removing potentially harmful HTML tags.
 *
 * @param string $error_message The original error message.
 * @param object $request       The API log request object containing details about the log entry.
 *
 * @return string The sanitized error message.
 */
add_filter(
	'automator_api_log_error',
	function ( $error_message, $request ) {
		// Sanitize the error message to prevent XSS vulnerabilities or malformed HTML.
		// Using wp_kses_post to allow common post formatting but strip potentially harmful tags.
		$sanitized_error_message = wp_kses_post( $error_message );

		// If the original error message was significantly different after sanitization,
		// you might want to log this as an internal alert or adjust the logic.
		// For this example, we'll just return the sanitized version.

		return $sanitized_error_message;
	},
	10, // Priority
	2  // Accepted args
);

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:268

}
				}
			}

			$type          = $request->type;
			$date          = $request->date;
			$completed     = apply_filters( 'automator_api_log_status', $completed, $request );
			$error_message = apply_filters( 'automator_api_log_error', $request->error_message, $request );
			$recipe_link   = get_edit_post_link( absint( $request->automator_recipe_id ) );
			$recipe_name   = '<a href="' . $recipe_link . '" class="uap-log-table__recipe-name">' . $request->recipe_title . '</a>';

			$recipe_status   = Automator_Status::name( $request->completed );
			$recipe_finished = Automator_Status::finished( $request->completed );

			$recipe_date_completed = $recipe_finished ? $request->recipe_date_time : '';


Scroll to Top