Title: Forcing a unique nickname
Last modified: August 22, 2016

---

# Forcing a unique nickname

 *  Resolved [janwyl](https://wordpress.org/support/users/janwyl/)
 * (@janwyl)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/forcing-a-unique-nickname/)
 * Hi there
 * I know the upgrade to 2.0 has removed filters, including the one I was using 
   to force a unique nickname. I have looked into the new code and have now put 
   the following into my functions file which seems to do what I want it to do (
   force a unique nickname). Although it seems to be working fine, can you see any
   reason why it might not in some circumstances?
 * Thanks!
    Jon
 *     ```
       add_filter('wppb_check_form_field_default-nickname', 'rf_force_unique_nickname', 11, 4);
   
       function rf_force_unique_nickname( $message, $field, $global_request, $form_type_args ) {
   
       	$nickname = $global_request['nickname'];
   
       	global $wpdb, $current_user;
   
       	//get user ID
       	get_currentuserinfo();
       	$curr_userid = $current_user->ID;
   
       	//check if new nickname is unique
       	$qtext = '
       		SELECT COUNT(users.id) AS nickname_check
       		FROM wp_[prefix]_users AS users
       		INNER JOIN wp_[prefix]_usermeta AS meta ON users.id = meta.user_id
       		WHERE meta.meta_key = %s AND meta.meta_value = %s AND user_id <> %d
       	';
   
       	$matches = $wpdb->get_var($wpdb->prepare($qtext, 'nickname', $nickname, $curr_userid));
   
       	if ( $matches > 0 ) { //if chosen nickname is already taken
       		$message = 'Unfortunately your choice of Nickname has already been taken. Please try another.';
       	}
   
       	return $message;
   
       }
       ```
   
 * [https://wordpress.org/plugins/profile-builder/](https://wordpress.org/plugins/profile-builder/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [janwyl](https://wordpress.org/support/users/janwyl/)
 * (@janwyl)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/forcing-a-unique-nickname/#post-5420832)
 * PS forgot to say I’m not using the register form to create users. So I only need
   to force the unique nickname on the edit profile field…
 *  Plugin Author [adispiac](https://wordpress.org/support/users/adispiac/)
 * (@adispiac)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/forcing-a-unique-nickname/#post-5420989)
 * Hi,
    Had a look at the code, tested it out and everything seems to work fine.
   So, you can use it with confidence 🙂
 *  Thread Starter [janwyl](https://wordpress.org/support/users/janwyl/)
 * (@janwyl)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/forcing-a-unique-nickname/#post-5421001)
 * Great! Thanks very much for taking the trouble to check it out…

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Forcing a unique nickname’ is closed to new replies.

 * ![](https://ps.w.org/profile-builder/assets/icon-256x256.png?rev=2961144)
 * [User Profile Builder - Beautiful User Registration Forms, User Profiles & User Role Editor](https://wordpress.org/plugins/profile-builder/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/profile-builder/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/profile-builder/)
 * [Active Topics](https://wordpress.org/support/plugin/profile-builder/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/profile-builder/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/profile-builder/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [janwyl](https://wordpress.org/support/users/janwyl/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/forcing-a-unique-nickname/#post-5421001)
 * Status: resolved