Filter
uncanny-automator
uap_option_list_caldera_forms_forms
Filters the list of available Caldera Forms to display in UAP settings when the integration is active.
add_filter( 'uap_option_list_caldera_forms_forms', $callback, 10, 1 );
Description
Filters the list of available forms when integrating with Caldera Forms. Developers can use this hook to modify the form options, add custom properties, or filter out specific forms before they are displayed in the Uncanny Automator form selection. This hook fires when generating the list of Caldera Forms available for automation.
Usage
add_filter( 'uap_option_list_caldera_forms_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the array of options for the Caldera Forms dropdown, which will be filtered by the hook.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'uap_option_list_caldera_forms_forms' filter.
*
* This filter allows you to modify the options array that is passed to the
* UAP plugin when it's fetching a list of Caldera Forms. In this example,
* we're adding a custom 'data_attribute' to each form option.
*/
add_filter( 'uap_option_list_caldera_forms_forms', function( $option ) {
// Check if the $option is an array and contains the expected structure.
if ( is_array( $option ) && ! empty( $option['forms'] ) && is_array( $option['forms'] ) ) {
// Iterate through each form in the $option['forms'] array.
foreach ( $option['forms'] as $form_id => &$form_data ) {
// Add a custom data attribute to the form data.
// This could be used by frontend JavaScript for various purposes.
$form_data['data_attribute'] = 'caldera-form-' . $form_id;
}
}
// Always return the modified (or original) $option array.
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/caldera-forms/helpers/caldera-helpers.php:92
public function list_caldera_forms_forms( $label = null, $option_code = 'CFFORMS', $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 ) {
$forms = Caldera_Forms_Forms::get_forms( true );
if ( ! empty( $forms ) ) {
foreach ( $forms as $form ) {
$options[ $form['ID'] ] = $form['name'];
}
}
}
$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,
);
return apply_filters( 'uap_option_list_caldera_forms_forms', $option );
}