Skip to content

Commit b690e42

Browse files
authored
Admin Bar: Link to the profile, rather than profile edit.
1 parent 288f29c commit b690e42

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

mu-plugins/blocks/global-header-footer/admin-bar.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ function filter_admin_bar_links( $wp_admin_bar ) {
4343
[ 'updates', 'stats', 'search', 'my-sites', 'admin-bar-likes-widget' ]
4444
);
4545

46+
// Restore edit profile link.
47+
$wp_admin_bar->add_node(
48+
array(
49+
'parent' => 'my-account-actions',
50+
'id' => 'edit-profile',
51+
'title' => __( 'Edit Profile' ),
52+
'href' => get_edit_profile_url( get_current_user_id() ),
53+
)
54+
);
55+
4656
// Empty array so we can reverse it to keep the correct order.
4757
$edit_items = [];
4858

@@ -58,9 +68,20 @@ function filter_admin_bar_links( $wp_admin_bar ) {
5868
$ab_item->meta['class'] = 'ab-sub-secondary';
5969
}
6070
$wp_admin_bar->add_node( $ab_item );
61-
} else if ( in_array( $ab_item->id, [ 'edit-profile', 'logout' ] ) ) {
62-
// Move "Edit Profile" and "Logout" to a new group at the end of the dropdown.
71+
} else if ( 'user-info' === $ab_item->id || 'my-account' === $ab_item->id ) {
72+
// Change the link location to the profile, rather than edit.
73+
$ab_item->href = str_replace( '/profile/edit/', '/', $ab_item->href );
74+
75+
// Remove the Edit Profile text.
76+
$ab_item->title = preg_replace( '!<span[^>]+edit-profile[^>]+>[^<]+</span>!i', '', $ab_item->title );
77+
78+
$wp_admin_bar->add_node( $ab_item );
79+
} else if ( 'logout' === $ab_item->id ) {
80+
// Move "Logout" to a new group at the end of the dropdown.
6381
$ab_item->parent = 'my-account-actions';
82+
83+
// Remove it before adding, to ensure it's after the Edit Profile link.
84+
$wp_admin_bar->remove_node('logout');
6485
$wp_admin_bar->add_node( $ab_item );
6586
} else if ( in_array( $ab_item->id, [ 'edit', 'site-editor', 'customize' ] ) ) {
6687
// Move "Edit [object]", "Customize", and "Edit Site" (if exist) to list to be

0 commit comments

Comments
 (0)