Filter uncanny-automator-pro

automator_pro_actions_conditions_log_message

Filters the log message generated for a specific Automator PRO action's condition execution.

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

Description

This filter allows developers to modify the log message when an action or condition fails. It fires within the `condition_failed` method, providing access to the default log message and the condition object itself. Developers can use this hook to customize failure messages for specific conditions, adding more context or translating them.


Usage

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

Parameters

$log_message (mixed)
This parameter contains the log message to be displayed when an action condition fails.
$this (mixed)
This parameter contains the log message that will be recorded when an action's condition fails.

Return Value

The filtered value.


Examples

add_filter( 'automator_pro_actions_conditions_log_message', 'my_custom_automator_log_message', 10, 2 );

/**
 * Modify the log message when an Uncanny Automator Pro condition fails.
 *
 * This example adds the specific user ID of the user whose automation failed to the log message.
 *
 * @param mixed $log_message The original log message.
 * @param object $action_condition The instance of the ActionCondition object.
 * @return string The modified log message.
 */
function my_custom_automator_log_message( $log_message, $action_condition ) {
    // Assuming the $action_condition object has a property or method to access user ID
    // In a real scenario, you'd need to inspect the $action_condition object structure
    // to determine how to reliably get the user ID.
    // For demonstration, let's assume it's available via $action_condition->action['user_id'].
    // You might also need to check if the user is logged in or if a user context is available.

    $user_id = '';
    if ( isset( $action_condition->action['user_id'] ) && ! empty( $action_condition->action['user_id'] ) ) {
        $user_id = absint( $action_condition->action['user_id'] );
    }

    if ( ! empty( $user_id ) ) {
        // Add the user ID to the existing log message or create a new one if it's empty.
        if ( empty( $log_message ) ) {
            $log_message = sprintf(
                __( 'Condition "%s" failed for User ID: %d', 'your-text-domain' ),
                $action_condition->name,
                $user_id
            );
        } else {
            $log_message .= sprintf(
                ' (User ID: %d)',
                $user_id
            );
        }
    }

    return $log_message;
}

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

uncanny-automator-pro/src/core/classes/action-condition.php:320

public function condition_failed( $log_message = '' ) {

		$log_message = apply_filters( 'automator_pro_actions_conditions_log_message', $log_message, $this );

		if ( empty( $log_message ) ) {
			$log_message = $this->name . __( ' failed', 'uncanny-automator-pro' );
		}

		$this->action['process_further']                          = false;
		$this->action['action_data']['failed_actions_conditions'] = true;
		$this->action['action_data']['actions_conditions_log'][]  = sanitize_text_field( $log_message );

		do_action( 'automator_pro_action_condition_failed', $this->action, $this->code, $log_message );

	}


Scroll to Top