Filter uncanny-automator

uap_option_wm_get_all_membership_levels

Filters the all membership levels retrieved by WishList Member for user access to options.

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

Description

Fires after Uncanny Automator retrieves all Wishlist Member membership levels. Developers can filter the `$option` array to modify the membership level data before it's returned, allowing customization of how membership levels are presented or processed within Uncanny Automator automations.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the membership levels retrieved for Wishlist Member integration.
 * This example adds a custom prefix to each membership level name.
 *
 * @param array $option The array containing membership level data.
 * @return array The modified array with prefixed membership level names.
 */
add_filter( 'uap_option_wm_get_all_membership_levels', function( $option ) {

    // Check if the 'options' key exists and is an array.
    if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {

        // Iterate through each membership level.
        foreach ( $option['options'] as $key => $level_data ) {

            // Ensure the level name exists and is a string before prefixing.
            if ( isset( $level_data['label'] ) && is_string( $level_data['label'] ) ) {
                $option['options'][ $key ]['label'] = '[Custom Prefix] ' . $level_data['label'];
            }
        }
    }

    return $option;
}, 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

src/integrations/wishlist-member/helpers/wishlist-member-helpers.php:100

public function wm_get_all_membership_levels( $label = null, $option_code = 'WMMEMBERSHIPLEVELS', $args = array() ) {

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

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

		$options = array();
		if ( $include_all ) {
			$options['-1'] = esc_attr__( 'All levels', 'uncanny-automator' );
		}

		if ( $any ) {
			$options['-1'] = esc_attr__( 'Any level', 'uncanny-automator' );
		}
		$levels = wlmapi_get_levels();

		if ( ! empty( $levels['levels']['level'] ) ) {
			foreach ( $levels['levels']['level'] as $level ) {
				$options[ $level['id'] ] = $level['name'];
			}
		}

		$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,
			'relevant_tokens' => array(
				$option_code => esc_attr__( 'Membership level', 'uncanny-automator' ),
			),
		);

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

Scroll to Top