diff --git a/assets/js/um-scripts.js b/assets/js/um-scripts.js index 4cc430e3..a1a99e5d 100644 --- a/assets/js/um-scripts.js +++ b/assets/js/um-scripts.js @@ -325,6 +325,7 @@ jQuery(document).ready(function() { url: um_scripts.ajax_select_options, type: 'post', data: { + parent_option_name: parent_option, parent_option: parent.val(), child_callback: um_ajax_source, child_name: me.attr('name'), diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 05224530..c963e1f6 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -675,10 +675,11 @@ if (in_array( $type, array( 'select', 'multiselect' ) ) && isset( $data['custom_dropdown_options_source'] ) && !empty( $data['custom_dropdown_options_source'] )) { - if (function_exists( $data['custom_dropdown_options_source'] )) { - - $arr_options = call_user_func( $data['custom_dropdown_options_source'] ); - + if ( function_exists( $data['custom_dropdown_options_source'] ) ) { + + $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] ); + + if ($type == 'select') { if (isset( $arr_options[$value] ) && !empty( $arr_options[$value] )) { return $arr_options[$value]; @@ -726,15 +727,10 @@ */ function get_options_from_callback( $data, $type ) { + if ( in_array( $type, array( 'select', 'multiselect' ) ) && isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ) { - if (in_array( $type, array( 'select', 'multiselect' ) ) && isset( $data['custom_dropdown_options_source'] ) && !empty( $data['custom_dropdown_options_source'] )) { - - if (function_exists( $data['custom_dropdown_options_source'] )) { - - $arr_options = call_user_func( $data['custom_dropdown_options_source'] ); - - } - + $arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] ); + } @@ -1869,7 +1865,7 @@ $has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) && um_user( $data['parent_dropdown_relationship'] ) ) { - $options = call_user_func( $data['custom_dropdown_options_source'] ); + $options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] ); $disabled_by_parent_option = ''; if (um_user( $form_key )) { $select_original_option_value = " data-um-original-value='" . um_user( $form_key ) . "' "; diff --git a/includes/core/class-form.php b/includes/core/class-form.php index de6ec7b6..4a6dc606 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -71,7 +71,7 @@ if ( ! class_exists( 'Form' ) ) { $arr_options['field'] = $form_fields[ $_POST['child_name'] ]; if( function_exists( $ajax_source_func ) ){ - $arr_options['items'] = call_user_func( $ajax_source_func ); + $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); } }else{