From 0d86805510c7e3d10c096b01a5a64f2c05c8c9ef Mon Sep 17 00:00:00 2001 From: champsupertramp Date: Fri, 27 May 2016 14:28:15 +0800 Subject: [PATCH] Fix permalink base format --- core/um-permalinks.php | 12 ++++++++---- core/um-rewrite.php | 5 +++++ core/um-user.php | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/core/um-permalinks.php b/core/um-permalinks.php index 0aac2ea5..ab212b39 100644 --- a/core/um-permalinks.php +++ b/core/um-permalinks.php @@ -194,16 +194,20 @@ class UM_Permalinks { $profile_url = apply_filters('um_localize_permalink_filter', $this->core, $page_id, $profile_url ); - + // Username if ( um_get_option('permalink_base') == 'user_login' ) { $user_in_url = um_user('user_login'); - if ( is_email($user_in_url) ) { + if ( is_email( $user_in_url ) ) { + $user_email = $user_in_url; $user_in_url = str_replace('@','',$user_in_url); + if( ( $pos = strrpos( $user_in_url , '.' ) ) !== false ) { $search_length = strlen( '.' ); $user_in_url = substr_replace( $user_in_url , '-' , $pos , $search_length ); } + update_user_meta( um_user('ID') , 'um_email_as_username_'.$user_in_url , $user_email ); + } else { $user_in_url = sanitize_title( $user_in_url ); @@ -212,10 +216,12 @@ class UM_Permalinks { } + // User ID if ( um_get_option('permalink_base') == 'user_id' ) { $user_in_url = um_user('ID'); } + // Fisrt and Last name $full_name_permalinks = array( 'name', 'name_dash', 'name_plus' ); if( in_array( um_get_option( 'permalink_base'), $full_name_permalinks ) ) { @@ -344,8 +350,6 @@ class UM_Permalinks { break; } - - } if ( get_option('permalink_structure') ) { diff --git a/core/um-rewrite.php b/core/um-rewrite.php index 3343aa87..4aa2117f 100644 --- a/core/um-rewrite.php +++ b/core/um-rewrite.php @@ -124,6 +124,11 @@ class UM_Rewrite { if ( isset( $the_user->ID ) ){ $user_id = $the_user->ID; } + + if( !$user_id ){ + $user_id = $ultimatemember->user->user_exists_by_email_as_username( $slug ); + } + } } diff --git a/core/um-user.php b/core/um-user.php index ecf1e612..aa0eb638 100644 --- a/core/um-user.php +++ b/core/um-user.php @@ -944,6 +944,7 @@ class UM_User { return $ids[0]; } + $value = str_replace(".", "_", $value ); $value = str_replace(" ", "", $value ); @@ -989,5 +990,41 @@ class UM_User { return $user_id; } } + /** + * @function user_exists_by_email_as_username() + * + * @description This method checks if a user exists or not in your site based on the user email as username + * + * @usage user->user_exists_by_email_as_username( $slug ); ?> + * + * @param $slug (string) (required) A user slug must be passed to check if the user exists + * + * @returns Returns true if user exists and false if user does not exist. + * + * @example Basic Usage + + user->user_exists_by_email_as_username( 'calumgmail-com' ); + if ( $boolean ) { + // That user exists + } + + ?> + + * + * + */ + function user_exists_by_email_as_username( $slug ){ + + $user_id = false; + + $ids = get_users( array( 'fields' => 'ID', 'meta_key' => 'um_email_as_username_'.$slug ) ); + if ( isset( $ids[0] ) && ! empty( $ids[0] ) ){ + $user_id = $ids[0]; + } + + return $user_id; + } }