I fix this bug next way (Changes labeled // plugin-hack begin
, // plugin-hack end
)
bugfix for personal cabinet
wp-user-manager/includes/wpum-forms/class-wpum-form-profile.php:119
public function validate_nickname( $pass, $fields, $values, $form ) {
if ( $form == $this->form_name && isset( $values['account']['user_nickname'] ) ) {
// plugin-hack begin
global $wpdb;
$form_display_name = $fields['account']['user_displayname']['options'][$values['account']['user_displayname']];
// If the user_displayname has changed
if( $this->user->data->display_name !== $form_display_name ) {
$displayname = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users WHERE display_name = %s AND ID <> %d", $form_display_name, $this->user->ID ) );
if ( $displayname >= '1' ) {
return new WP_Error( 'displayname-unique-validation-error', esc_html__( 'This display name is already in use by someone else. Display names must be unique.', 'wp-user-manager' ) );
}
}
// plugin-hack end
$nickname = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users as users, $wpdb->usermeta as meta WHERE users.ID = meta.user_id AND meta.meta_key = 'nickname' AND meta.meta_value = %s AND users.ID <> %d", $values['account']['user_nickname'], $this->user->ID ) );
// plugin-hack begin
if ( $nickname >= '1' ) {
// plugin-hack end
return new WP_Error( 'displayname-unique-validation-error', esc_html__( 'This nickname is already in use by someone else. Nicknames must be unique.', 'wp-user-manager' ) );
}
}
return $pass;
}
And bugfix for admin-panel
wp-user-manager/includes/actions.php:236
function wpum_check_display_name( $user_id ) {
global $wpdb;
// plugin-hack begin
// Getting user data and user meta data.
$user_data = get_userdata($_POST['user_id']);
// If the user_displayname has changed
if( $user_data->data->display_name !== $_POST['display_name'] ) {
$err['display'] = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users WHERE display_name = %s AND ID <> %d", $_POST['display_name'], $_POST['user_id'] ) );
}
// plugin-hack end
$err['nick'] = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users as users, $wpdb->usermeta as meta WHERE users.ID = meta.user_id AND meta.meta_key = 'nickname' AND meta.meta_value = %s AND users.ID <> %d", $_POST['nickname'], $_POST['user_id'] ) );
foreach ( $err as $key => $e ) {
if ( $e >= 1 ) {
add_action( 'user_profile_update_errors', "wpum_check_{$key}_field", 10, 3 );
}
}
}
I have on my site more 60 Not unique “display_name” users. Respectively on other sites too will have not unique “display_name” users which will can’t update
profile, until change their “display-name” (it’s not logical for users), I suggest you add next condition
wp-user-manager/includes/wpum-forms/class-wpum-form-profile.php
public function validate_nickname( $pass, $fields, $values, $form ) {
...
if( $this->user->data->display_name !== $form_display_name ) {
wp-user-manager/includes/actions.php
function wpum_check_display_name( $user_id ) {
...
if( $user_data->data->display_name !== $_POST['display_name'] ) {
It checks whether user “display name” has changed, if “Yes” then you need to check whether there is the same in the database already, if not changed, we allow the user to update other fields, even if it does not have a unique display name.
Can you add these conditions or tell us about your alternative solution to this problem?
And also I found a bug – if we want create user from admin-panel
, we can make user with not unique “display name”, when we fill name
and second_name
, Display_name will fill automatically from the name, second_name without check on unique “display_name”