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!
Jonadd_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; }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Forcing a unique nickname’ is closed to new replies.