Filter
uncanny-automator
uap_option_list_wp_fluent_forms
Filters the options list for WP Fluent Forms integration to allow modification before display.
add_filter( 'uap_option_list_wp_fluent_forms', $callback, 10, 1 );
Description
Filters the list of options for WP Fluent Forms integration. Allows developers to modify the available options and their associated tokens before they are returned. This hook fires when Uncanny Automator is preparing to list WP Fluent Forms options for use in recipes.
Usage
add_filter( 'uap_option_list_wp_fluent_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the current option value, which can be modified by the filter.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the uap_option_list_wp_fluent_forms filter hook.
* This example adds an option to include the form's submission date as a token.
*/
add_filter( 'uap_option_list_wp_fluent_forms', 'my_custom_fluentforms_option_list', 10, 1 );
/**
* Adds submission date to the list of options and relevant tokens for WP Fluent Forms.
*
* @param array $option The original array of options and relevant tokens.
* @return array The modified array of options and relevant tokens.
*/
function my_custom_fluentforms_option_list( $option ) {
// Ensure the required keys exist before proceeding to avoid errors.
if ( ! isset( $option['options'] ) || ! isset( $option['relevant_tokens'] ) || ! isset( $option_code ) ) {
return $option;
}
// Define a new option key for the submission date.
$submission_date_key = $option_code . '_submission_date';
// Add the submission date option to the list.
$option['options'][ $submission_date_key ] = esc_attr_x( 'Form Submission Date', 'Wp Fluent Forms', 'uncanny-automator' );
// Add the submission date to the relevant tokens.
$option['relevant_tokens'][ $submission_date_key ] = esc_attr_x( 'Form Submission Date', 'Wp Fluent Forms', 'uncanny-automator' );
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/wp-fluent-forms/helpers/wp-fluent-forms-helpers.php:101
public function list_wp_fluent_forms( $label = null, $option_code = 'WPFFFORMS', $args = array() ) {
if ( ! $label ) {
$label = esc_attr_x( 'Form', 'Wp Fluent 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 ( Automator()->helpers->recipe->load_helpers ) {
if ( function_exists( 'wpFluent' ) ) {
$forms = wpFluent()->table( 'fluentform_forms' )
->select( array( 'id', 'title' ) )
->orderBy( 'id', 'DESC' )
->get();
if ( ! empty( $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_attr_x( 'Form title', 'Wp Fluent Forms', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr_x( 'Form ID', 'Wp Fluent Forms', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_list_wp_fluent_forms', $option );
}