PluginProbe
Private groups / 2.3
Private groups v2.3
trunk 1.5 1.6 1.7 1.8 1.8.1 1.9.1 1.9.2 2.0 2.0.1 2.2 2.3 2.4 2.5 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 116 releases
← All changes | includes/user-view-post.php +25 -21 1.6 → 2.3 View file →
@@ -2,15 +2,14 @@
2 2 /*
3 3 * Conditional tag to check if a user can view a specific post, by checking if they can see the forum that it belongs to.
4 4 * Non-logged in site visitors cannot view posts if groups were selected for the forum they belong to.
5 5 * A user cannot view a post if their group role has not been selected in the meta box on the edit forum screen in the dashboard.
6 - * If no groups were selected, all users and site visitors
7 - * can view the content.
6 + * If no groups were selected, all users and site visitors can view the content.
7 +
8 + * Keymasters can always view, and moderators with no group set can view
8 9 *
9 - * There are exceptions to this rule though. The post author, and users that have the ability to edit the post can always
10 - * view the post, even if their role was not granted permission to view it.
11 - *
12 - *Much of this code is Justin Tadlocks' from the members plugin - thanks Justin for awesome work !
10 + *
11 + *Some of this code is Justin Tadlocks' from the members plugin - thanks Justin for awesome work !
13 12 */
14 13
15 14 function private_groups_can_user_view_post_id($forum_id) {
16 15 //get user ID
@@ -29,9 +28,9 @@
29 28
30 29 /* Get the groups for the forum */
31 30 $groups = get_post_meta( $forum_id, '_private_group', false );
32 31
33 - /* If we have groups set for this forum let's get to work. */
32 + /* If we have groups set for this forum let's get to work. */
34 33 if ( !empty( $groups ) && is_array( $groups ) ) {
35 34
36 35 /**
37 36 * Since specific groups exist let's assume the user can't view the post at
@@ -42,30 +41,35 @@
42 41 /* If the user's not logged in, assume it's blocked at this point. */
43 42 if (!is_user_logged_in() ) {
44 43 $can_view = false;
45 44 }
45 +
46 46
47 -
48 -
49 - /*Check if user is moderator or keymaster
50 - *This code is only here for the widgets, other bbp code already overrides $can_view
51 - *to allow moderators and keymasters to see forum lists, topics and replies*/
52 -
53 - if ( bbp_is_user_keymaster() || user_can( $user_id, 'moderate' ) ) {
54 - $can_view = true;
55 - }
56 -
57 -
47 + /*Check if user is keymaster*/
48 + if ( bbp_is_user_keymaster()) $can_view = true;
49 + //now we'll check if the user is a moderator.
50 + else {
51 + $role = bbp_get_user_role( $user_id );
52 + $check=get_user_meta( $user_id, 'private_group',true);
53 + //if they are a mod, and they have no forum groups set, then they can moderate and see across all forums
54 + if ($role == 'bbp_moderator' && (empty($check))) $can_view= true ;
55 + //otherwise if they are a moderator with groups set, then they can see (and moderate) only their visible forums
56 + //- just as everyone else does
57 +
58 58 /* Else, let's check the user's group against the selected group. */
59 59 else {
60 60
61 61 /* Loop through each group and set $can_view to true if the user has this group. */
62 62 $check=get_user_meta( $user_id, 'private_group',true);
63 +
63 64 foreach ( $groups as $group ) {
64 - if ($check==$group )
65 -
66 - $can_view = true;
65 + //single group set?
66 + if ($check==$group ) $can_view = true;
67 + //multiple group set
68 + if (strpos($check, '*'.$group.'*') !== FALSE) $can_view = true;
69 +
67 70 }
71 + }
68 72 }
69 73 }
70 74
71 75