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 Oct 4, 2024
1 parent 7ec470b commit c6f08cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Admin bar: replace 'Edit Profile' and 'My Account' with 'My Profile'
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

0 comments on commit c6f08cf

Please sign in to comment.