ID; //then check if they can view the forum the post belongs to return private_groups_can_user_view_post($user_id, $forum_id); } function private_groups_can_user_view_post( $user_id, $forum_id = '' ) { //the $forum_id that needs to be passed to this function is the forum_id that the post belongs to /* Assume the user can view the post at this point. */ $can_view = true; /* Get the groups for the forum */ $groups = get_post_meta( $forum_id, '_private_group', false ); /* If we have groups set for this forum let's get to work. */ if ( !empty( $groups ) && is_array( $groups ) ) { /** * Since specific groups exist let's assume the user can't view the post at * this point. The rest of this functionality should try to disprove this. */ $can_view = false; /* If the user's not logged in, assume it's blocked at this point. */ if (!is_user_logged_in() ) { $can_view = false; } /*Check if user is moderator or keymaster *This code is only here for the widgets, other bbp code already overrides $can_view *to allow moderators and keymasters to see forum lists, topics and replies*/ if ( bbp_is_user_keymaster() || user_can( $user_id, 'moderate' ) ) { $can_view = true; } /* Else, let's check the user's group against the selected group. */ else { /* Loop through each group and set $can_view to true if the user has this group. */ $check=get_user_meta( $user_id, 'private_group',true); foreach ( $groups as $group ) { if ($check==$group ) $can_view = true; } } } /* Allow developers to overwrite the final return value. */ return apply_filters( 'private_groups_can_user_view_post', $can_view, $user_id, $forum_id ); } ?>