Filter uncanny-automator

automator_logs_recipe_status

Filters recipe status for Automator logs, allowing modification of the status before it's saved or displayed.

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

Description

Fires when determining the recipe log status. Allows developers to modify the status label or its underlying identifier. The `$status` parameter holds the current status, and `$flow_items` contains all recipe action items. Use this to customize how recipe execution status is displayed or processed.


Usage

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

Parameters

$status (mixed)
This parameter holds the calculated status class name for the log entry.
$flow_items (mixed)
This parameter holds the current status of the recipe, which can be modified by the filter.

Return Value

The filtered value.


Examples

/**
 * Example usage of the 'automator_logs_recipe_status' filter.
 *
 * This callback modifies the determined recipe status based on specific conditions
 * within the flow items. It's intended to provide custom status indicators
 * for logs, potentially for debugging or enhanced reporting.
 *
 * @param string $status       The current status class name for the recipe log.
 * @param array  $flow_items   An array of flow items associated with the recipe.
 * @return string              The modified status class name.
 */
add_filter( 'automator_logs_recipe_status', function( $status, $flow_items ) {

    // Check if there are any flow items to process.
    if ( ! empty( $flow_items ) ) {

        // Example: If any flow item has an 'error' status, override the main status.
        $has_error_in_flow = false;
        foreach ( $flow_items as $item ) {
            // Assuming flow items are arrays and have a 'status' key.
            if ( isset( $item['status'] ) && $item['status'] === 'error' ) {
                $has_error_in_flow = true;
                break; // No need to check further if one error is found.
            }
        }

        if ( $has_error_in_flow ) {
            // Return a custom status class if an error is found within the flow items.
            // This might be a predefined class for error indication.
            return 'automator-log-status-has-flow-error';
        }
    }

    // If no specific conditions are met, return the original status.
    return $status;

}, 10, 2 ); // Priority 10, accepts 2 arguments ($status, $flow_items)

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/services/rest/endpoint/log-endpoint.php:252

public function determine_status_id( $status, $recipe_status, $flow_items ) {

		$formatter = $this->formatter;

		// The original recipe status.
		$status = $formatter::status_class_name( $status, intval( $recipe_status ) );

		return apply_filters( 'automator_logs_recipe_status', $status, $flow_items );
	}


Scroll to Top