diff --git a/includes/class-functions.php b/includes/class-functions.php index 3a770725..1c75d127 100644 --- a/includes/class-functions.php +++ b/includes/class-functions.php @@ -387,7 +387,7 @@ if ( ! class_exists( 'UM_Functions' ) ) { if ( is_array( $var ) ) { return array_map( array( $this, 'clean_array' ), $var ); } else { - return is_scalar( $var ) ? sanitize_text_field( $var ) : $var; + return ! is_scalar( $var ) ? sanitize_text_field( $var ) : $var; } } diff --git a/includes/core/class-form.php b/includes/core/class-form.php index 4d7dfa5b..b53dead8 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -122,8 +122,6 @@ if ( ! class_exists( 'um\core\Form' ) ) { if ( isset( $arr_options['post']['members_directory'] ) && 'yes' === $arr_options['post']['members_directory'] ) { $ajax_source_func = $_POST['child_callback']; if ( function_exists( $ajax_source_func ) ) { - $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); - global $wpdb; $values_array = $wpdb->get_col( @@ -137,7 +135,15 @@ if ( ! class_exists( 'um\core\Form' ) ) { ); if ( ! empty( $values_array ) ) { - $arr_options['items'] = array_intersect( $arr_options['items'], $values_array ); + $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); + + if ( array_keys( $arr_options['items'] ) !== range( 0, count( $arr_options['items'] ) - 1 ) ) { + // array with dropdown items is associative + $arr_options['items'] = array_intersect_key( array_map( 'trim', $arr_options['items'] ), array_flip( $values_array ) ); + } else { + // array with dropdown items has sequential numeric keys, starting from 0 and there are intersected values with $values_array + $arr_options['items'] = array_intersect( $arr_options['items'], $values_array ); + } } else { $arr_options['items'] = array(); } diff --git a/templates/members-grid.php b/templates/members-grid.php index 94bb5576..125e1564 100644 --- a/templates/members-grid.php +++ b/templates/members-grid.php @@ -18,7 +18,7 @@ $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?>