Make WordPress Core


Ignore:
Timestamp:
09/14/2015 05:09:58 PM (11 years ago)
Author:
johnbillion
Message:

Update links to the user profile editing screen in the admin toolbar when the current logged in user has no role on the current site. Covers single site and Multisite and introduces tests.

Fixes #25162

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/admin-bar.php

    r33213 r34122  
    180180        $user_id      = get_current_user_id();
    181181        $current_user = wp_get_current_user();
    182         $profile_url  = get_edit_profile_url( $user_id );
    183182
    184183        if ( ! $user_id )
    185184                return;
     185
     186        if ( current_user_can( 'read' ) ) {
     187                $profile_url = get_edit_profile_url( $user_id );
     188        } elseif ( is_multisite() ) {
     189                $profile_url = get_dashboard_url( $user_id, 'profile.php' );
     190        } else {
     191                $profile_url = false;
     192        }
    186193
    187194        $avatar = get_avatar( $user_id, 26 );
    … …  
    210217        $user_id      = get_current_user_id();
    211218        $current_user = wp_get_current_user();
    212         $profile_url  = get_edit_profile_url( $user_id );
    213219
    214220        if ( ! $user_id )
    215221                return;
     222
     223        if ( current_user_can( 'read' ) ) {
     224                $profile_url = get_edit_profile_url( $user_id );
     225        } elseif ( is_multisite() ) {
     226                $profile_url = get_dashboard_url( $user_id, 'profile.php' );
     227        } else {
     228                $profile_url = false;
     229        }
    216230
    217231        $wp_admin_bar->add_group( array(
    … …  
    235249                ),
    236250        ) );
    237         $wp_admin_bar->add_menu( array(
    238                 'parent' => 'user-actions',
    239                 'id'     => 'edit-profile',
    240                 'title'  => __( 'Edit My Profile' ),
    241                 'href' => $profile_url,
    242         ) );
     251
     252        if ( false !== $profile_url ) {
     253                $wp_admin_bar->add_menu( array(
     254                        'parent' => 'user-actions',
     255                        'id'     => 'edit-profile',
     256                        'title'  => __( 'Edit My Profile' ),
     257                        'href'   => $profile_url,
     258                ) );
     259        }
     260
    243261        $wp_admin_bar->add_menu( array(
    244262                'parent' => 'user-actions',
    … …  
    282300                'id'    => 'site-name',
    283301                'title' => $title,
    284                 'href'  => is_admin() ? home_url( '/' ) : admin_url(),
     302                'href'  => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
    285303        ) );
    286304
    … …  
    305323                }
    306324
    307         } else {
     325        } else if ( current_user_can( 'read' ) ) {
    308326                // We're on the front end, link to the Dashboard.
    309327                $wp_admin_bar->add_menu( array(
Note: See TracChangeset for help on using the changeset viewer.