• Resolved janwyl

    (@janwyl)


    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://www.ads-software.com/plugins/profile-builder/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter janwyl

    (@janwyl)

    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

    (@adispiac)

    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

    (@janwyl)

    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.