automator_options_callback_response
Filters the response data and arguments before an Automator callback is executed, allowing for modification of its output.
add_filter( 'automator_options_callback_response', $callback, 10, 3 );
Description
This filter allows developers to modify the response data after a callback function retrieves options for a trigger or action. Use it to filter, transform, or add data to the options before they are cached and displayed in the Automator plugin interface. It's applied just before the options are saved to the database.
Usage
add_filter( 'automator_options_callback_response', 'your_function_name', 10, 3 );
Parameters
-
$response(mixed) - This parameter holds the response from the callback function.
-
$callback(mixed) - This parameter contains the response from the callback function.
-
$callable_type(mixed) - This parameter is used to store the response from the callable action or trigger, including any data or errors.
Return Value
The filtered value.
Examples
add_filter( 'automator_options_callback_response', 'my_automator_modify_callback_response', 10, 5 );
/**
* Example callback function to modify the response from automator_options_callback_response filter.
*
* This function demonstrates how to alter the $response array before it's cached.
* For instance, you might want to add a default value or filter out specific options.
*
* @param mixed $response The original response from the callback.
* @param mixed $callback The callback function being executed.
* @param array $args1 The first array of arguments passed to the callback (empty in this context).
* @param array $args2 The second array of arguments passed to the callback (empty in this context).
* @param mixed $callable_type The type of callable being processed.
*
* @return mixed The modified or original response.
*/
function my_automator_modify_callback_response( $response, $callback, $args1, $args2, $callable_type ) {
// Check if the response is an array and not empty before attempting modification.
if ( ! is_array( $response ) || empty( $response ) ) {
return $response; // Return original if not an array or empty.
}
// Example: If the callable type is 'trigger' and the callback is a specific function,
// add a custom default option to the response.
if ( 'trigger' === $callable_type && 'my_custom_trigger_callback' === $callback ) {
// Ensure we don't overwrite existing values with the same key.
if ( ! isset( $response['my_new_default_option'] ) ) {
$response['my_new_default_option'] = array(
'value' => 'default_value_for_trigger',
'label' => __( 'My Custom Default Trigger Option', 'my-text-domain' ),
);
}
}
// Example: Filter out options that contain a specific keyword in their label for 'action' callable types.
if ( 'action' === $callable_type ) {
foreach ( $response as $key => $option ) {
if ( isset( $option['label'] ) && strpos( $option['label'], 'deprecated' ) !== false ) {
unset( $response[ $key ] );
}
}
}
// Always return the modified (or original) response.
return $response;
}
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/services/resolver/fields-resolver.php:468
src/core/lib/class-automator-functions.php:1071
protected function build_extra_options_cache( string $integration_code, string $object_code, string $cache_key ): ?array {
// Fields_Resolver uses singular type ('action'/'trigger'), but
// load_extra_options() / get_options_from_callable() use plural
// ('actions'/'triggers'). Normalise here so this builder matches the
// existing builder semantics rather than its own singular-flavoured ones.
$is_action = 'action' === $this->get_object_type();
$callable_type = $is_action ? 'actions' : 'triggers';
$callback = $is_action
? Automator()->get->value_from_action_meta( $object_code, 'options_callback' )
: Automator()->get->value_from_trigger_meta( $object_code, 'options_callback' );
if ( ! $callback ) {
return null;
}
try {
$response = Automator()->get_options_from_callable( $callable_type, $object_code, $callback );
} catch ( Throwable $e ) {
return null;
}
if ( ! is_array( $response ) || empty( $response ) ) {
return null;
}
$response = apply_filters( 'automator_options_callback_response', $response, $callback, array(), array(), $callable_type );
automator_update_option( $cache_key, $response, false );
return $response;
}
Internal Usage
Found in src/core/lib/recipe-parts/global-custom-name-field.php:34:
add_filter( 'automator_options_callback_response', array( $this, 'rearrange_trigger_options' ), 599, 5 );
Found in src/core/lib/recipe-parts/global-custom-name-field.php:36:
add_filter( 'automator_options_callback_response', array( $this, 'add_custom_name_field' ), 999, 5 );