Filter
uncanny-automator
uap_option_all_um_forms
Filters all Ultimate Member forms, allowing modification of form data before it's displayed.
add_filter( 'uap_option_all_um_forms', $callback, 10, 1 );
Description
Filters the available Ultimate Member forms list for Uncanny Automator. Developers can modify or add to the `$option` array to customize form selections, or inject additional relevant tokens for use in Automator recipes. This hook fires when Uncanny Automator retrieves Ultimate Member form data.
Usage
add_filter( 'uap_option_all_um_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the current value of the 'all_um_forms' option, which is being filtered to potentially modify the list of Ultimate Member forms available to Uncanny Automator.
Return Value
The filtered value.
Examples
/**
* Example of using the 'uap_option_all_um_forms' filter hook.
*
* This example demonstrates how to add a custom option to the list of Ultimate Member forms
* returned by the hook, or modify the existing options/relevant tokens.
*
* @param array $option The array of options and relevant tokens for Ultimate Member forms.
* @return array The modified array of options and relevant tokens.
*/
add_filter( 'uap_option_all_um_forms', 'my_custom_um_forms_options', 10, 1 );
function my_custom_um_forms_options( $option ) {
// Let's say we want to add a prefix to the form title token for clarity
// if it doesn't already exist.
if ( isset( $option['relevant_tokens'] ) && is_array( $option['relevant_tokens'] ) ) {
foreach ( $option['relevant_tokens'] as $token_key => $token_label ) {
// Example: Add a prefix "UM_" to the FORM_TITLE token if found.
if ( str_contains( $token_key, '_FORM_TITLE' ) ) {
$option['relevant_tokens'][ 'UM_' . $token_key ] = '(UM) ' . $token_label;
// Optionally, remove the original if you prefer the prefixed version exclusively
// unset( $option['relevant_tokens'][ $token_key ] );
}
}
}
// Another example: If we wanted to ensure a specific form is always available in the options list
// even if Ultimate Member doesn't detect it for some reason. (This might be rare, but shows manipulation).
// Assuming $option['options'] is an array of form IDs or form objects.
// For demonstration, let's assume it's a simple array of form IDs.
// If the form with ID 123 is not present, add it.
$specific_form_id = 123;
if ( ! in_array( $specific_form_id, $option['options'] ) ) {
// Assuming $option['options'] is an array of IDs. If it's more complex, adjust accordingly.
$option['options'][] = $specific_form_id;
// If we add a form, we might also want to add its tokens.
// This is more complex as we'd need to know the form's title.
// For simplicity, let's assume we're just adding the ID here.
// A real scenario might involve fetching the form title from Ultimate Member API.
// Example if you had access to form titles:
// $option['relevant_tokens']['MY_CUSTOM_FORM_TITLE_' . $specific_form_id] = 'Custom Form Title (ID: ' . $specific_form_id . ')';
// $option['relevant_tokens']['MY_CUSTOM_FORM_ID_' . $specific_form_id] = 'Custom Form ID (ID: ' . $specific_form_id . ')';
}
// Return the modified 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
src/integrations/ultimate-member/helpers/ultimate-member-helpers.php:119
public function get_um_forms( $label = null, $option_code = 'UMFORM', $type = 'register', $params = array() ) {
if ( ! $label ) {
$label = esc_attr__( 'Form', 'uncanny-automator' );
}
$token = key_exists( 'token', $params ) ? $params['token'] : false;
$is_ajax = key_exists( 'is_ajax', $params ) ? $params['is_ajax'] : false;
$target_field = key_exists( 'target_field', $params ) ? $params['target_field'] : '';
$end_point = key_exists( 'endpoint', $params ) ? $params['endpoint'] : '';
$any = key_exists( 'any', $params ) ? $params['any'] : true;
$options = array();
if ( $any ) {
$options['-1'] = esc_attr__( 'Any form', 'uncanny-automator' );
}
$args = array(
'posts_per_page' => 999,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'um_form',
'post_status' => 'publish',
'suppress_filters' => true,
'fields' => array( 'ids', 'titles' ),
);
if ( 'any' !== (string) $type ) {
$args['meta_query'] = array(
array(
'key' => '_um_mode',
'value' => $type,
'compare' => 'LIKE',
),
);
}
//$forms_list = get_posts( $args );
$forms_list = Automator()->helpers->recipe->options->wp_query( $args );
/*if ( ! empty( $forms_list ) ) {
foreach ( $forms_list as $form ) {
// Check if the form title is defined
$post_title = ! empty( $form->post_title ) ? $form->post_title : sprintf( esc_attr__( 'ID: %1$s (no title)', 'uncanny-automator' ), $form->ID );
$options[ $form->ID ] = $post_title;
}
}*/
$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' => $forms_list,
'relevant_tokens' => array(
$option_code . '_FORM_TITLE' => esc_attr__( 'Form title', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr__( 'Form ID', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_all_um_forms', $option );
}