Filter uncanny-automator-pro

uap_option_wm_get_all_forms

Filters the retrieved Wishlist Member forms before they are returned for use within Ultimate Affiliate Pro.

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

Description

Allows developers to modify the data returned for Wishlist Member forms. This filter fires when Uncanny Automator Pro is fetching all available Wishlist Member forms to present them as selectable options within recipes. Developers can add, remove, or alter form data before it's displayed, providing customization for how forms are integrated.


Usage

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

Parameters

$option (mixed)
This parameter contains a mixed value that is used to filter the list of forms.

Return Value

The filtered value.


Examples

/**
 * Example callback function for the 'uap_option_wm_get_all_forms' filter hook.
 *
 * This function demonstrates how to modify the array of forms returned by Uncanny Automator
 * for Wishlist Member. In this example, we'll add a custom 'description' to a specific
 * form based on its ID, and also filter out forms that have a specific key in their options.
 *
 * @param array $option The original array of form data, including 'endpoint', 'options', and 'relevant_tokens'.
 * @return array The modified array of form data.
 */
add_filter( 'uap_option_wm_get_all_forms', 'my_custom_wm_forms_filter', 10, 1 );

function my_custom_wm_forms_filter( $option ) {
	// Let's assume the $option array contains a structure like:
	// $option = [
	//     'endpoint' => '...',
	//     'options'  => [
	//         'form_id_1' => ['name' => 'Registration Form', 'other_data' => '...'],
	//         'form_id_2' => ['name' => 'Membership Level Upgrade', 'restrict_content' => true],
	//         // ... more forms
	//     ],
	//     'relevant_tokens' => ['some_token' => 'Form'],
	// ];

	// Example 1: Add a custom description to a specific form.
	if ( isset( $option['options']['form_id_1'] ) && is_array( $option['options']['form_id_1'] ) ) {
		$option['options']['form_id_1']['description'] = 'This is the primary registration form for new members.';
	}

	// Example 2: Filter out forms that have a specific option set, e.g., 'restrict_content'.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
		foreach ( $option['options'] as $form_id => $form_data ) {
			if ( isset( $form_data['restrict_content'] ) && $form_data['restrict_content'] === true ) {
				unset( $option['options'][ $form_id ] );
			}
		}
	}

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

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/wishlist-member/helpers/wishlist-member-pro-helpers.php:88

public function wm_get_all_forms( $label = null, $option_code = 'WMFORMS', $args = array() ) {

		global $wpdb;

		if ( ! $label ) {
			$label = esc_attr_x( 'Form', 'Wishlist Member', 'uncanny-automator-pro' );
		}

		$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'] : '';
		$any          = key_exists( 'any', $args ) ? $args['any'] : false;

		$options = array();
		if ( $any ) {
			$options['-1'] = esc_attr_x( 'Any form', 'Wishlist Member', 'uncanny-automator-pro' );
		}

		$options['default'] = esc_attr_x( 'Default registration form', 'Wishlist Member', 'uncanny-automator-pro' );
		$forms              = $wpdb->get_results( "SELECT option_name,option_value FROM `{$wpdb->prefix}wlm_options` WHERE `option_name` LIKE 'CUSTOMREGFORM-%' ORDER BY `option_name` ASC", ARRAY_A );

		foreach ( $forms as $k => $form ) {
			$form_value                        = maybe_unserialize( wlm_serialize_corrector( $form['option_value'] ) );
			$all_forms[ $form['option_name'] ] = $form_value['form_name'];
		}

		if ( ! empty( $all_forms ) ) {
			foreach ( $all_forms as $key => $form ) {
				$options[ $key ] = $form;
			}
		}

		$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_x( 'Form', 'Wishlist Member', 'uncanny-automator' ),
			),
		);

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

Scroll to Top