Filter
uncanny-automator
automator_register_closure
Filters the closure registration process, allowing modification before it's stored for use.
add_filter( 'automator_register_closure', $callback, 10, 1 );
Description
Filters the array of closure registration data before it's finalized. Developers can modify closure properties like 'code', 'sentence', 'select_option_name', 'execution_function', and 'options' to customize how closures are registered within the Automator system. This hook fires during the closure registration process.
Usage
add_filter( 'automator_register_closure', 'your_function_name', 10, 1 );
Parameters
-
$closure(mixed) - This parameter contains the closure or callback function that defines the custom logic for the recipe step.
Return Value
The filtered value.
Examples
/**
* Example of modifying the closure data before it's registered.
*
* This example demonstrates how to add a custom 'description' field
* to the closure registration if a specific condition is met.
*
* @param array $closure The closure data array.
* @return array The modified closure data array.
*/
add_filter( 'automator_register_closure', function( $closure ) {
// Let's assume we only want to add a description for closures
// that have a specific 'code' or 'sentence' pattern.
if ( isset( $closure['code'] ) && 'my_custom_trigger_code' === $closure['code'] ) {
$closure['description'] = __( 'This is a custom trigger that performs a specific action.', 'your-text-domain' );
} elseif ( isset( $closure['sentence'] ) && strpos( $closure['sentence'], 'when a user does something specific' ) !== false ) {
$closure['description'] = __( 'This closure triggers when a user completes a very particular action.', 'your-text-domain' );
}
// Always return the (potentially modified) closure array.
return $closure;
}, 10, 1 );
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/recipe-parts/closures/trait-closure-setup.php:251
src/core/lib/utilities/class-automator-registration.php:464
protected function register_closure() {
$closure = array(
'author' => $this->get_author(),
'support_link' => $this->get_support_link(),
'is_pro' => $this->get_is_pro(),
'is_deprecated' => $this->get_is_deprecated(),
'integration' => $this->get_integration(),
'code' => $this->get_code(),
'sentence' => $this->get_sentence(),
'select_option_name' => $this->get_readable_sentence(),
'execution_function' => array( $this, 'redirect' ),
'options' => array( $this->get_options() ),
);
$closure = apply_filters( 'automator_register_closure', $closure );
Automator()->register->closure( $closure );
}