mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-15 20:53:39 +09:00
Fix permalink base name format and redirect loop in profile page
This commit is contained in:
@@ -4,9 +4,7 @@ add_filter("um_localize_permalink_filter","um_localize_permalink_filter",10,3);
|
||||
function um_localize_permalink_filter( $core_pages, $page_id, $profile_url ){
|
||||
global $ultimatemember;
|
||||
|
||||
get_post( $page_id );
|
||||
|
||||
if ( function_exists('icl_get_current_language') && icl_get_current_language() != icl_get_default_language() ) {
|
||||
if ( function_exists('icl_get_current_language') && icl_get_current_language() != icl_get_default_language() ) {
|
||||
if ( get_the_ID() > 0 && get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1 ) {
|
||||
$profile_url = get_permalink( get_the_ID() );
|
||||
}
|
||||
@@ -34,9 +32,5 @@ function um_localize_permalink_filter( $core_pages, $page_id, $profile_url ){
|
||||
add_filter('um_core_page_id_filter','um_core_page_id_filter');
|
||||
function um_core_page_id_filter( $page_id ){
|
||||
|
||||
/* if( ! empty( $_GET['lang'] ) && isset( $_GET['lang'] ) ){
|
||||
$page_id = $page_id.'_'.$_GET['lang'];
|
||||
}
|
||||
*/
|
||||
return $page_id;
|
||||
}
|
||||
@@ -80,10 +80,38 @@
|
||||
*/
|
||||
add_filter('um_clean_user_basename_filter','um_clean_user_basename_filter',2,10);
|
||||
function um_clean_user_basename_filter( $value, $raw ){
|
||||
global $wpdb;
|
||||
$permalink_base = um_get_option('permalink_base');
|
||||
|
||||
// Checks if last name has dash
|
||||
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
|
||||
$value = str_replace( '_', '-', $value );
|
||||
switch( $permalink_base ){
|
||||
case 'name':
|
||||
|
||||
$slugname = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT meta_value FROM ".$wpdb->usermeta." WHERE meta_key = %s ",
|
||||
'um_user_profile_url_slug_name_'.$raw,
|
||||
$raw
|
||||
)
|
||||
);
|
||||
|
||||
$value = $slugname;
|
||||
if( ! empty( $value ) && strrpos( $value ,".") > -1 ){
|
||||
$value = str_replace( '.', ' ', $value );
|
||||
}
|
||||
|
||||
// Checks if last name has a dash
|
||||
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
|
||||
$value = str_replace( '_', '. ', $value );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// Checks if last name has a dash
|
||||
if( ! empty( $value ) && strrpos( $value ,"_") > -1 && substr( $value , "_") == 1 ){
|
||||
$value = str_replace( '_', '-', $value );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
+33
-5
@@ -223,10 +223,7 @@ class UM_Permalinks {
|
||||
$last_name = um_user( 'last_name' );
|
||||
$count = intval( um_is_meta_value_exists( 'full_name', $full_name ) );
|
||||
|
||||
if( strpos( $last_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){
|
||||
$full_name = str_replace('-', '_', $full_name );
|
||||
}
|
||||
|
||||
|
||||
if( $count > 1 )
|
||||
{
|
||||
$full_name .= ' ' . um_user( 'ID' );
|
||||
@@ -235,15 +232,46 @@ class UM_Permalinks {
|
||||
switch( um_get_option('permalink_base') )
|
||||
{
|
||||
case 'name':
|
||||
$user_in_url = rawurlencode( strtolower( str_replace( " ", ".", $full_name ) ) );
|
||||
|
||||
$full_name_slug = $full_name;
|
||||
$difficulties = 0;
|
||||
|
||||
if( strpos( $full_name, '.' ) > -1 ){
|
||||
$full_name = str_replace(".", "_", $full_name );
|
||||
$difficulties++;
|
||||
}
|
||||
|
||||
$full_name = strtolower( str_replace( " ", ".", $full_name ) );
|
||||
|
||||
if( strpos( $full_name, '_.' ) > -1 ){
|
||||
$full_name = str_replace('_.', '_', $full_name );
|
||||
$difficulties++;
|
||||
}
|
||||
|
||||
$full_name_slug = str_replace( '-' , '.', $full_name_slug );
|
||||
$full_name_slug = str_replace( ' ' , '.', $full_name_slug );
|
||||
$full_name_slug = str_replace( '..' , '.', $full_name_slug );
|
||||
|
||||
if( $difficulties > 0 ){
|
||||
update_user_meta( um_user('ID'), 'um_user_profile_url_slug_name_'.$full_name_slug, $full_name );
|
||||
}
|
||||
|
||||
|
||||
$user_in_url = rawurlencode( $full_name_slug );
|
||||
|
||||
break;
|
||||
case 'name_dash':
|
||||
if( strpos( $last_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){
|
||||
$full_name = str_replace('-', '_', $full_name );
|
||||
}
|
||||
$user_in_url = rawurlencode( strtolower( str_replace(" ", "-", $full_name ) ) );
|
||||
break;
|
||||
case 'name_plus':
|
||||
$user_in_url = strtolower( str_replace(" ", "+" , $full_name ) );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ( get_option('permalink_structure') ) {
|
||||
|
||||
@@ -145,6 +145,7 @@
|
||||
function um_clean_user_basename( $value ) {
|
||||
|
||||
$raw_value = $value;
|
||||
$value = str_replace('.', ' ', $value);
|
||||
$value = str_replace('-', ' ', $value);
|
||||
$value = str_replace('+', ' ', $value);
|
||||
|
||||
|
||||
+2
-1
@@ -893,10 +893,11 @@ class UM_User {
|
||||
{
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
|
||||
$ids = get_users(array( 'fields' => 'ID', 'meta_key' => 'full_name','meta_value' => $value ,'meta_compare' => '=') );
|
||||
if ( isset( $ids[0] ) )
|
||||
return $ids[0];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user