PluginProbe
Private groups / 1.7
Private groups v1.7
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 1.7, at includes/topics.php

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