Skip to content

Commit

Permalink
Admin Bar: Point the (Profile) -> Edit Profile menu to /me when appro…
Browse files Browse the repository at this point in the history
…priate (#38530)
  • Loading branch information
fushar authored Jul 25, 2024
1 parent 991bb5f commit 31821a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Admin Bar: Point the (Profile) -> Edit Profile menu to /me when appropriate
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 31821a6

Please sign in to comment.