Filter uncanny-automator

uap_option_all_lf_memberships

Filters the membership options for LifterLMS when displaying all memberships.

add_filter( 'uap_option_all_lf_memberships', $callback, 10, 2 );

Description

Filters the available options for LifterLMS memberships in Uncanny Automator. Developers can use this hook to add, remove, or modify the membership data fields (like title, ID, or URL) offered as tokens or choices within automations. The `$is_all_label` parameter indicates if all membership options are being retrieved.


Usage

add_filter( 'uap_option_all_lf_memberships', 'your_function_name', 10, 2 );

Parameters

$option (mixed)
This parameter contains the current value of the option being filtered, which could be anything depending on how the filter is being used.
$is_all_label (mixed)
This parameter contains the current option value being processed or generated for the LifterLMS memberships.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of filtering the 'uap_option_all_lf_memberships' hook to add custom membership options.
 *
 * This function demonstrates how to modify the array of membership options returned by the hook.
 * In this example, we're adding a new option to include the membership description.
 *
 * @param array $option       The original array of membership options.
 * @param bool  $is_all_label Whether the option is for 'all' labels (currently not explicitly used in the original snippet, but passed).
 * @return array The modified array of membership options.
 */
add_filter( 'uap_option_all_lf_memberships', function( $option, $is_all_label ) {

	// Let's assume $option_code is available in the scope where this filter is applied,
	// or is derived from context. For realism, let's simulate getting it.
	// In a real scenario, this might be a constant or a variable passed from the parent function.
	// For this example, we'll use a placeholder.
	$simulated_option_code = 'lifterlms_membership';

	// Check if the expected structure exists before attempting to modify it.
	if ( is_array( $option ) && isset( $option[ $simulated_option_code ] ) ) {

		// Add a new option for the membership description.
		// We'll create a new key, e.g., 'lifterlms_membership_DESC'.
		$option[ $simulated_option_code . '_DESC' ] = esc_attr__( 'Membership description', 'uncanny-automator' );

		// You could also modify existing options if needed.
		// For example, to change the text for 'Membership ID':
		// $option[ $simulated_option_code . '_ID' ] = esc_attr__( 'LLMS Membership Identifier', 'uncanny-automator' );
	}

	// It's crucial to return the modified (or original) option array.
	return $option;

}, 10, 2 ); // Priority 10, accepts 2 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/lifterlms/helpers/lifterlms-helpers.php:223

public function all_lf_memberships( $label = null, $option_code = 'LFMEMBERSHIP', $any_option = true, $is_all_label = false ) {

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

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

		if ( $is_all_label ) {
			$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any membership', 'uncanny-automator' ), $is_all_label );
		} else {
			$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any membership', 'uncanny-automator' ) );
		}

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => true,
			// to setup example, lets define the value the child will be based on
			'current_value'            => false,
			'validation_type'          => 'text',
			'options'                  => $options,
			'relevant_tokens'          => array(
				$option_code          => esc_attr__( 'Membership title', 'uncanny-automator' ),
				$option_code . '_ID'  => esc_attr__( 'Membership ID', 'uncanny-automator' ),
				$option_code . '_URL' => esc_attr__( 'Membership URL', 'uncanny-automator' ),
			),
			'custom_value_description' => esc_attr__( 'Membership ID', 'uncanny-automator' ),
		);

		return apply_filters( 'uap_option_all_lf_memberships', $option, $is_all_label );
	}

Scroll to Top