Filter uncanny-automator-pro

automator_pro_action_condition_should_register

Filter to override whether a condition should be registered. Filters whether a specific action condition should be registered by the Automator Pro plugin.

add_filter( 'automator_pro_action_condition_should_register', $callback, 10, 4 );

Description

Fires before an action condition is registered, allowing developers to programmatically prevent registration. Use this filter to conditionally disable specific conditions based on integration, code, or the condition object itself. Modify the `$should_register` boolean parameter to `false` to unregister.


Usage

add_filter( 'automator_pro_action_condition_should_register', 'your_function_name', 10, 4 );

Parameters

$should_register (bool)
Whether the condition should be registered.
$integration (string)
The integration code.
$code (string)
The condition code.
$condition (object)
The condition instance.

Return Value

The filtered value.


Examples

/**
 * Prevent registration of a specific Uncanny Automator Pro condition.
 *
 * This example demonstrates how to use the 'automator_pro_action_condition_should_register'
 * filter to conditionally prevent a specific condition from being registered by Uncanny Automator Pro.
 * In this scenario, we're preventing a hypothetical "User Role Change" condition
 * for the "WordPress" integration from being registered.
 *
 * @param bool   $should_register Whether the condition should be registered.
 * @param string $integration The integration code.
 * @param string $code The condition code.
 * @param object $condition The condition instance.
 *
 * @return bool The modified $should_register value.
 */
add_filter( 'automator_pro_action_condition_should_register', function( $should_register, $integration, $code, $condition ) {

	// Define the specific condition and integration we want to prevent from registering.
	$target_integration = 'wordpress';
	$target_condition_code = 'user_role_changed';

	// Check if the current condition matches our target.
	if ( $integration === $target_integration && $code === $target_condition_code ) {
		// If it matches, set $should_register to false to prevent its registration.
		return false;
	}

	// For all other conditions, return the original $should_register value.
	return $should_register;

}, 10, 4 );

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

final public function register( $actions_conditions ) {

		// Check if dependencies are active before registering
		$should_register = $this->is_dependency_active();
		
		/**
		 * Filter to override whether a condition should be registered.
		 *
		 * @param bool   $should_register Whether the condition should be registered.
		 * @param string $integration The integration code.
		 * @param string $code The condition code.
		 * @param object $condition The condition instance.
		 */
		$should_register = apply_filters( 'automator_pro_action_condition_should_register', $should_register, $this->integration, $this->code, $this );
		
		if ( ! $should_register ) {
			return $actions_conditions;
		}

		if ( empty( $this->name ) ) {
			throw new Exception( 'Condition name is required' );
		}

		if ( empty( $this->dynamic_name ) ) {
			throw new Exception( 'Condition dynamic is required' );
		}

		if ( empty( $this->fields() ) ) {
			throw new Exception( 'Condition fields are required' );
		}

		$add_condition = array(
			'name'          => $this->name,
			'dynamic_name'  => $this->dynamic_name,
			'is_pro'        => $this->is_pro,
			'requires_user' => $this->requires_user,
			'deprecated'    => $this->deprecated,
		);

		// Extract manifest data if trait is used
		if ( $this->uses_item_manifest_trait() && is_callable( array( $this, 'extract_item_manifest_data' ) ) ) {
			$manifest = call_user_func( array( $this, 'extract_item_manifest_data' ) );
			if ( ! empty( $manifest ) ) {
				$add_condition['manifest'] = $manifest;
			}
		}
		
		$actions_conditions[ $this->integration ][ $this->code ] = $add_condition;

		return $actions_conditions;
	}

Scroll to Top