Filter uncanny-automator

uap_option_list_gravity_forms

Filters the list of Gravity Forms options for user account creation.

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

Description

Filters the options list for Gravity Forms integration. Developers can use this hook to modify or extend the available Gravity Forms options presented within Uncanny Automator, such as adding custom form data or altering existing entries. This filter fires when generating the list of forms for automator recipes.


Usage

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

Parameters

$option (mixed)
This parameter is the value of the option being processed, which could be a form ID, a form label, or other related data.

Return Value

The filtered value.


Examples

/**
 * Example of how to modify the Gravity Forms options for Uncanny Automator.
 *
 * This filter allows developers to add, remove, or modify the options
 * presented to the user when selecting a Gravity Form in Uncanny Automator.
 *
 * For instance, you might want to dynamically add a specific form to a list
 * that isn't normally picked up, or perhaps conditionally hide certain forms.
 *
 * @param array $option The current options array being filtered.
 * @return array The modified options array.
 */
add_filter( 'uap_option_list_gravity_forms', function( $option ) {

	// Check if the 'options' key exists and is an array.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {

		// Let's imagine we want to add a custom entry for a specific form
		// that might not always be returned by Gravity Forms' default API,
		// or we want to highlight a particular form.
		$custom_form_title = 'My Special Form';
		$custom_form_id = 123; // Replace with the actual ID of your special form.

		// Construct the option array for our custom form.
		$custom_option_entry = array(
			'value' => $custom_form_id,
			'label' => $custom_form_title,
		);

		// Add our custom form entry to the beginning of the options array.
		array_unshift( $option['options'], $custom_option_entry );

		// We might also want to add custom tokens if our special form
		// requires unique token identifiers in Uncanny Automator.
		// For demonstration, let's assume the base option code would be 'gravity_forms'.
		// We'll create tokens for 'My Special Form title' and 'My Special Form ID'.
		$base_option_code = 'gravity_forms'; // This would typically be derived from the function context.

		// Ensure 'relevant_tokens' key exists.
		if ( ! isset( $option['relevant_tokens'] ) ) {
			$option['relevant_tokens'] = array();
		}

		// Add the custom tokens.
		$option['relevant_tokens'][ $base_option_code . '_my_special_form_title' ] = esc_html__( 'My Special Form Title', 'your-text-domain' );
		$option['relevant_tokens'][ $base_option_code . '_my_special_form_id' ]    = esc_html__( 'My Special Form ID', 'your-text-domain' );

		// In a real scenario, you would likely check if the form ID already exists
		// to avoid duplicates, and you might have more complex logic for adding tokens.
	}

	// Always return the filtered $option array.
	return $option;

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

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/gravity-forms/helpers/gravity-forms-helpers.php:108

public function list_gravity_forms( $label = null, $option_code = 'GFFORMS', $args = array(), $is_any = false ) {
		// if ( ! $this->load_options ) {

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

		if ( ! $label ) {
			$label = esc_attr_x( 'Form', 'Gravity Forms', '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 ( true === $is_any ) {
			$options[- 1] = esc_attr_x( 'Any form', 'Gravity Forms', 'uncanny-automator' );
		}

		if ( Automator()->helpers->recipe->load_helpers ) {
			$forms = GFAPI::get_forms();

			if ( $forms ) {
				foreach ( $forms as $form ) {
					$options[ $form['id'] ] = esc_html( $form['title'] );
				}
			}
		}
		$type = 'select';

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => $type,
			'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_x( 'Form title', 'Gravity Forms', 'uncanny-automator' ),
				$option_code . '_ID' => esc_html_x( 'Form ID', 'Gravity Forms', 'uncanny-automator' ),
			),
		);

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

Scroll to Top