Filter uncanny-automator

automator_action_should_process_in_background

Filters whether an Automator action should be processed in the background.

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

Description

Filters whether an Automator action should be processed in the background. Fires just before an action is queued for background execution. Developers can return `false` to prevent an action from running in the background, useful for debugging or specific action logic. The action object is passed for context.


Usage

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

Parameters

$process_in_bg (mixed)
This parameter determines whether the current action should be processed in the background.
$this (mixed)
This parameter is a boolean value indicating whether the current action should be processed in the background.

Return Value

The filtered value.


Examples

/**
 * Conditionally disable background processing for specific actions.
 *
 * This function checks if the current action is a 'specific_action_type' and,
 * if so, forces it to run in the foreground by returning false.
 *
 * @param bool $process_in_bg The current value determining if the action should run in the background.
 * @param object $action The current action object being processed.
 * @return bool False to prevent background processing for 'specific_action_type', otherwise the original value.
 */
function my_automator_disable_specific_action_in_background( $process_in_bg, $action ) {
    // Check if the action object has a property or method that identifies its type.
    // This is a placeholder; you'd replace 'get_action_type()' with the actual method/property name.
    if ( isset( $action->action_type ) && 'specific_action_type' === $action->action_type ) {
        return false; // Force this specific action to run in the foreground.
    }

    // For all other actions, respect the original background processing decision.
    return $process_in_bg;
}
add_filter( 'automator_action_should_process_in_background', 'my_automator_disable_specific_action_in_background', 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/classes/class-background-actions.php:211

public function should_process_in_background() {

		$process_in_bg = $this->bg_actions_enabled() && $this->is_bg_action();

		$process_in_bg = apply_filters( 'automator_action_should_process_in_background', $process_in_bg, $this->action );

		if ( ! $process_in_bg ) {
			throw new Exception( esc_html__( 'This action is not set to run in background', 'uncanny-automator' ) );
		}

		return $this;
	}

Internal Usage

Found in uncanny-automator-pro/src/core/loops/loop-entry-point.php:76:

add_filter( 'automator_action_should_process_in_background', array( $this, 'disable_background_actions' ), 10, 2 );
Scroll to Top