From 4bca551925d9ceff79cbef4b33786944ea9dcda5 Mon Sep 17 00:00:00 2001 From: okmttdhr Date: Thu, 29 Aug 2024 16:14:39 +0900 Subject: [PATCH] Point Howdy to /me --- .../wpcom-admin-bar/class-wpcom-admin-bar.php | 12 ------- .../wpcom-admin-bar/wpcom-admin-bar.php | 35 +++++++++++++------ 2 files changed, 25 insertions(+), 22 deletions(-) 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 76f2d0eb33c9c..f3bec819bf0b6 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 @@ -59,18 +59,6 @@ public function add_node( $args ) { parent::add_node( $args ); return; } - - if ( $args['id'] === 'my-account' ) { - if ( ! is_user_member_of_blog() || get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) { - $args['href'] = 'https://wordpress.com/me'; - - // Temporarily point to wpcalypso.wordpress.com for testing purposes. - if ( get_option( 'wpcom_site_level_user_profile' ) === '1' ) { - $args['href'] = 'https://wpcalypso.wordpress.com/me'; - } - } - } - $home_url = home_url( '/' ); $site_slug = wp_parse_url( $home_url, PHP_URL_HOST ); $href = str_replace( $home_url, '', $args['href'] ); 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 ebce5ad3d5ae3..3f0bc736734d7 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 @@ -161,21 +161,22 @@ function wpcom_add_reader_menu( $wp_admin_bar ) { add_action( 'admin_bar_menu', 'wpcom_add_reader_menu', 11 ); /** - * Points the (Profile) -> Edit Profile menu to /me when appropriate. + * Points the "Edit Profile" and "Howdy,..." 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 ) { + /** + * The Edit Profile menu should point to /me, instead of the site's profile.php + * if one of the following is true: + * - the user is not a member of the current site + * - the current site uses Default admin interface AND the site-level user profile is disabled + */ + $should_replace = ! is_user_member_of_blog() || ( empty( get_option( 'wpcom_site_level_user_profile' ) ) && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ); + $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 one of the following is true: - * - the user is not a member of the current site - * - the current site uses Default admin interface AND the site-level user profile is disabled - */ - if ( ! is_user_member_of_blog() || ( empty( get_option( 'wpcom_site_level_user_profile' ) ) && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) ) { - + if ( $should_replace ) { // Temporarily point to wpcalypso.wordpress.com for testing purposes. $url = 'https://wordpress.com/me'; if ( ! empty( get_option( 'wpcom_site_level_user_profile' ) ) ) { @@ -186,8 +187,22 @@ function wpcom_maybe_replace_edit_profile_menu_to_me( $wp_admin_bar ) { $wp_admin_bar->add_node( (array) $edit_profile_node ); } } + + $my_account_node = $wp_admin_bar->get_node( 'my-account' ); + if ( $my_account_node ) { + if ( $should_replace ) { + // Temporarily point to wpcalypso.wordpress.com for testing purposes. + $url = 'https://wordpress.com/me/account'; + if ( ! empty( get_option( 'wpcom_site_level_user_profile' ) ) ) { + $url = 'https://wpcalypso.wordpress.com/me/account'; + } + + $my_account_node->href = maybe_add_origin_site_id_to_url( $url ); + $wp_admin_bar->add_node( (array) $my_account_node ); + } + } } -add_action( 'admin_bar_menu', 'wpcom_maybe_replace_edit_profile_menu_to_me', 1 ); +add_action( 'admin_bar_menu', 'wpcom_maybe_replace_edit_profile_menu_to_me', 9999 ); /** * Adds (Profile) -> My Account menu pointing to /me/account.