PluginProbe
Private groups / 2.5
Private groups v2.5
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 / topics.php

topics.php in Private groups 2.5, at includes/topics.php

61 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //version 1.9.2 fixed private groups forums for subscriptions
4
5 add_filter ('bbp_before_has_topics_parse_args', 'pg_has_topics') ;
6
7 function pg_has_topics( $args = '' ) {
8 //check if being called by subscriptions and if so skip filtering (as you can only subscribe to forums you can already see)
9 if($args['post__in']) {
10 return $args ;
11 }
12 $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
13
14 if ($default_post_parent == 'any') {
15 if ( bbp_is_user_keymaster()) return $args;
16 $user_id = wp_get_current_user()->ID;
17
18 if (user_can( $user_id, 'moderate' ) ) {
19 $check=get_user_meta( $user_id, 'private_group',true);
20 if ($check=='') return $args;
21 }
22
23
24 global $wpdb;
25 $topic=bbp_get_topic_post_type() ;
26 $post_ids=$wpdb->get_col("select ID from $wpdb->posts where post_type = '$topic'") ;
27 //check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics
28 $allowed_posts = check_private_groups_topic_ids($post_ids) ;
29
30 $args['post__in'] = $allowed_posts;
31 }
32 return $args;
33 }
34
35
36 //the function to check the above !
37 function check_private_groups_topic_ids($post_ids) {
38
39 //Init the Array which will hold our list of allowed posts
40 $allowed_posts = array();
41
42
43 //Loop through all the posts
44 foreach ( $post_ids as $post_id ) {
45 //Get the Forum ID based on Post Type Topic
46 $topic=bbp_get_topic_post_type() ;
47 $forum_id = private_groups_get_forum_id_from_post_id($post_id, $topic);
48 //Check if User has permissions to view this Post ID
49 //by calling the function that checks if the user can view this forum, and hence this post
50 if (private_groups_can_user_view_post_id($forum_id)) {
51
52 //User can view this post - add it to the allowed array
53 array_push($allowed_posts, $post_id);
54 }
55 }
56
57 //Return the list
58 return $allowed_posts;
59 }
60
61