PluginProbe
Private groups / 1.6
Private groups v1.6
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
bbp-private-groups / includes / user-view-post.php

user-view-post.php in Private groups 1.6, at includes/user-view-post.php

77 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
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 * Non-logged in site visitors cannot view posts if groups were selected for the forum they belong to.
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.
8 *
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 !
13 */
14
15 function private_groups_can_user_view_post_id($forum_id) {
16 //get user ID
17 $user_id = wp_get_current_user()->ID;
18 //then check if they can view the forum the post belongs to
19 return private_groups_can_user_view_post($user_id, $forum_id);
20 }
21
22
23 function private_groups_can_user_view_post( $user_id, $forum_id = '' ) {
24 //the $forum_id that needs to be passed to this function is the forum_id that the post belongs to
25
26 /* Assume the user can view the post at this point. */
27 $can_view = true;
28
29
30 /* Get the groups for the forum */
31 $groups = get_post_meta( $forum_id, '_private_group', false );
32
33 /* If we have groups set for this forum let's get to work. */
34 if ( !empty( $groups ) && is_array( $groups ) ) {
35
36 /**
37 * Since specific groups exist let's assume the user can't view the post at
38 * this point. The rest of this functionality should try to disprove this.
39 */
40 $can_view = false;
41
42 /* If the user's not logged in, assume it's blocked at this point. */
43 if (!is_user_logged_in() ) {
44 $can_view = false;
45 }
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
58 /* Else, let's check the user's group against the selected group. */
59 else {
60
61 /* Loop through each group and set $can_view to true if the user has this group. */
62 $check=get_user_meta( $user_id, 'private_group',true);
63 foreach ( $groups as $group ) {
64 if ($check==$group )
65
66 $can_view = true;
67 }
68 }
69 }
70
71
72 /* Allow developers to overwrite the final return value. */
73 return apply_filters( 'private_groups_can_user_view_post', $can_view, $user_id, $forum_id );
74
75 }
76 ?>
77