Support » Plugins » Hacks » Current user display_name does not update

  • Resolved michalmusial



    I would like to update user’s display_name and first_name.
    I am doing it this way:

    $current_user = wp_get_current_user();
    $update = array(
    'ID' => $current_user->ID,
    'first_name' => $field_value,
    'display_name' => $new_display
    wp_update_user( $update );
    $current_user = wp_get_current_user();
    echo $current_user->user_firstname . ' ' . $current_user->display_name;
    exit(); // all these are in AJAX request

    The ‘echo’ line shows, that first_name is updated, but display_name – not. In the database (wp_users) both fields are updated. The display_name is echo’ed correctly after reload of the page.
    Why does $current_user->display_name contain old value after wp_update_user() and wp_get_current_user() invocations, while $current_user->user_firstname contains the new one?

    I would appreciate the answer.

    Michal Musial

Viewing 1 replies (of 1 total)
  • Function:
    does not taken the data from the database. It uses global variable: $current_user.

    So after wp_update_user() I used:

    $user_ID = get_current_user_id();
    $current_user = get_userdata( $user_ID );

    and it is fine now.


Viewing 1 replies (of 1 total)
  • The topic ‘Current user display_name does not update’ is closed to new replies.