Filter uncanny-automator

uap_option_all_buddyboss_users

Filters the BuddyBoss user options to customize all BuddyBoss user data.

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

Description

Fires after Uncanny Automator retrieves all BuddyBoss users. Developers can filter the $option array to modify how BuddyBoss users are displayed or processed within Uncanny Automator triggers and actions. This is useful for customizing user selection interfaces or pre-processing user data.


Usage

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

Return Value

The filtered value.


Examples

// Example: Modify the options for the "All BuddyBoss Users" select field
// to include only administrators if a specific condition is met.
add_filter(
	'uap_option_all_buddyboss_users',
	function ( $option ) {
		// Let's assume we want to filter based on a global setting or another option.
		// For demonstration, we'll hardcode a condition.
		$should_filter_to_admins = true; // In a real scenario, this would come from a WP option or global var.

		if ( $should_filter_to_admins && isset( $option['options'] ) && is_array( $option['options'] ) ) {
			$filtered_users = [];
			foreach ( $option['options'] as $user_id => $user_data ) {
				$user = get_user_by( 'id', $user_id );
				if ( $user && $user->has_cap( 'administrator' ) ) {
					$filtered_users[ $user_id ] = $user_data;
				}
			}
			$option['options'] = $filtered_users;
			// Optionally, update the description to reflect the change.
			$option['custom_value_description'] = esc_attr__( 'User ID (Administrators only)', 'your-text-domain' );
		}

		return $option;
	},
	10, // Priority
	1  // Accepted arguments
);

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/buddyboss/helpers/buddyboss-helpers.php:155

public function all_buddyboss_users( $label = null, $option_code = 'BDBUSERS', $args = array() ) {

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

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr__( 'Any user', 'uncanny-automator' ),
			)
		);

		$options = array();

		if ( Automator()->helpers->recipe->load_helpers ) {
			if ( $args['uo_include_any'] ) {
				$options[- 1] = $args['uo_any_label'];
			}

			$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,
			'custom_value_description' => esc_attr__( 'User ID', 'uncanny-automator' ),
		);

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

Scroll to Top