Filter
uncanny-automator
uap_option_get_recipes
Filters Uncanny Automator recipes before they are retrieved, allowing for modification of the recipe data.
add_filter( 'uap_option_get_recipes', $callback, 10, 1 );
Description
Fires when retrieving available Uncanny Automator recipes for selection. Developers can filter the `$option` array to customize recipe choices, add or remove recipes, or modify their presentation. This hook is useful for dynamically controlling which recipes are presented to users.
Usage
add_filter( 'uap_option_get_recipes', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is used to specify a label for the recipes.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_get_recipes', 'my_custom_uap_recipes_filter', 10, 1 );
/**
* Filters the Uncanny Automator recipes available for selection.
*
* This example demonstrates how to remove specific recipes from the list
* based on their slug, perhaps to prevent certain automations from being
* chosen by users in a particular context.
*
* @param array $option The array of recipe options, typically keyed by recipe slug.
* @return array The modified array of recipe options.
*/
function my_custom_uap_recipes_filter( $option ) {
// Ensure the options key exists and is an array before proceeding.
if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
// Define the slugs of recipes we want to exclude.
$recipes_to_exclude = array(
'some-internal-recipe-slug',
'another-recipe-to-hide',
);
// Loop through the recipes to exclude and remove them from the $option['options'] array.
foreach ( $recipes_to_exclude as $slug_to_remove ) {
if ( array_key_exists( $slug_to_remove, $option['options'] ) ) {
unset( $option['options'][ $slug_to_remove ] );
}
}
}
// Always return the modified (or unmodified) $option array.
return $option;
}
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/integrations/uncanny-automator/helpers/uoa-helpers.php:83
public function get_recipes( $label = null, $option_code = 'UOARECIPE', $any_option = false ) {
if ( ! $label ) {
$label = esc_attr__( 'Recipe', 'uncanny-automator' );
}
// post query arguments.
global $wpdb;
$results = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title, post_status FROM $wpdb->posts WHERE post_status IN ('publish', 'draft') AND post_type = %s ORDER BY post_title ASC", 'uo-recipe' ) );
$options = array();
$options['-1'] = esc_attr__( 'Any recipe', 'uncanny-automator' );
if ( $results ) {
foreach ( $results as $result ) {
$options[ $result->ID ] = sprintf( '%s (%s)', $result->post_title, $result->post_status );
}
}
//$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any recipe', 'uncanny-automator' ) );
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(),
//'custom_value_description' => esc_attr__( 'Recipe slug', 'uncanny-automator' ),
);
return apply_filters( 'uap_option_get_recipes', $option );
}