Filter uncanny-automator-pro

uap_option_get_all_groups

Filters all user group options before they are retrieved for display or use within the plugin.

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

Description

Fires after Uncanny User Manager fetches all groups. Developers can filter the returned group options to customize group selections or add/remove options programmatically. Use this to dynamically control which groups are available for integration with Uncanny Automator.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the 'uap_option_get_all_groups' hook to modify group options.
 *
 * This example demonstrates adding a custom attribute to a specific group option
 * or conditionally removing a group from the list.
 */
add_filter( 'uap_option_get_all_groups', function( $option ) {

	// Check if the $option is an array and contains the expected structure.
	if ( is_array( $option ) && ! empty( $option ) ) {

		// Example 1: Add a custom attribute to a specific group.
		// Let's say we want to add a 'custom_data' attribute to the group with slug 'premium_members'.
		foreach ( $option as &$group ) {
			if ( isset( $group['value'] ) && $group['value'] === 'premium_members' ) {
				$group['custom_data'] = 'This is premium member specific data';
				// You could also modify existing attributes like 'label' or 'disabled'.
				// $group['label'] = 'Premium Members (Special)';
				break; // Stop searching once found.
			}
		}
		unset( $group ); // Unset the reference to prevent unexpected behavior.

		// Example 2: Conditionally remove a group based on a condition.
		// Let's say we want to hide the 'guest' group if the current user is logged in.
		if ( is_user_logged_in() ) {
			$option = array_filter( $option, function( $group ) {
				return isset( $group['value'] ) && $group['value'] !== 'guest';
			} );
		}

	}

	// Always return the modified (or original) $option.
	return $option;
}, 10, 1 ); // Priority 10, accepts 1 argument.
?>

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-user-manager/helpers/wp-user-manager-pro-helpers.php:182

public function get_all_groups( $label = null, $option_code = 'WPUMGROUPS', $args = array() ) {

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

		$token        = key_exists( 'token', $args ) ? $args['token'] : false;
		$is_ajax      = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
		$is_any       = key_exists( 'is_any', $args ) ? $args['is_any'] : false;
		$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point    = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';

		$args = array(
			'post_type'      => 'wpum_group',
			'posts_per_page' => 999,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => 'publish',
		);

		$options = Automator()->helpers->recipe->options->wp_query(
			$args,
			$is_any,
			esc_attr__( 'Any group', 'uncanny-automator' )
		);

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'supports_tokens' => $token,
			'is_ajax'         => $is_ajax,
			'fill_values_in'  => $target_field,
			'endpoint'        => $end_point,
			'options'         => $options,
		);

		return apply_filters( 'uap_option_get_all_groups', $option );

	}

Scroll to Top