Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin bar: replace 'Edit Profile' and 'My Account' with 'My Profile' #39600

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading