Support » Plugins » Hacks » Update Display Name

  • Hello.

    I’m currently trying to make a “edit profile” page (WordPress + Buddypress).
    But when I’m trying to update the display name something strange happens.

    The data gets updated, and are shown in the backend. But the username is still shown in front end and not the display name.
    And this even happens if I close the browser and try again (or simply clears the cache).

    But if I go to the backend, and press “update user” without changing anything (since it shows the correct data) the changes takes place.

    The code looks like this:

    //Set display name
    $args = array(
    	'ID' => $current_user->ID,
    	'first_name' => 'tester',
    	'last_name' => 'testersen',
    	'nickname' => 'tester testersen',
    	'display_name' => 'tester testersen',
    );
    wp_update_user( $args );
    
    update_user_meta($current_user->ID, 'first_name', 'tester');
    update_user_meta($current_user->ID, 'last_name', 'testersen');
    update_user_meta($current_user->ID, 'nickname', 'tester testersen');
    update_user_meta($current_user->ID, 'display_name', 'tester testersen');

    And yes – I know it’s overkill, but I’m trying everything right now.

    I hope someone are able to help med 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • You’re probably looking for “user_nicename’

    http://codex.wordpress.org/Function_Reference/get_userdata

    on the update you probably want to reload getting the userdata as well

    Thread Starter maaggel

    (@maaggel)

    When I set the “user_nicename”, the url to the user acount changes (etc.: /members/tester/). But the name is still shown as the same.

    And the get user part sounds interesting.
    When I retrieve the data, shall I then call another function for it to be reloaded?

    And thank you for the response 🙂

    yes, absolutely retrieve the data again (AFTER UPDATING) because you need to set the internal variables

    Thread Starter maaggel

    (@maaggel)

    Hmm, I guess that makes sense.
    But since I havn’t done this before I’m not sure how to do it.

    Ive just tried to do this:

    wp_set_current_user( $current_user->ID, "tester" );
    wp_set_auth_cookie( $current_user->ID );
    do_action( 'wp_login', $current_user->user_login );

    But it doesn’t change anything.
    Can you perhaps send me a like to the function I should use to set the internal variables?

    I don’t know how either, (on the top of my head) .. how about just giving them a note about logging them off and log them off making them login again.

    Thread Starter maaggel

    (@maaggel)

    oh, well the problem is that the display name isn’t shown even if I do that. Even if I clear the cache, or even restarts the computer/use a different computer – it’s still that username that is shown.
    Even though it’s shown correctly in the backend :S

    It’s really really strange.. So I was thinking that perhaps it was a “use display name” flag that I needed to set.. But in the backend the display name is already set to “tester”

    Well this is how I do display name

    if(get_query_var('author_name') ) {
    		$curauth = get_user_by('slug', get_query_var('author_name'));
    	} else {
    		$curauth = get_userdata(get_query_var('author'));
    	}
    if($curauth->display_name)
    			$authorname = $curauth->display_name;
    		elseif($curauth->user_nickname)
    			$authorname = $curauth->nickname;
    		elseif($curauth->user_nicename)
    			$authorname = $curauth->user_nicename;
    		else
    			$authorname = $curauth->user_login;

    .. Just to make sure that I have $authorname covered

    Thread Starter maaggel

    (@maaggel)

    Thank you very very much 😀

    I’ve added your script to bp_core_get_user_displayname in bp-members-functions.php.
    And though it didn’t work right away, it worked when I cleared the cache for the user when changing the name.

    You’re a life saver 🙂

    I found some great clues on how to address my update display_name bug for my frontend profile page here: http://wordpress.stackexchange.com/questions/35403/forcing-nickname-as-display-name-in-custom-edit-profile-template

    Apparently, there are two database tables you have to update. Wasted many hours reviewing code to realize this.

    Moderator bcworkz

    (@bcworkz)

    Apparently, there are two database tables you have to update.

    In case anyone is wondering, the name in usermeta is “nickname”, corresponding to the same field in the User Profile panel. The display name in the user table corresponds to the display preference pull down in the User Profile. So yes, there are two different locations, and for many, they are the same value because most people want the nickname to be their display preference. But they are not the same thing, one is a data field and the other is a sort of pointer to one’s preferred field.

    What I don’t understand is how does user_nicename really come into play? The only place it shows up is in the admin bar user pulldown and you cannot set it anywhere in any admin panel.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Update Display Name’ is closed to new replies.