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.


Built from https://develop.svn.wordpress.org/trunk@40657


git-svn-id: http://core.svn.wordpress.org/trunk@40520 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Adam Silverstein 2017-05-12 20:06:42 +00:00
parent 020ffded1a
commit cb2eac9e06
4 changed files with 19 additions and 4 deletions

View File

@ -328,7 +328,9 @@
$(document).ready( function() { $(document).ready( function() {
var $colorpicker, $stylesheet, user_id, current_user_id, 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 ); $('#pass1').val('').on( inputEvent + ' pwupdate', check_pass_strength );
$('#pass-strength-result').show(); $('#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' ); $colorpicker = $( '#color-picker' );

File diff suppressed because one or more lines are too long

View File

@ -214,7 +214,7 @@ function wp_admin_bar_my_account_item( $wp_admin_bar ) {
$avatar = get_avatar( $user_id, 26 ); $avatar = get_avatar( $user_id, 26 );
/* translators: %s: current user's display name */ /* translators: %s: current user's display name */
$howdy = sprintf( __( 'Howdy, %s' ), $current_user->display_name ); $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' );
$class = empty( $avatar ) ? '' : 'with-avatar'; $class = empty( $avatar ) ? '' : 'with-avatar';
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.8-alpha-40656'; $wp_version = '4.8-alpha-40657';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.