Filter uncanny-automator

uap_option_all_formidable_forms

Filters the options for all Formidable Forms integrations with the Ultimate Affiliate Pro plugin.

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

Description

Fires when retrieving all available Formidable Forms. Developers can filter the returned array to modify the list of forms, add custom forms, or exclude specific ones from the Uncanny Automator integration's dropdown.


Usage

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

Parameters

$option (mixed)
This parameter contains the array of available Formidable Forms, which is filtered to modify or extend the default options.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the 'uap_option_all_formidable_forms' hook.
 *
 * This example demonstrates how to add a custom option to the list of
 * available Formidable Forms that can be selected in Uncanny Automator.
 * We'll add a specific form as a "featured" option.
 */
add_filter( 'uap_option_all_formidable_forms', 'my_custom_automator_formidable_forms', 10, 1 );

function my_custom_automator_formidable_forms( $option ) {
	// Ensure we are dealing with the expected structure and that it's an array.
	if ( ! is_array( $option ) || ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
		return $option;
	}

	// Let's assume we want to highlight a specific Formidable Form.
	// You would typically get this form ID dynamically or from another setting.
	$featured_form_id = 123; // Replace with an actual Formidable Form ID.

	// Get the title of the featured form.
	// This requires interacting with Formidable Forms' API.
	// Ensure Formidable Forms is active and accessible.
	if ( class_exists( 'FrmForm' ) ) {
		$featured_form = FrmForm::getOne( $featured_form_id );

		if ( $featured_form ) {
			// Add a new option to the beginning of the 'options' array.
			$new_option_key = 'featured_form_' . $featured_form_id;
			$new_option_value = array(
				'value' => $featured_form_id,
				'label' => sprintf( esc_html__( '⭐ Featured: %s', 'uncanny-automator' ), $featured_form->name ),
				'type'  => 'option', // Assuming 'option' is the correct type for individual items.
			);

			// Prepend the featured form to the list.
			$option['options'] = array_merge( array( $new_option_key => $new_option_value ), $option['options'] );

			// Optionally, add relevant tokens for this featured form.
			if ( isset( $option['relevant_tokens'] ) && is_array( $option['relevant_tokens'] ) ) {
				$option['relevant_tokens'][ $new_option_key ] = esc_html__( 'Featured Form title', 'uncanny-automator' );
				$option['relevant_tokens'][ $new_option_key . '_ID' ] = esc_html__( 'Featured Form ID', 'uncanny-automator' );
			}
		}
	}

	// Return the modified 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

src/integrations/formidable/helpers/formidable-helpers.php:121

public function all_formidable_forms( $label = null, $option_code = 'FIFORMS', $args = array() ) {
		// if ( ! $this->load_options ) {

		// 	return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
		// }

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

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr__( 'Any product', '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'] : '';
		$options      = array();

		if ( Automator()->helpers->recipe->load_helpers ) {
			if ( $args['uo_include_any'] ) {
				$options[- 1] = $args['uo_any_label'];
			}
			$s_query                = array(
				array(
					'or'               => 1,
					'parent_form_id'   => null,
					'parent_form_id <' => 1,
				),
			);
			$s_query['is_template'] = 0;
			$s_query['status !']    = 'trash';
			$forms                  = FrmForm::getAll( $s_query, '', ' 0, 999' );

			if ( ! empty( $forms ) ) {
				foreach ( $forms as $form ) {
					$options[ $form->id ] = $form->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_html__( 'Form title', 'uncanny-automator' ),
				$option_code . '_ID' => esc_html__( 'Form ID', 'uncanny-automator' ),
			),
		);

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

Scroll to Top