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
bbp-private-groups / includes / replies.php

replies.php in Private groups 2.3, at includes/replies.php

72 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 //this is only used (as far as I can see) by the 'replies created' part of the user profile
3
4 add_filter ('bbp_get_user_replies_created', 'pg_get_user_replies_created') ;
5
6 function pg_get_user_replies_created( $user_id = 0 ) {
7
8 // Validate user
9 $user_id2 = bbp_get_user_id( $user_id );
10 $current_user= wp_get_current_user()->ID;
11 if ( empty( $user_id ) )
12 return false;
13
14 if ( bbp_is_user_keymaster()) $limit='n' ;
15
16 if (user_can( $current_user, 'moderate' ) ) {
17 $check=get_user_meta( $current_user, 'private_group',true);
18 if ($check=='') $limit='n' ;
19 }
20 if ($limit != 'n') {
21 global $wpdb;
22 $reply=bbp_get_reply_post_type() ;
23 $post_ids=$wpdb->get_col("select ID from $wpdb->posts where post_type = '$reply'") ;
24 //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
25 $allowed_posts = check_private_groups_reply_ids($post_ids) ;
26
27 }
28
29 // The default reply query with allowed topic and reply ids array added
30
31
32
33 // Try to get the topics
34 $query = bbp_has_replies( array(
35 'post_type' => bbp_get_reply_post_type(),
36 'order' => 'DESC',
37 'author' => $user_id2,
38 'post__in' => $allowed_posts
39 ) );
40
41 return apply_filters( 'pg_get_user_replies_created', $query, $user_id );
42 }
43
44 //the function to check the above !
45 function check_private_groups_reply_ids($post_ids) {
46
47 //Init the Array which will hold our list of allowed posts
48 $allowed_posts = array();
49
50
51 //Loop through all the posts
52 foreach ( $post_ids as $post_id ) {
53 //Get the Forum ID based on Post Type Topic
54 $reply=bbp_get_reply_post_type() ;
55 $forum_id = private_groups_get_forum_id_from_post_id($post_id, $reply);
56 //Check if User has permissions to view this Post ID
57 //by calling the function that checks if the user can view this forum, and hence this post
58 if (private_groups_can_user_view_post_id($forum_id)) {
59
60 //User can view this post - add it to the allowed array
61 array_push($allowed_posts, $post_id);
62 }
63 }
64
65 //Return the list
66 return $allowed_posts;
67 }
68
69
70
71
72