From 74292fe18b18800dc5f9d4d3ce732d8bce2928e4 Mon Sep 17 00:00:00 2001 From: champsupertramp Date: Mon, 5 Sep 2016 23:30:56 +0800 Subject: [PATCH] Fix profile permalink structure --- core/um-permalinks.php | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/core/um-permalinks.php b/core/um-permalinks.php index ceb30f13..2dad6e96 100644 --- a/core/um-permalinks.php +++ b/core/um-permalinks.php @@ -280,25 +280,30 @@ class UM_Permalinks { $last_name = um_user( 'last_name' ); $full_name = um_user( 'display_name' ); - if( in_array( $permalink_base, array( 'user_login' ) ) ){ - $search = um_user( 'display_name' ); - }else{ - $search = "{$first_name} {$last_name}"; + $arr_search_keywords = array( um_user( 'display_name' ), "{$first_name} {$last_name}"); + + foreach ( $arr_search_keywords as $keyword ) { + + $search = preg_replace('/\s+/', ' ', $keyword ); + + // Check for duplicate names + $args = array( + 'search' => $search, + 'search_columns' => array( 'display_name' ), + 'orderby' => 'registered', + 'order' => 'ASC', + 'fields' => array('user_registered','ID') + ); + + $user_query = new WP_User_Query( $args ); + if( $user_query->total_users > 1 ){ + break; + } + } + // Remove double spaces $full_name = preg_replace('/\s+/', ' ', $full_name); - $search = preg_replace('/\s+/', ' ', $search ); - - // Check for duplicate names - $args = array( - 'search' => $search, - 'search_columns' => array( 'display_name' ), - 'orderby' => 'registered', - 'order' => 'ASC', - 'fields' => array('user_registered','ID') - ); - - $user_query = new WP_User_Query( $args ); $duplicate_hash_name = md5( $full_name );