diff --git a/includes/class-admin.php b/includes/class-admin.php index e35aab80..fc68d88a 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -2182,6 +2182,9 @@ public function override_post_format_title( $title, $post_id = null ) { * @return int Unread count + friend requests. */ public function friends_unread_friend_request_count( $unread ) { + if ( ! current_user_can( Friends::REQUIRED_ROLE ) ) { + return $unread; + } $friend_requests = User_Query::all_friend_requests(); return $unread + $friend_requests->get_total(); } @@ -2246,17 +2249,28 @@ public function admin_bar_friends_menu( \WP_Admin_Bar $wp_menu ) { // If we cannot find a site, we shouldn't show the admin bar entry. return; } - - $my_url = set_url_scheme( $site->siteurl ); - $my_own_site = $site; - $on_my_own_site = get_current_blog_id() === intval( $site->blog_id ); - if ( is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) { - if ( current_user_can( 'pending_friend_request' ) ) { - $they_requested_friendship = true; - } elseif ( current_user_can( 'friend_request' ) ) { - $we_requested_friendship = true; + if ( current_user_can( Friends::REQUIRED_ROLE ) ) { + $my_url = set_url_scheme( $site->siteurl ); + $my_own_site = $site; + $on_my_own_site = get_current_blog_id() === intval( $site->blog_id ); + if ( is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) { + if ( current_user_can( 'pending_friend_request' ) ) { + $they_requested_friendship = true; + } elseif ( current_user_can( 'friend_request' ) ) { + $we_requested_friendship = true; + } + } + } elseif ( current_user_can( 'friend' ) ) { + $current_user = wp_get_current_user(); + if ( ! $current_user->user_url ) { + return; } + + $my_url = $current_user->user_url; } + } elseif ( current_user_can( Friends::REQUIRED_ROLE ) ) { + $my_url = home_url(); + $on_my_own_site = true; } elseif ( current_user_can( 'friend' ) ) { $current_user = wp_get_current_user(); if ( ! $current_user->user_url ) { @@ -2264,9 +2278,6 @@ public function admin_bar_friends_menu( \WP_Admin_Bar $wp_menu ) { } $my_url = $current_user->user_url; - } elseif ( current_user_can( Friends::REQUIRED_ROLE ) ) { - $my_url = home_url(); - $on_my_own_site = true; } if ( ! $on_my_own_site && $my_own_site ) { diff --git a/includes/class-messages.php b/includes/class-messages.php index 9c07b5cd..8b18d2b7 100644 --- a/includes/class-messages.php +++ b/includes/class-messages.php @@ -248,6 +248,9 @@ private function add_message_to_post( \WP_User $sender, User $friend_user, $subj * @return int Unread count + unread messages. */ public function friends_unread_messages_count( $unread ) { + if ( ! current_user_can( Friends::REQUIRED_ROLE ) ) { + return $unread; + } $unread_messages = new \WP_Query( array( 'post_type' => self::CPT,