Filter
uncanny-automator
uap_option_all_divi_forms
Filters all Divi form options, allowing modification before they are displayed or saved.
add_filter( 'uap_option_all_divi_forms', $callback, 10, 1 );
Description
Filters the options array used for selecting Divi forms within the Uncanny Automator plugin. Developers can use this hook to modify the available form options, add custom labels, or alter the default behavior of form selection in Divi integrations.
Usage
add_filter( 'uap_option_all_divi_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the option array which will be filtered by the hook.
Return Value
The filtered value.
Examples
/**
* Filters the list of Divi forms available for selection in the WordPress Automator plugin.
*
* This function adds an option to include all Divi forms if the user has the 'include_all' setting enabled.
* It also ensures that if a specific form ID is being updated, that form is prioritized or included.
*
* @param array $option The current list of Divi forms, usually an associative array where keys are form IDs and values are form titles.
* @return array The modified list of Divi forms.
*/
add_filter( 'uap_option_all_divi_forms', function( $option ) {
// Check if we need to include an 'any' option for flexibility.
// This logic might be dependent on other plugin settings, represented here by $args['uo_include_any'].
// In a real scenario, $args would be passed through from the context where the filter is applied.
// For this example, we'll assume $args is accessible or can be derived.
// Let's simulate having an $args array for demonstration.
$args = array(
'uo_include_any' => true, // Example: enable 'any' option
'uo_any_label' => 'Any Divi Form', // Example: label for 'any' option
'uo_update_form_id' => '123', // Example: a specific form ID being updated
);
if ( ! empty( $args['uo_include_any'] ) ) {
// Add an option to select 'Any Divi Form'.
// The key '-1' is often used for such general selections in plugins.
$option['-1'] = $args['uo_any_label'];
}
// In a real scenario, you might want to ensure a specific form is listed
// if it's the one being updated, or perhaps reorder the list.
// For instance, if $args['uo_update_form_id'] exists and is valid,
// you might want to make sure it's present in the $option array.
// This example focuses on adding the 'any' option.
// Example of ensuring a specific form is present (if it wasn't already)
// This is hypothetical as we don't have actual Divi form data here.
// $specific_form_id = $args['uo_update_form_id'];
// if ( ! isset( $option[ $specific_form_id ] ) ) {
// // Fetch the form title for this ID (e.g., from Divi API or stored options)
// $specific_form_title = get_post_meta( $specific_form_id, '_et_pb_form_id', true ); // Fictional example
// if ( $specific_form_title ) {
// $option[ $specific_form_id ] = $specific_form_title;
// }
// }
// Return the modified array of Divi forms.
return $option;
}, 10, 1 ); // Priority 10, accepts 1 argument.
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/divi/helpers/divi-helpers.php:100
src/integrations/divi/helpers/divi-helpers.php:117
public function all_divi_forms( $label = null, $option_code = 'DIVIMFORMS', $args = array() ) {
$label = null === $label ? esc_attr__( 'Form', 'uncanny-automator' ) : $label;
$args = wp_parse_args(
$args,
array(
'uo_include_any' => true,
'uo_any_label' => esc_attr__( 'Any form', 'uncanny-automator' ),
'uo_update_form_id' => false,
)
);
$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();
$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,
//'options_show_id' => false,
);
if ( ! Automator()->helpers->recipe->load_helpers ) {
return apply_filters( 'uap_option_all_divi_forms', $option );
}
if ( $args['uo_include_any'] ) {
$options['-1'] = $args['uo_any_label'];
}
$data = self::extract_forms( $args['uo_update_form_id'] );
if ( $data ) {
foreach ( $data as $form_id => $d ) {
$options[ $form_id ] = $d['title'];
}
}
$option['options'] = $options;
return apply_filters( 'uap_option_all_divi_forms', $option );
}