mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-18 14:13:46 +09:00
- fixed unique address of the user's link
This commit is contained in:
@@ -22,6 +22,8 @@ if ( ! class_exists( 'Permalinks' ) ) {
|
||||
remove_action( 'wp_head', 'rel_canonical' );
|
||||
|
||||
add_action( 'wp_head', array( &$this, 'um_rel_canonical_' ), 9 );
|
||||
|
||||
add_filter( 'um_user_pre_updating_profile_array', array( &$this, 'um_user_pre_updating_profile_array') );
|
||||
}
|
||||
|
||||
|
||||
@@ -249,6 +251,7 @@ if ( ! class_exists( 'Permalinks' ) ) {
|
||||
// Permalink base
|
||||
$permalink_base = UM()->options()->get( 'permalink_base' );
|
||||
|
||||
|
||||
// Get user slug
|
||||
$profile_slug = get_user_meta( um_user('ID'), "um_user_profile_url_slug_{$permalink_base}", true );
|
||||
$generate_slug = UM()->options()->get( 'um_generate_slug_in_directory' );
|
||||
@@ -298,61 +301,54 @@ if ( ! class_exists( 'Permalinks' ) ) {
|
||||
|
||||
// Fisrt and Last name
|
||||
$full_name_permalinks = array( 'name', 'name_dash', 'name_plus' );
|
||||
if( in_array( $permalink_base, $full_name_permalinks ) )
|
||||
{
|
||||
$opt_display_name = UM()->options()->get( 'display_name' );
|
||||
$first_name = um_user( 'first_name' );
|
||||
$last_name = um_user( 'last_name' );
|
||||
$full_name = um_user( 'display_name' );
|
||||
$full_name = preg_replace('/\s+/', ' ', $full_name); // Remove double spaces
|
||||
|
||||
$profile_slug = $this->profile_slug( $full_name, $first_name, $last_name );
|
||||
if ( in_array( $permalink_base, $full_name_permalinks ) ) {
|
||||
$separated = array('name' => '.','name_dash' =>'-','name_plus'=>'+');
|
||||
$separate = $separated[$permalink_base];
|
||||
$opt_display_name = UM()->options()->get( 'display_name' );
|
||||
$first_name = um_user( 'first_name' );
|
||||
$last_name = um_user( 'last_name' );
|
||||
$full_name = sprintf('%s %s',$first_name,$last_name);
|
||||
$full_name = preg_replace( '/\s+/', ' ', $full_name ); // Remove double spaces
|
||||
$profile_slug = UM()->permalinks()->profile_slug( $full_name, $first_name, $last_name );
|
||||
|
||||
$duplicate_slug_hash = md5( $profile_slug );
|
||||
if ( isset($update_slug['need_change_permalink']) && $update_slug['need_change_permalink'] == true ) {
|
||||
|
||||
$args = array(
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => "um_user_profile_url_slug_{$permalink_base}",
|
||||
'value' => $profile_slug,
|
||||
'compare' => '='
|
||||
),
|
||||
),
|
||||
'orderby' => 'registered',
|
||||
'order' => 'ASC',
|
||||
'fields' => array('user_registered','ID'),
|
||||
);
|
||||
$append = 0;
|
||||
$username = $full_name;
|
||||
$_username = $full_name;
|
||||
|
||||
$user_query = new \WP_User_Query( $args );
|
||||
while ( 1 ) {
|
||||
$username = $_username . ( empty( $append ) ? '' : " $append" );
|
||||
if ( ! $this->exist_url_slug_permalink_base( $permalink_base, $profile_slug . ( empty( $append ) ? '' : "{$separate}{$append}" ) ) ) {
|
||||
break;
|
||||
}
|
||||
$append ++;
|
||||
|
||||
if( $user_query->total_users > 1 ){
|
||||
}
|
||||
}
|
||||
|
||||
$duplicate_names = $user_query->get_results();
|
||||
|
||||
$current = end( $duplicate_names );
|
||||
|
||||
update_option("um_duplicate_name_{$duplicate_slug_hash}", $current->ID );
|
||||
|
||||
}
|
||||
|
||||
$duplicate_id = get_option("um_duplicate_name_{$duplicate_slug_hash}");
|
||||
|
||||
if( ! empty( $duplicate_id ) && $duplicate_id != um_user('ID') ){
|
||||
$full_name = $full_name.' ' . um_user( 'ID' );
|
||||
}
|
||||
|
||||
$user_in_url = $this->profile_slug( $full_name, $first_name, $last_name );
|
||||
|
||||
}
|
||||
$user_in_url = $this->profile_slug( $username, $first_name, $last_name );
|
||||
error_log('<pre>'.print_r($user_in_url,true).'</pre>');
|
||||
}
|
||||
|
||||
update_user_meta( um_user('ID'), "um_user_profile_url_slug_{$permalink_base}", $user_in_url );
|
||||
|
||||
$profile_url = $this->profile_permalink( $user_in_url );
|
||||
|
||||
return $profile_url;
|
||||
}
|
||||
|
||||
|
||||
function exist_url_slug_permalink_base( $permalink_base, $slug ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( $user_id = $wpdb->get_var( "SELECT `user_id` FROM `{$wpdb->usermeta}` WHERE `meta_key` = 'um_user_profile_url_slug_{$permalink_base}' AND `meta_value` = '{$slug}'" ) ) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Profile Permalink
|
||||
* @param string $slug
|
||||
@@ -512,5 +508,16 @@ if ( ! class_exists( 'Permalinks' ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $to_update
|
||||
*/
|
||||
function um_user_pre_updating_profile_array( $to_update ) {
|
||||
|
||||
if ( um_user( 'first_name' ) != $to_update['first_name'] ||
|
||||
um_user( 'last_name' ) != $to_update['last_name'] ) {
|
||||
$to_update['need_change_permalink'] = true;
|
||||
}
|
||||
return $to_update;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ if ( ! class_exists( 'User' ) ) {
|
||||
);
|
||||
$args = apply_filters( 'um_admin_pending_queue_filter', $args );
|
||||
$users = new \WP_User_Query( $args );
|
||||
|
||||
|
||||
delete_option( 'um_cached_users_queue' );
|
||||
add_option( 'um_cached_users_queue', $users->get_total(), '', 'no' );
|
||||
|
||||
@@ -166,112 +166,103 @@ if ( ! class_exists( 'User' ) ) {
|
||||
|
||||
|
||||
function get_profile_url( $user_id, $update_slug = false ) {
|
||||
// Permalink base
|
||||
$permalink_base = UM()->options()->get( 'permalink_base' );
|
||||
|
||||
// Permalink base
|
||||
$permalink_base = UM()->options()->get( 'permalink_base' );
|
||||
// Get user slug
|
||||
$profile_slug = get_user_meta( $user_id, "um_user_profile_url_slug_{$permalink_base}", true );
|
||||
$generate_slug = UM()->options()->get( 'um_generate_slug_in_directory' );
|
||||
|
||||
// Get user slug
|
||||
$profile_slug = get_user_meta( $user_id, "um_user_profile_url_slug_{$permalink_base}", true );
|
||||
$generate_slug = UM()->options()->get( 'um_generate_slug_in_directory' );
|
||||
|
||||
// Return existing profile slug
|
||||
if ( $generate_slug && $update_slug == false && $profile_slug )
|
||||
return UM()->permalinks()->profile_permalink( $profile_slug );
|
||||
// Return existing profile slug
|
||||
if ( $generate_slug && $update_slug == false && $profile_slug ) {
|
||||
return UM()->permalinks()->profile_permalink( $profile_slug );
|
||||
}
|
||||
|
||||
|
||||
// Reset cache
|
||||
if ( $update_slug == true ) {
|
||||
delete_option( "um_cache_userdata_{$user_id}" );
|
||||
um_fetch_user( $user_id );
|
||||
}
|
||||
// Reset cache
|
||||
if ( $update_slug == true ) {
|
||||
delete_option( "um_cache_userdata_{$user_id}" );
|
||||
um_fetch_user( $user_id );
|
||||
}
|
||||
|
||||
$userdata = get_userdata( $user_id );
|
||||
$userdata = get_userdata( $user_id );
|
||||
|
||||
if ( empty( $userdata ) )
|
||||
return UM()->permalinks()->profile_permalink( $profile_slug );
|
||||
if ( empty( $userdata ) ) {
|
||||
return UM()->permalinks()->profile_permalink( $profile_slug );
|
||||
}
|
||||
|
||||
$user_in_url = '';
|
||||
// Username
|
||||
if ( $permalink_base == 'user_login' ) {
|
||||
$user_in_url = $userdata->user_login;
|
||||
$user_in_url = '';
|
||||
// Username
|
||||
if ( $permalink_base == 'user_login' ) {
|
||||
$user_in_url = $userdata->user_login;
|
||||
|
||||
if ( is_email( $user_in_url ) ) {
|
||||
$user_email = $user_in_url;
|
||||
$user_in_url = str_replace('@','',$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( $user_id , "um_email_as_username_{$user_in_url}" , $user_email );
|
||||
if ( ( $pos = strrpos( $user_in_url, '.' ) ) !== false ) {
|
||||
$search_length = strlen( '.' );
|
||||
$user_in_url = substr_replace( $user_in_url, '-', $pos, $search_length );
|
||||
}
|
||||
update_user_meta( $user_id, "um_email_as_username_{$user_in_url}", $user_email );
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
$user_in_url = sanitize_title( $user_in_url );
|
||||
$user_in_url = sanitize_title( $user_in_url );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User ID
|
||||
if ( $permalink_base == 'user_id' )
|
||||
$user_in_url = $user_id;
|
||||
// User ID
|
||||
if ( $permalink_base == 'user_id' ) {
|
||||
$user_in_url = $user_id;
|
||||
}
|
||||
|
||||
// Fisrt and Last name
|
||||
$full_name_permalinks = array( 'name', 'name_dash', 'name_plus' );
|
||||
if ( in_array( $permalink_base, $full_name_permalinks ) ) {
|
||||
// Fisrt and Last name
|
||||
$full_name_permalinks = array( 'name', 'name_dash', 'name_plus' );
|
||||
if ( in_array( $permalink_base, $full_name_permalinks ) ) {
|
||||
$separated = array('name' => '.','name_dash' =>'-','name_plus'=>'+');
|
||||
$separate = $separated[$permalink_base];
|
||||
$first_name = $userdata->first_name;
|
||||
$last_name = $userdata->last_name;
|
||||
$full_name = sprintf('%s %s',$first_name,$last_name);
|
||||
|
||||
$first_name = $userdata->first_name;
|
||||
$last_name = $userdata->last_name;
|
||||
$full_name = $userdata->display_name;
|
||||
$full_name = preg_replace( '/\s+/', ' ', $full_name ); // Remove double spaces
|
||||
|
||||
$full_name = preg_replace( '/\s+/', ' ', $full_name ); // Remove double spaces
|
||||
$profile_slug = UM()->permalinks()->profile_slug( $full_name, $first_name, $last_name );
|
||||
|
||||
$profile_slug = UM()->permalinks()->profile_slug( $full_name, $first_name, $last_name );
|
||||
$current_slug = get_user_meta( $user_id, "um_user_profile_url_slug_{$permalink_base}", true );
|
||||
if ( $current_slug ) {
|
||||
$username = $current_slug;
|
||||
} else {
|
||||
|
||||
$duplicate_slug_hash = md5( $profile_slug );
|
||||
$append = 0;
|
||||
$username = $full_name;
|
||||
$_username = $full_name;
|
||||
|
||||
$args = array(
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => "um_user_profile_url_slug_{$permalink_base}",
|
||||
'value' => $profile_slug,
|
||||
'compare' => '='
|
||||
),
|
||||
),
|
||||
'orderby' => 'registered',
|
||||
'order' => 'ASC',
|
||||
'fields' => array('user_registered','ID'),
|
||||
);
|
||||
while ( 1 ) {
|
||||
|
||||
$user_query = new \WP_User_Query( $args );
|
||||
$username = $_username .(empty($append)?'':" $append" );
|
||||
if(!UM()->permalinks()->exist_url_slug_permalink_base( $permalink_base, $profile_slug . (empty($append)?'':"{$separate}{$append}" ) )){
|
||||
break;
|
||||
}
|
||||
$append++;
|
||||
|
||||
if ( $user_query->get_total() > 1 ) {
|
||||
}
|
||||
}
|
||||
$user_in_url = UM()->permalinks()->profile_slug( $username, $first_name, $last_name );
|
||||
}
|
||||
|
||||
$duplicate_names = $user_query->get_results();
|
||||
update_user_meta( $user_id, "um_user_profile_url_slug_{$permalink_base}", $user_in_url );
|
||||
|
||||
$current = end( $duplicate_names );
|
||||
if ( empty ( $user_in_url ) ) {
|
||||
$user_in_url = $user_id;
|
||||
}
|
||||
|
||||
update_option( "um_duplicate_name_{$duplicate_slug_hash}", $current->ID );
|
||||
return UM()->permalinks()->profile_permalink( $user_in_url );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$duplicate_id = get_option( "um_duplicate_name_{$duplicate_slug_hash}" );
|
||||
|
||||
if ( ! empty( $duplicate_id ) && $duplicate_id != $user_id )
|
||||
$full_name = trim( $full_name . ' ' . $user_id );
|
||||
|
||||
$user_in_url = UM()->permalinks()->profile_slug( $full_name, $first_name, $last_name );
|
||||
}
|
||||
|
||||
update_user_meta( $user_id, "um_user_profile_url_slug_{$permalink_base}", $user_in_url );
|
||||
|
||||
if ( empty ( $user_in_url )) {
|
||||
$user_in_url = $user_id;
|
||||
}
|
||||
|
||||
return UM()->permalinks()->profile_permalink( $user_in_url );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -305,26 +296,37 @@ if ( ! class_exists( 'User' ) ) {
|
||||
* @param int $user_id
|
||||
* @param \WP_User $old_data
|
||||
*/
|
||||
function profile_update( $user_id, $old_data ) {
|
||||
// Bail if no user ID was passed
|
||||
if ( empty( $user_id ) )
|
||||
return;
|
||||
function profile_update( $user_id, $old_data ) {
|
||||
// Bail if no user ID was passed
|
||||
if ( empty( $user_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$old_roles = $old_data->roles;
|
||||
$userdata = get_userdata( $user_id );
|
||||
$new_roles = $userdata->roles;
|
||||
$old_roles = $old_data->roles;
|
||||
$userdata = get_userdata( $user_id );
|
||||
$new_roles = $userdata->roles;
|
||||
|
||||
if ( ! empty( $_POST['um-role'] ) ) {
|
||||
$new_roles = array_merge( $new_roles, array( $_POST['um-role'] ) );
|
||||
if ( ! user_can( $user_id, $_POST['um-role'] ) ) {
|
||||
UM()->roles()->set_role( $user_id, $_POST['um-role'] );
|
||||
}
|
||||
}
|
||||
if ( ! empty( $_POST['um-role'] ) ) {
|
||||
$new_roles = array_merge( $new_roles, array( $_POST['um-role'] ) );
|
||||
if ( ! user_can( $user_id, $_POST['um-role'] ) ) {
|
||||
UM()->roles()->set_role( $user_id, $_POST['um-role'] );
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'um_after_member_role_upgrade', $new_roles, $old_roles );
|
||||
do_action( 'um_after_member_role_upgrade', $new_roles, $old_roles );
|
||||
|
||||
$this->remove_cache( $user_id );
|
||||
}
|
||||
//Update permalink
|
||||
$changes = apply_filters( 'um_user_edit_after_updating_profile_array', $_POST );
|
||||
if ( isset( $changes['need_change_permalink'] ) && $changes['need_change_permalink'] == true ) {
|
||||
|
||||
$pre_user_id = um_user( 'ID' );
|
||||
um_fetch_user( $user_id );
|
||||
UM()->permalinks()->profile_url( $changes );
|
||||
um_fetch_user( $pre_user_id );
|
||||
}
|
||||
|
||||
$this->remove_cache( $user_id );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -183,7 +183,7 @@ function um_submit_account_errors_hook( $args ) {
|
||||
delete_user_meta( um_user('ID'), 'hide_in_members' );
|
||||
unset( $changes['hide_in_members'] );
|
||||
}
|
||||
|
||||
$changes = apply_filters( 'um_account_pre_updating_profile_array', $changes );
|
||||
// fired on account page, just before updating profile
|
||||
do_action('um_account_pre_update_profile', $changes, um_user('ID') );
|
||||
|
||||
@@ -191,7 +191,7 @@ function um_submit_account_errors_hook( $args ) {
|
||||
|
||||
do_action('um_post_account_update');
|
||||
|
||||
do_action('um_after_user_account_updated', get_current_user_id() );
|
||||
do_action('um_after_user_account_updated', get_current_user_id(), $changes);
|
||||
|
||||
$url = '';
|
||||
if ( um_is_core_page( 'account' ) ) {
|
||||
@@ -260,4 +260,19 @@ function um_submit_account_errors_hook( $args ) {
|
||||
function um_account_secure_registered_fields(){
|
||||
$secure_fields = UM()->account()->register_fields;
|
||||
update_user_meta( um_user('ID'), 'um_account_secure_fields', $secure_fields );
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'um_account_pre_updating_profile_array','um_account_pre_updating_profile_array_1' );
|
||||
function um_account_pre_updating_profile_array_1( $to_update ) {
|
||||
|
||||
if ( um_user( 'first_name' ) != $to_update['first_name'] ||
|
||||
um_user( 'last_name' ) != $to_update['last_name'] ) {
|
||||
$to_update['need_change_permalink'] = true;
|
||||
}
|
||||
return $to_update;
|
||||
}
|
||||
|
||||
add_action('um_after_user_account_updated','um_after_user_account_updated_1',10,2);
|
||||
function um_after_user_account_updated_1($user_id,$changed){
|
||||
UM()->permalinks()->profile_url($changed);
|
||||
}
|
||||
@@ -185,3 +185,22 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
return $changes;
|
||||
}
|
||||
|
||||
add_filter('insert_user_meta','um_user_edit_after_updating_profile_array',10,3);
|
||||
function um_user_edit_after_updating_profile_array($meta, $user, $update){
|
||||
if (!empty($_POST['user_id'])){
|
||||
if(get_user_meta( $_POST['user_id'],'first_name',true ) != $meta['first_name'] ||
|
||||
get_user_meta( $_POST['user_id'],'last_name',true ) != $meta['last_name']){
|
||||
add_filter( 'um_user_edit_after_updating_profile_array','um_user_edit_after_updating_profile_array_1' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
function um_user_edit_after_updating_profile_array_1( $to_update ) {
|
||||
$to_update['need_change_permalink'] = true;
|
||||
|
||||
return $to_update;
|
||||
}
|
||||
Reference in New Issue
Block a user