From 31821a6d205334b18917a6c4ce0746cdb349ecf9 Mon Sep 17 00:00:00 2001 From: Ashar Fuadi Date: Thu, 25 Jul 2024 14:14:53 +0700 Subject: [PATCH] Admin Bar: Point the (Profile) -> Edit Profile menu to /me when appropriate (#38530) --- .../changelog/fix-admin-bar-edit-profile | 4 ++++ .../wpcom-admin-bar/class-wpcom-admin-bar.php | 5 ---- .../wpcom-admin-bar/wpcom-admin-bar.php | 23 ++++++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/fix-admin-bar-edit-profile diff --git a/projects/packages/jetpack-mu-wpcom/changelog/fix-admin-bar-edit-profile b/projects/packages/jetpack-mu-wpcom/changelog/fix-admin-bar-edit-profile new file mode 100644 index 0000000000000..d0bc5fec36993 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/fix-admin-bar-edit-profile @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Admin Bar: Point the (Profile) -> Edit Profile menu to /me when appropriate diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/class-wpcom-admin-bar.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/class-wpcom-admin-bar.php index d4aedf14478f5..31c62ae02722d 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/class-wpcom-admin-bar.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/class-wpcom-admin-bar.php @@ -32,11 +32,6 @@ class WPCOM_Admin_Bar extends \WP_Admin_Bar { 'wp-admin/post-new.php?post_type=page' => 'https://wordpress.com/page/%home_url%', 'wp-admin/user-new.php' => 'https://wordpress.com/people/new/%home_url%', - /** - * Profile menu - */ - 'wp-admin/profile.php' => 'https://wordpress.com/me', - /** * Jetpack */ diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php index c324dc59cc542..e5289eca448bf 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-bar/wpcom-admin-bar.php @@ -25,7 +25,7 @@ function maybe_add_origin_site_id_to_url( $url ) { } // Add query param to URL only for users who can access wp-admin. - if ( ! current_user_can( 'read' ) ) { + if ( ! is_user_member_of_blog() ) { return $url; } @@ -114,6 +114,27 @@ function wpcom_add_reader_menu( $wp_admin_bar ) { } add_action( 'admin_bar_menu', 'wpcom_add_reader_menu', 15 ); +/** + * Points the (Profile) -> Edit Profile menu to /me when appropriate. + * + * @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 ) { + $edit_profile_node = $wp_admin_bar->get_node( 'user-info' ); + if ( $edit_profile_node ) { + // If one of the following is true: + // - the user is not a member of the current site + // - the current site uses Default admin interface + // + // Then, the Edit Profile menu should point to /me, instead of the site's profile.php. + if ( ! is_user_member_of_blog() || get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) { + $edit_profile_node->href = maybe_add_origin_site_id_to_url( 'https://wordpress.com/me' ); + $wp_admin_bar->add_node( (array) $edit_profile_node ); + } + } +} +add_action( 'admin_bar_menu', 'wpcom_maybe_replace_edit_profile_menu_to_me', 1 ); + /** * Adds (Profile) -> My Account menu pointing to /me/account. *