Filter
uncanny-automator
automator_option_select_field_ajax
Filters the data for the option select field's AJAX request, allowing modification before it's sent.
add_filter( 'automator_option_select_field_ajax', $callback, 10, 1 );
Description
Filters the options array for the select field AJAX request. Use this hook to modify, add, or remove options before they are returned to the frontend. Developers can dynamically adjust the available choices based on recipe context or other custom logic. The hook is fired after relevant tokens are determined and before the options are sent via AJAX.
Usage
add_filter( 'automator_option_select_field_ajax', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the selected option from a dropdown or select field.
Return Value
The filtered value.
Examples
<?php
/**
* Example to conditionally add a 'required' attribute to an option based on its value.
* This could be useful if certain option selections necessitate further input.
*
* @param array $option The option data being processed by the filter.
* @return array The modified option data.
*/
add_filter( 'automator_option_select_field_ajax', function( $option ) {
// Assuming the option array contains a 'value' key for the option's value
// and we want to mark options with a specific value as 'required'.
if ( isset( $option['value'] ) && 'specific_trigger_value' === $option['value'] ) {
// Add a flag to indicate this option requires further configuration.
$option['requires_additional_setup'] = true;
}
// Always return the modified (or unmodified) $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/core/lib/helpers/class-automator-recipe-helpers-field.php:629
public function select_field_ajax( $option_code = 'SELECT', $label = null, $options = array(), $default = null, $placeholder = '', $supports_token = false, $is_ajax = false, $args = array(), $relevant_tokens = array() ) {
// TODO this function should be the main way to create select fields
// TODO chained values should be introduced using the format in function "list_gravity_forms"
// TODO the following function should use this function to create selections
// -- less_or_greater_than
// -- all_posts
// -- all_pages
// -- all_ld_courses
// -- all_ld_lessons
// -- all_ld_topics
// -- all_ld_groups
// -- all_ld_quiz
// -- all_buddypress_groups
// -- all_wc_products
// -- list_contact_form7_forms
// -- list_bbpress_forums
// -- wc_order_statuses
// -- wp_user_roles
// -- list_gravity_forms
// -- all_ec_events
// -- all_lp_courses
// -- all_lp_lessons
// -- all_lf_courses
// -- all_lf_lessons
if ( ! $label ) {
$label = esc_attr__( 'Option', 'uncanny-automator' );
}
$token_name = isset( $args['token_name'] ) ? $args['token_name'] : '';
$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
$end_point = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
$description = key_exists( 'description', $args ) ? $args['description'] : null;
$custom_value_description = key_exists( 'custom_value_description', $args ) ? $args['custom_value_description'] : null;
// default true
$supports_custom_value = $this->supports_custom_value( $args );
$supports_tokens = key_exists( 'supports_tokens', $args ) ? $args['supports_tokens'] : null;
$supports_tokens = apply_filters_deprecated( 'uap_option_' . $option_code . '_select_field', array( $supports_tokens ), '3.0', 'automator_option_' . $option_code . '_select_field' );
$supports_tokens = apply_filters( 'automator_option_' . $option_code . '_select_field', $supports_tokens );
$token_name = apply_filters( 'automator_option_' . $option_code . '_select_field_token_name', $token_name, $args );
$options_show_id = empty( $args['options_show_id'] ) ? true : $args['options_show_id'];
$options_show_id = apply_filters( 'automator_options_show_id', $options_show_id, $this );
$option = array(
'option_code' => $option_code,
'label' => $label,
'description' => $description,
'input_type' => 'select',
'supports_tokens' => $supports_tokens,
'required' => true,
'default_value' => $default,
'options' => $options,
'custom_value_description' => $custom_value_description,
'supports_custom_value' => $supports_custom_value,
'is_ajax' => $is_ajax,
'fill_values_in' => $target_field,
'integration' => 'GF',
'endpoint' => $end_point,
'placeholder' => $placeholder,
'token_name' => $token_name,
'options_show_id' => $options_show_id,
);
if ( ! empty( $relevant_tokens ) ) {
$option['relevant_tokens'] = $relevant_tokens;
}
$option = apply_filters_deprecated( 'uap_option_select_field_ajax', array( $option ), '3.0', 'automator_option_select_field_ajax' );
return apply_filters( 'automator_option_select_field_ajax', $option );
}