The MU forums have moved to WordPress.org

[BUG] Can't change Display Name in profile after update_usermeta (5 posts)

  1. mdgross
    Member
    Posted 14 years ago #

    So I've updated my display name using:

    update_usermeta(1, 'display_name', 'Some Name');

    Now when I access my profile and select a different name using the drop-down it doesn't actually change when I hit "update profile."

    The only way to change it back is to use update_usermeta again.... Please help!

    Update: I've tried using the default "update profile" functionality on other users for which I've never done update_usermeta and it is working as intended.

    It seems that once I use the update_usermeta to change the display name once that setting is forever broken in the user's profile. Even if I use update_usermeta to change the display name back to the default value it still won't let me make any more changes using the profile.

    Once I use update_usermeta on a user's display name the only way I can change it is with the code again... it seems that the profile gets "stuck"

  2. DeannaS
    Member
    Posted 14 years ago #

    That's because the display name isn't "usermeta." The usermeta is stored in the wp_usermeta table. The display name is stored in the wp_user table. The info from the wp_user table is called first when a new user class is instantiated. Then, the usermeta info is added to it. So, now that you have a field with the same name in the usermeta table, it is overwriting the core user display name.

    To fix it - go into your database and remove that usermeta field. And, don't update the display_name via the update_usermeta code.

  3. mdgross
    Member
    Posted 14 years ago #

    DennaS, thank you for your assistance. How would you recommend updating the display_name then?

  4. mdgross
    Member
    Posted 14 years ago #

    Tried this to no avail...

    wp_update_user(array("ID" => 1, "display_name" => 'some name'));

  5. DeannaS
    Member
    Posted 14 years ago #

    Well, the manual way would be something like so:

    $wpdb->query( $wpdb->prepare("UPDATE $wpdb->users SET display_name = %s WHERE ID = %d", $id, $user->ID) );

    Otherwise, it looks like the edit_user() function expects post variables. It's not written to be called stand-alone. But you could probably hack it like so:

    $userid = 99;
    $_POST['display_name'] = 'your new display name';
    edit_user( $userid );

About this Topic