Filter
uncanny-automator
uap_option_all_forminator_forms
Filters all available Forminator form IDs, allowing for modification before they are listed.
add_filter( 'uap_option_all_forminator_forms', $callback, 10, 1 );
Description
Filters the available Forminator form tokens for Uncanny Automator, allowing developers to customize the form title and ID tokens presented to users. This hook fires when Uncanny Automator is retrieving Forminator form data, enabling modification or addition of options before they are displayed.
Usage
add_filter( 'uap_option_all_forminator_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter holds the value of the option being filtered, which in this case, represents a form.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the 'uap_option_all_forminator_forms' hook to modify the form data.
*
* This example demonstrates how to add custom information to the form data before it's returned.
* In this specific case, we'll add a new key-value pair to the 'relevant_tokens' array
* for each Forminator form.
*
* @param array $option The original array of Forminator form data.
* @return array The modified array of Forminator form data.
*/
add_filter( 'uap_option_all_forminator_forms', function( $option ) {
// Check if the $option is an array and contains the 'forms' key.
if ( is_array( $option ) && isset( $option['forms'] ) && is_array( $option['forms'] ) ) {
// Iterate through each form in the 'forms' array.
foreach ( $option['forms'] as &$form_data ) {
// Ensure the 'relevant_tokens' key exists for the current form.
if ( isset( $form_data['relevant_tokens'] ) && is_array( $form_data['relevant_tokens'] ) ) {
// Add a custom token representing the Forminator form's description (if available).
// This is a hypothetical example; you'd replace 'Forminator form description'
// with actual logic to retrieve or generate the description.
$custom_description_token_key = $form_data['option_code'] . '_description';
$custom_description_token_value = __( 'Forminator form description', 'your-text-domain' ); // Replace with actual description retrieval
$form_data['relevant_tokens'][ $custom_description_token_key ] = $custom_description_token_value;
}
}
}
// Always return the modified (or original if no changes) $option.
return $option;
}, 10, 1 );
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/forminator/helpers/forminator-helpers.php:105
public function all_forminator_forms( $label = null, $option_code = 'FRFORMS', $args = array() ) {
if ( ! $label ) {
$label = esc_attr__( 'Form', 'uncanny-automator' );
}
$args = wp_parse_args(
$args,
array(
'uo_include_any' => false,
'uo_any_label' => esc_attr__( 'Any 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 ) {
if ( $args['uo_include_any'] ) {
$options[- 1] = $args['uo_any_label'];
}
$forms = Forminator_API::get_forms( null, 1, 999 );
if ( ! empty( $forms ) ) {
foreach ( $forms as $form ) {
$options[ $form->id ] = isset( $form->settings ) && isset( $form->settings['form_name'] ) ? $form->settings['form_name'] : $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_attr__( 'Form title', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr__( 'Form ID', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_all_forminator_forms', $option );
}