Filter
uncanny-automator
automator_modify_option_results
Filters the options array before they are returned, allowing modifications based on provided arguments.
add_filter( 'automator_modify_option_results', $callback, 10, 2 );
Description
Modify the results of an option query before they are returned. Developers can filter this hook to adjust the retrieved options, for example, to add or remove items, or to change the structure of the results for custom integrations. This hook fires after the initial query is performed.
Usage
add_filter( 'automator_modify_option_results', 'your_function_name', 10, 2 );
Parameters
-
$options(mixed) - This parameter contains an array or object representing the options that are being modified.
-
$args(mixed) - This parameter contains the options array, which is filtered to modify the results of a WordPress query.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'automator_modify_option_results' filter hook.
* This example demonstrates how to add a custom option to the results
* if a specific condition is met.
*/
add_filter( 'automator_modify_option_results', 'my_custom_automator_option_results', 10, 2 );
/**
* Modifies the options results for the Automator plugin.
*
* @param array $options The original options array returned by automator_wp_query.
* @param array $args The arguments passed to automator_wp_query.
*
* @return array The modified options array.
*/
function my_custom_automator_option_results( $options, $args ) {
// Check if we are dealing with a specific type of options and if a custom option should be added.
// For this example, let's assume we want to add a custom option if the 'post_type' argument is 'my_custom_post_type'.
if ( isset( $args['post_type'] ) && 'my_custom_post_type' === $args['post_type'] ) {
// Define the details of the custom option.
$custom_option = array(
'ID' => 'custom_value_id', // Unique identifier for your custom option.
'title' => __( 'My Custom Item', 'textdomain' ), // User-friendly label.
'value' => 'custom_value', // The actual value that will be stored.
);
// Add the custom option to the beginning of the options array.
// You might want to adjust the insertion point based on your needs.
array_unshift( $options, $custom_option );
}
// Always return the modified options array.
return $options;
}
?>
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/helpers/class-automator-recipe-helpers.php:836
public function wp_query( $args, $add_any_option = false, $add_any_option_label = null, $is_all_label = false ) {
// Allow automator to load this wp_query results from MCP requests. Backwards compatibility.
$is_mcp = ( defined( 'REST_REQUEST' ) && REST_REQUEST )
&& isset( $_SERVER['REQUEST_URI'] ) && false !== strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/automator/v1/mcp' );
if ( ! $this->load_helpers && ! $is_mcp ) {
return array();
}
if ( empty( $args ) ) {
return array();
}
/** @var array $args Allow developers to modify $args. */
$args = apply_filters( 'automator_wp_query_args', $args );
// Translate legacy positional params into modern array params.
$params = $args;
if ( $add_any_option ) {
if ( $is_all_label ) {
$params['include_all'] = true;
$params['all_label'] = $this->resolve_any_option_label( $add_any_option_label, true );
} else {
$params['include_any'] = true;
$params['any_label'] = $this->resolve_any_option_label( $add_any_option_label, false );
}
}
$options = automator_wp_query( $params, 'legacy' );
return apply_filters( 'automator_modify_option_results', $options, $args );
}