From e6e9bd17d808430402df6179df2a394af7f3e85f Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Tue, 14 Dec 2021 02:08:15 +0200 Subject: [PATCH] - fixed using callback for member directory fields; - fixed "false" display name in the member directory. it displays empty for now; - fixed function for cleaning and sanitize arrays; --- includes/class-functions.php | 2 +- includes/core/class-form.php | 12 +++++++++--- templates/members-grid.php | 18 ++++++++++-------- templates/members-list.php | 16 +++++++++------- 4 files changed, 29 insertions(+), 19 deletions(-) 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 ); ?>
@@ -27,7 +27,7 @@ $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?> if ( $profile_photo ) { ?>
- + {{{user.avatar}}} @@ -37,11 +37,13 @@ $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?>
- + <# if ( user.display_name_html ) { #> + + <# } #> 100 @@ -148,4 +150,4 @@ $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?>
- \ No newline at end of file + diff --git a/templates/members-list.php b/templates/members-list.php index 1355fa24..09ab2d75 100644 --- a/templates/members-list.php +++ b/templates/members-list.php @@ -15,7 +15,7 @@ $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?>
- + {{{user.avatar}}} @@ -27,11 +27,13 @@ $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?>
- + <# if ( user.display_name_html ) { #> + + <# } #> {{{user.hook_just_after_name}}} @@ -148,4 +150,4 @@ $unique_hash = substr( md5( $args['form_id'] ), 10, 5 ); ?> <# } #>
- \ No newline at end of file +