Filter uncanny-automator-pro

uap_option_all_wp_users

Filters user IDs for all WordPress users, allowing modification before they are retrieved.

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

Description

Filters the options for selecting all WordPress users, often used in Uncanny Automator. Developers can modify the `$option` array to alter input type, requirements, available user options, or support for custom values, influencing how user selections are presented and processed.


Usage

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

Parameters

$option (mixed)
This parameter holds the value that is being filtered, which represents the current option data for displaying WordPress users.

Return Value

The filtered value.


Examples

// Filter to add specific WordPress users to the 'All WP Users' option.
// This example demonstrates how to exclude a user with ID 1 (often the administrator)
// from being selectable in the 'All WP Users' dropdown in Uncanny Automator Pro.
add_filter( 'uap_option_all_wp_users', function( $options ) {

	// Check if $options is an array and not empty.
	if ( ! is_array( $options ) || empty( $options ) ) {
		return $options;
	}

	// Example: Exclude the user with ID 1 from the list.
	// In a real-world scenario, you might have more complex logic,
	// like excluding users based on roles, custom meta, or if they are
	// specific types of users for your plugin.
	$user_id_to_exclude = 1;

	foreach ( $options as $key => $value ) {
		// Assuming the key in the $options array represents the user ID.
		// The $value is typically the user's display name or username.
		if ( $key == $user_id_to_exclude ) {
			unset( $options[ $key ] );
		}
	}

	// Return the modified options array.
	return $options;

}, 10, 1 );

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

uncanny-automator-pro/src/integrations/wp/helpers/wp-pro-helpers.php:929

public function all_wp_users( $label = null, $option_code = 'WPUSERS', $args = array() ) {

		if ( ! $label ) {
			$label = esc_attr__( 'User', 'uncanny-automator-pro' );
		}

		$options = array();
		$users   = Automator()->helpers->recipe->wp_users();

		foreach ( $users as $user ) {
			$options[ $user->ID ] = $user->display_name;
		}

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => true,
			'options'                  => $options,
			'supports_custom_value'    => $options,
			'custom_value_description' => esc_attr__( 'User ID', 'uncanny-automator' ),
		);

		return apply_filters( 'uap_option_all_wp_users', $option );
	}

Scroll to Top