Filter uncanny-automator

uap_option_list_wp_forms

Filters the options list for WPForms integration, allowing modification before being displayed.

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

Description

Filters the list of WPForms options available for Uncanny Automator triggers and actions. Developers can use this hook to add, remove, or modify the available form title and ID tokens, allowing for custom data selection when integrating with WPForms.


Usage

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

Parameters

$option (mixed)
This parameter holds the current value of the option being filtered.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Add a custom option to the WPForms integration list.
 *
 * This example demonstrates how to hook into 'uap_option_list_wp_forms'
 * to add a new choice to the dropdown list of available WPForms options
 * within the Uncanny Automator plugin. It will add an option representing
 * a specific form's submission confirmation message, if available.
 */
add_filter( 'uap_option_list_wp_forms', 'my_custom_uap_wpforms_option', 10, 1 );

function my_custom_uap_wpforms_option( $option ) {
	// Check if the current option being processed is the one we want to modify.
	// This is a hypothetical check; in a real scenario, you'd likely target
	// a specific form or a more general condition if Uncanny Automator
	// provides a way to identify the context of the option being built.
	// For demonstration, let's assume '$option' might contain information
	// about the form being processed or its ID.
	// In a real plugin, the structure of $option passed to this filter might be more complex.
	// For this example, we'll assume we want to add a new option if a form ID is present.

	// Hypothetical check: If the option array contains a 'form_id' key.
	// This is a simplification for demonstration. You would need to inspect
	// the actual structure of the `$option` variable as provided by the plugin.
	if ( isset( $option['form_id'] ) && ! empty( $option['form_id'] ) ) {
		$form_id = $option['form_id'];
		$form_title = get_the_title( $form_id );

		// Let's assume we want to add an option for the confirmation message.
		// We need to construct a unique key for this new option.
		$option_code_prefix = 'wpforms_confirmation_message'; // A prefix for our custom option
		$unique_option_code = $option_code_prefix . '_' . $form_id;

		// Check if the option already exists to avoid duplicates.
		if ( ! isset( $option['options'][ $unique_option_code ] ) ) {
			// Add our custom option to the 'options' array.
			$option['options'][ $unique_option_code ] = sprintf(
				esc_html__( 'Confirmation message for %s', 'your-text-domain' ),
				$form_title
			);

			// Optionally, add relevant tokens for this new option.
			if ( ! isset( $option['relevant_tokens'] ) ) {
				$option['relevant_tokens'] = array();
			}
			$option['relevant_tokens'][ $unique_option_code ] = sprintf(
				esc_attr__( 'Confirmation message for %s', 'your-text-domain' ),
				$form_title
			);
		}
	}

	// Always return the modified (or unmodified) $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/wpforms/helpers/wpforms-helpers.php:113

public function list_wp_forms( $label = null, $option_code = 'WPFFORMS', $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;
		$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 ) {
			$wpforms = new WPForms_Form_Handler();

			$forms = $wpforms->get( '', array( 'orderby' => 'title' ) );

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

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

Scroll to Top