From 0f4c1e88dd04c42223697733e43beaf135897959 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 12 May 2017 20:05:07 +0000 Subject: [PATCH] Users: Update name in toolbar when changing user display name. When changing the user name in Users -> Your Profile, update the name displayed in the toolbar dynamically using JavaScript. Props menakas, lukecavanagh, maguiar. Fixes #40342. git-svn-id: https://develop.svn.wordpress.org/trunk@40657 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/user-profile.js | 17 ++++++++++++++++- src/wp-includes/admin-bar.php | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/js/user-profile.js b/src/wp-admin/js/user-profile.js index 650fbd5d00..ca99584215 100644 --- a/src/wp-admin/js/user-profile.js +++ b/src/wp-admin/js/user-profile.js @@ -328,7 +328,9 @@ $(document).ready( function() { var $colorpicker, $stylesheet, user_id, current_user_id, - select = $( '#display_name' ); + select = $( '#display_name' ), + current_name = select.val(), + greeting = $( '#wp-admin-bar-my-account' ).find( '.display-name' ); $('#pass1').val('').on( inputEvent + ' pwupdate', check_pass_strength ); $('#pass-strength-result').show(); @@ -370,6 +372,19 @@ } }); }); + + /** + * Replaces "Howdy, *" in the admin toolbar whenever the display name dropdown is updated for one's own profile. + */ + select.on( 'change', function() { + if ( user_id !== current_user_id ) { + return; + } + + var display_name = $.trim( this.value ) || current_name; + + greeting.text( display_name ); + } ); } $colorpicker = $( '#color-picker' ); diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 27266a108c..7ff55febe2 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -214,7 +214,7 @@ function wp_admin_bar_my_account_item( $wp_admin_bar ) { $avatar = get_avatar( $user_id, 26 ); /* translators: %s: current user's display name */ - $howdy = sprintf( __( 'Howdy, %s' ), $current_user->display_name ); + $howdy = sprintf( __( 'Howdy, %s' ), '' . $current_user->display_name . '' ); $class = empty( $avatar ) ? '' : 'with-avatar'; $wp_admin_bar->add_menu( array(