Filter uncanny-automator

uap_option_get_all_forms

Filters all user form options before they are retrieved, allowing modification of their values.

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

Description

Fires after Uncanny Automator Pro retrieves all available WP User Manager forms. Developers can use this filter to modify the list of forms, add custom form data, or filter out specific forms before they are used in automations. This hook allows for advanced customization of how WP User Manager forms integrate with Uncanny Automator Pro.


Usage

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

Parameters

$option (mixed)
This parameter is an array that can contain a form's label, option code, or other arguments.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of using the 'uap_option_get_all_forms' filter to modify form data.
 *
 * This function adds a custom 'form_type' key to each form's data if it's not already present.
 * This could be useful for differentiating forms programmatically within your application.
 */
add_filter( 'uap_option_get_all_forms', function( $forms_data ) {

	// Ensure we're dealing with an array before proceeding
	if ( ! is_array( $forms_data ) ) {
		return $forms_data;
	}

	// Iterate over each form in the provided data
	foreach ( $forms_data as $form_id => &$form_data ) {
		// Check if the 'form_type' key exists. If not, add it with a default value.
		if ( ! isset( $form_data['form_type'] ) ) {
			// In a real-world scenario, you might have more sophisticated logic
			// to determine the form type based on $form_id or other properties.
			$form_data['form_type'] = 'default_form';
		}
	}
	unset( $form_data ); // Unset the reference to avoid unexpected behavior

	return $forms_data;

}, 10, 1 ); // 10 is the default priority, 1 is the number of arguments accepted by the callback function.
?>

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/wp-user-manager/helpers/wp-user-manager-helpers.php:94
uncanny-automator-pro/src/integrations/wp-user-manager/helpers/wp-user-manager-pro-helpers.php:99

public function get_all_forms( $label = null, $option_code = 'WPUMFORMS', $args = array() ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Form', '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'] : '';
		$options      = array();

		if ( $is_any ) {
			$options['-1'] = esc_html__( 'Any form', 'uncanny-automator' );
		}

		$forms = wpumrf_registration_forms();

		if ( is_array( $forms ) && ! empty( $forms ) ) {
			foreach ( $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,
		);

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

Scroll to Top