Filter uncanny-automator

automator_skip_closure_registration

Filters whether to skip registering a closure for a specific integration and its code.

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

Description

Allows developers to conditionally prevent closure registration for specific integrations. Use this filter to skip registering a closure based on the closure itself, integration code, or the integration object, ensuring finer control over automator processes. This hook is called before a closure is registered.


Usage

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

Parameters

$skip_closure_registration (mixed)
This parameter is a boolean that determines whether the closure registration should be skipped.
$closure (mixed)
This parameter is a boolean that indicates whether the closure registration should be skipped.
$integration_code (mixed)
This parameter represents the closure function that is being considered for registration.
$integration (mixed)
This parameter represents the integration code of the current integration.

Return Value

The filtered value.


Examples

/**
 * Prevent a specific closure from being registered for a particular integration.
 *
 * This filter allows developers to conditionally skip the registration of a
 * closure based on the integration or the closure itself.
 *
 * @param bool   $skip_closure_registration Whether to skip the closure registration. Defaults to false.
 * @param mixed  $closure                 The closure function being considered for registration.
 * @param string $integration_code        The unique code identifying the integration.
 * @param object $integration             The integration object.
 *
 * @return bool True to skip registration, false otherwise.
 */
add_filter(
	'automator_skip_closure_registration',
	function ( $skip_closure_registration, $closure, $integration_code, $integration ) {
		// Example: Skip registration for a specific 'my_custom_action' closure
		// if the integration code is 'woocommerce'.
		if (
			'woocommerce' === $integration_code &&
			is_callable( $closure ) &&
			'my_custom_action' === ( new ReflectionFunction( $closure ) )->getName()
		) {
			// Log that we're skipping registration for this specific case.
			error_log(
				sprintf(
					'Skipping closure registration for integration "%s" with closure "%s" as per custom logic.',
					$integration_code,
					'my_custom_action'
				)
			);
			return true; // Skip registration
		}

		// Example: Skip registration for any closure associated with a deprecated integration.
		if ( isset( $integration->is_deprecated ) && true === $integration->is_deprecated ) {
			error_log(
				sprintf(
					'Skipping closure registration for deprecated integration "%s".',
					$integration_code
				)
			);
			return true; // Skip registration for deprecated integrations
		}

		return $skip_closure_registration; // Default behavior: don't skip
	},
	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

src/core/lib/utilities/class-automator-registration.php:450

$skip_closure_registration = false;
		$skip_closure_registration = apply_filters_deprecated(
			'skip_closure_registration',
			array( $skip_closure_registration, $closure, $integration_code, $integration ),
			'3.0',
			'automator_skip_closure_registration'
		);
		$skip_closure_registration = apply_filters( 'automator_skip_closure_registration', $skip_closure_registration, $closure, $integration_code, $integration );
		if ( true === $skip_closure_registration ) {
			return null;
		}

		/**
		 * Use this hook to modify the uap closures before it it error checked and registered
		 */


Scroll to Top