Filter
uncanny-automator
automator_closures
Filters the automator closures, allowing modification of the callback functions used by the core integration.
add_filter( 'automator_closures', $callback, 10, 1 );
Description
Filters the internal closures array. Use this hook to modify or extend the available closures within the core automation engine. It fires during the initialization of the automation functions. Developers can add, remove, or alter closures to customize automation behavior.
Usage
add_filter( 'automator_closures', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter represents the collection of integrations that the Automator plugin is aware of and can use.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the 'automator_closures' hook.
* This hook is used to modify the list of available closures (functions or methods)
* that can be used within the Automator plugin.
*
* In this example, we'll add a custom closure that logs a message when it's executed.
*/
add_filter( 'automator_closures', 'my_custom_automator_closure', 10, 1 );
/**
* Adds a custom closure to the Automator closures list.
*
* @param array $closures The existing array of closures.
* @return array The modified array of closures.
*/
function my_custom_automator_closure( $closures ) {
// Define a simple closure that logs a message.
$custom_closure = function( $args ) {
// In a real-world scenario, you would likely use more complex logic here
// and potentially interact with WordPress functions or custom plugin data.
$log_message = 'Custom Automator Closure executed!';
if ( ! empty( $args ) ) {
$log_message .= ' Arguments: ' . print_r( $args, true );
}
error_log( $log_message );
// Closures should ideally return a value or indicate success/failure
// depending on their intended use within the Automator.
return true;
};
// Add the custom closure to the array. We'll use a unique key for it.
// The key format is typically 'plugin_slug:closure_name'.
$closures['my_plugin:log_message'] = array(
'function' => $custom_closure,
'name' => __( 'Log a custom message', 'my-text-domain' ),
'description' => __( 'This closure logs a message to the error log, useful for debugging.', 'my-text-domain' ),
// Add any other relevant metadata for the closure, e.g., parameters it expects.
'parameters' => array(
'args' => array(
'type' => 'array',
'name' => __( 'Arguments', 'my-text-domain' ),
'description' => __( 'An array of arguments to pass to the closure.', 'my-text-domain' ),
'required' => false,
),
),
);
// Return the modified array of closures.
return $closures;
}
?>
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/class-automator-functions.php:351
public function filter_recipe_parts() {
$this->integrations = apply_filters_deprecated( 'uap_integrations', array( $this->integrations ), '3.0', 'automator_integrations' );
$this->integrations = apply_filters( 'automator_integrations', $this->integrations );
$this->actions = apply_filters_deprecated( 'uap_actions', array( $this->actions ), '3.0', 'automator_actions' );
$this->actions = apply_filters( 'automator_actions', $this->actions );
$this->triggers = apply_filters_deprecated( 'uap_triggers', array( $this->triggers ), '3.0', 'automator_triggers' );
$this->triggers = apply_filters( 'automator_triggers', $this->triggers );
$this->closures = apply_filters_deprecated( 'uap_closures', array( $this->closures ), '3.0', 'automator_closures' );
$this->closures = apply_filters( 'automator_closures', $this->closures );
$this->recipe_items = apply_filters( 'automator_recipe_items', $this->recipe_items );
$this->all_integrations = apply_filters( 'automator_all_integrations', $this->all_integrations );
$this->recipe_types = apply_filters_deprecated( 'uap_recipe_types', array( $this->recipe_types ), '3.0', 'automator_recipe_types' );
$this->recipe_types = apply_filters( 'automator_recipe_types', $this->recipe_types );
}