Skip to content

Commit

Permalink
Admin bar: replace 'Edit Profile' and 'My Account' with 'My Profile' …
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar authored and matticbot committed Oct 4, 2024
1 parent 2016d6b commit aec08af
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 123 deletions.
58 changes: 29 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This is an alpha version! The changes listed here are not final.
- Global Styles: add a Help Link to premium styles limitation message

### Changed
- Admin bar: replace 'Edit Profile' and 'My Account' with 'My Profile'
- Blog Privacy: Do not add custom rules to wpcom's robots.txt if blog_public=0
- Help Center: use Zendesk staging when proxied
- jetpack-mu-wpcom: remove unneeded filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,52 +236,25 @@ function wpcom_add_reader_menu( $wp_admin_bar ) {
add_action( 'admin_bar_menu', 'wpcom_add_reader_menu', 11 );

/**
* Points the "Edit Profile" and "Howdy,..." to /me when appropriate.
* Points the "Edit Profile" and "Howdy,..." to /me.
*
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar core object.
*/
function wpcom_maybe_replace_edit_profile_menu_to_me( $wp_admin_bar ) {
function wpcom_replace_edit_profile_menu_to_me( $wp_admin_bar ) {
$edit_profile_node = $wp_admin_bar->get_node( 'user-info' );
if ( $edit_profile_node ) {
/**
* The Edit Profile menu should point to /me, instead of the site's profile.php
* if the user is not a member of the current site
*/
if ( ! is_user_member_of_blog() ) {
$edit_profile_node->href = maybe_add_origin_site_id_to_url( 'https://wordpress.com/me' );
$wp_admin_bar->add_node( (array) $edit_profile_node );
}
}
}
// Run this function later than Core: https://github.com/WordPress/wordpress-develop/blob/5a30482419f1b0bcc713a7fdee3a14afd67a1bca/src/wp-includes/class-wp-admin-bar.php#L651
add_action( 'admin_bar_menu', 'wpcom_maybe_replace_edit_profile_menu_to_me', 9999 );

/**
* Adds (Profile) -> My Account menu pointing to /me.
*
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar core object.
*/
function wpcom_add_my_account_item_to_profile_menu( $wp_admin_bar ) {
$logout_node = $wp_admin_bar->get_node( 'logout' );
if ( $logout_node ) {
// Adds the 'My Account' menu item before 'Log Out'.
$wp_admin_bar->remove_node( 'logout' );
$edit_profile_node->href = maybe_add_origin_site_id_to_url( 'https://wordpress.com/me' );
$edit_profile_node->title = preg_replace( "/(<span class='display-name edit-profile'>)(.*?)(<\/span>)/", '$1' . __( 'My Profile', 'jetpack-mu-wpcom' ) . '$3', $edit_profile_node->title );
$wp_admin_bar->add_node( (array) $edit_profile_node );
}

$wp_admin_bar->add_node(
array(
'id' => 'wpcom-profile',
'parent' => 'user-actions',
'title' => __( 'My Account', 'jetpack-mu-wpcom' ),
'href' => maybe_add_origin_site_id_to_url( 'https://wordpress.com/me' ),
)
);

if ( $logout_node ) {
$wp_admin_bar->add_node( (array) $logout_node );
$my_account_node = $wp_admin_bar->get_node( 'my-account' );
if ( $my_account_node ) {
$my_account_node->href = maybe_add_origin_site_id_to_url( 'https://wordpress.com/me' );
$wp_admin_bar->add_node( (array) $my_account_node );
}
}
add_action( 'admin_bar_menu', 'wpcom_add_my_account_item_to_profile_menu' );
// Run this function later than Core: https://github.com/WordPress/wordpress-develop/blob/5a30482419f1b0bcc713a7fdee3a14afd67a1bca/src/wp-includes/class-wp-admin-bar.php#L651
add_action( 'admin_bar_menu', 'wpcom_replace_edit_profile_menu_to_me', 9999 );

/**
* Replaces the default admin bar class with our own.
Expand Down
Loading

0 comments on commit aec08af

Please sign in to comment.