Skip to content

Commit

Permalink
Fix remote friends menu when remote site is a multisite
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 19, 2022
1 parent 2c1293f commit 4a3dea4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
35 changes: 23 additions & 12 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -2246,27 +2249,35 @@ 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 ) {
return;
}

$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 ) {
Expand Down
3 changes: 3 additions & 0 deletions includes/class-messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4a3dea4

Please sign in to comment.