Filter uncanny-automator

automator_add_any_option_label

Filters the label for the "Add Any Option" setting, allowing customization of the default text.

add_filter( 'automator_add_any_option_label', $callback, 10, 1 );

Description

This filter allows you to modify the label for the "Add any" option within Automator recipes. You can customize this label to better suit your needs or provide context. The hook passes the existing options array, the default "Add any" label, and a flag indicating if it's an "all" label.


Usage

add_filter( 'automator_add_any_option_label', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

<?php

/**
 * Example of how to use the 'automator_add_any_option_label' filter.
 * This example adds a custom option label to the dropdown when a placeholder like "Select a User" is needed.
 *
 * @param array $options          The current array of options for the dropdown.
 * @param string $add_any_option_label The default label for the "add any" option.
 * @param bool $is_all_label      A flag indicating if the current label is for an "all" option.
 *
 * @return array The modified array of options.
 */
function my_automator_custom_add_any_option_label( $options, $add_any_option_label, $is_all_label ) {

	// If it's not an "all" label and the default placeholder is generic,
	// we can prepend a more specific identifier, like "Select a User".
	if ( ! $is_all_label && $add_any_option_label === esc_attr__( 'Any', 'automator' ) ) {
		$options['-1'] = esc_attr__( 'Select a User', 'my-plugin-textdomain' );
	}

	// If it is an "all" label, and the default is generic, we might want to clarify it means "all users".
	if ( $is_all_label && $add_any_option_label === esc_attr__( 'Any', 'automator' ) ) {
		$options['-1'] = esc_attr__( 'All Users', 'my-plugin-textdomain' );
	}

	// Always return the modified options array.
	return $options;
}

// Add the filter to WordPress.
// The '3' in add_filter specifies that the callback function accepts 3 arguments.
add_filter( 'automator_add_any_option_label', 'my_automator_custom_add_any_option_label', 10, 3 );

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:976

break;
			default:
				//fallback, assuming  esc_attr__() string is passed
				$options['-1'] = $add_any_option_label;
				break;
		}

		return apply_filters( 'automator_add_any_option_label', $options, $add_any_option_label, $is_all_label );
	}

	/**
	 * @param string $limit
	 *
	 * @return array
	 * @version 2.6 - this function replaces wp's get_users()


Scroll to Top