Filter uncanny-automator

automator_status_get_class_name

Filters the CSS class names used to display different automator statuses, allowing for custom visual representations.

add_filter( 'automator_status_get_class_name', $callback, 10, 1 );

Description

Filters the CSS class name associated with an Automator action's status. Developers can modify this array to change the default class names used for various statuses like "completed," "in-progress," or "failed," allowing for custom styling of action feedback.


Usage

add_filter( 'automator_status_get_class_name', 'your_function_name', 10, 1 );

Parameters

$status (mixed)
This parameter contains an array mapping internal status codes to their corresponding CSS class names.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the CSS class for a specific Automator action status.
 *
 * This filter allows developers to change the default CSS class assigned to a particular
 * status of an Automator action. For example, we might want to visually distinguish
 * "completed with errors" from "completed" by using a more prominent error class.
 *
 * @param array $default_classes An array of status constants mapped to their default CSS classes.
 * @param mixed $status The current status being processed.
 * @return array The modified array of status classes.
 */
add_filter( 'automator_status_get_class_name', function( $default_classes, $status ) {
	// Example: Add a custom class 'warning' for statuses that are 'completed with errors'.
	if ( $status === Automator_Action_Status::COMPLETED_WITH_ERRORS ) {
		// We'll add our custom class alongside the default one, or you could replace it entirely.
		// Here, we're adding it as an additional class.
		if ( isset( $default_classes[ Automator_Action_Status::COMPLETED_WITH_ERRORS ] ) ) {
			$default_classes[ Automator_Action_Status::COMPLETED_WITH_ERRORS ] .= ' warning';
		} else {
			// Fallback if the constant somehow isn't in the default array (shouldn't happen normally).
			$default_classes['completed-with-errors'] = 'completed-with-errors warning';
		}
	}

	// Example: Make 'skipped' actions appear as 'disabled' visually.
	if ( $status === Automator_Action_Status::SKIPPED ) {
		$default_classes[ Automator_Action_Status::SKIPPED ] = 'disabled';
	}

	return $default_classes;
}, 10, 2 ); // Priority 10, 2 arguments expected.
?>

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/lib/process/class-automator-action-status.php:153

public static function get_class_name( $status ) {

		$label = apply_filters(
			'automator_status_get_class_name',
			array(
				self::NOT_COMPLETED          => 'not-completed',
				self::COMPLETED              => 'completed',
				self::COMPLETED_WITH_ERRORS  => 'completed-with-errors',
				self::IN_PROGRESS            => 'in-progress',
				self::SKIPPED                => 'skipped',
				self::DID_NOTHING            => 'completed-do-nothing',
				self::COMPLETED_AWAITING     => 'completed-awaiting',
				self::COMPLETED_WITH_NOTICE  => 'completed-with-notice',
				self::CANCELLED              => 'cancelled',
				self::QUEUED                 => 'queued',
				self::FAILED                 => 'failed',
				self::IN_PROGRESS_WITH_ERROR => 'in-progress-with-errors',
			),
			$status
		);

		return ! isset( $label[ $status ] ) ? $status : $label[ $status ];

	}


Scroll to Top