PluginProbe
Private groups / trunk
Private groups vtrunk
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 / shortcodes.php

shortcodes.php in Private groups trunk, at includes/shortcodes.php

287 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //new shortcodes first
4 // then versions of bbpress ones with filtering
5
6
7
8 //******************** NEW SHORTCODES ***************
9 add_shortcode('list-pg-users', 'list_pg_users');
10 add_shortcode('pg-single-forum', 'pg_single_forum');
11 add_shortcode('pg-single-topic', 'pg_display_topic');
12 add_shortcode('pg-single-reply', 'pg_display_reply');
13
14
15 function list_pg_users ($attr) {
16 global $rpg_groups ;
17 $users= get_users() ;
18 if ( !empty( $attr['group'] ) ) {
19 //we have a group name !
20 $content=$attr['group'] ;
21 foreach ( $rpg_groups as $group => $details ){
22 if ($details == $content) {
23 echo '<b>'.$details.'</b>';
24 echo '<ul>' ;
25 foreach ( $users as $user ) {
26 $groupcheck=get_user_meta( $user->ID, 'private_group',true);
27 if ($groupcheck == $group) echo '<li>'.esc_html( $user->display_name ).'</li>' ;
28 }
29 echo '</ul>' ;
30 }
31 }
32 }
33 else {
34 // we don't have a group name, so show all !
35 foreach ( $rpg_groups as $group => $details ){
36 if ($details == '') $details = $group.' - no name' ;
37 echo '<b>'.$details.'</b>';
38 echo '<ul>' ;
39 foreach ( $users as $user ) {
40 $groupcheck=get_user_meta( $user->ID, 'private_group',true);
41 if ($groupcheck == $group) echo '<li>'.esc_html( $user->display_name ).'</li>' ;
42 }
43 echo '</ul>' ;
44 }
45 }
46 }
47
48
49 //*********************** NEW PG VERSIONS OF EXISTING SHORTCODES *****************
50
51
52 /**
53 * Display the contents of a specific forum ID in an output buffer
54 * and return to ensure that post/page contents are displayed first.
55 *
56 * @since bbPress (r3031)
57 *
58 * @param array $attr
59 * @param string $content
60 * @uses get_template_part()
61 * @uses bbp_single_forum_description()
62 * @return string
63 */
64 function pg_single_forum( $attr, $content = '' ) {
65
66 // Sanity check required info
67 if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) )
68 return $content;
69
70 // Set passed attribute to $forum_id for clarity
71 $forum_id = bbpress()->current_forum_id = $attr['id'];
72
73 // Bail if ID passed is not a forum
74 if ( !bbp_is_forum( $forum_id ) )
75 return $content;
76
77 // Start output buffer
78 pg_start( 'bbp_single_forum' );
79
80 //check if pg user cannot view forum
81 if (!private_groups_can_user_view_post_id($forum_id)) {
82 if (!empty($attr['message'])) {
83 echo $attr['message'] ;
84 }
85 return pg_end() ;
86 }
87
88
89 // Check forum caps
90 if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
91 bbp_get_template_part( 'content', 'single-forum' );
92
93 // Forum is private and user does not have caps
94 } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
95 bbp_get_template_part( 'feedback', 'no-access' );
96 }
97
98 // Return contents of output buffer
99 return pg_end();
100 }
101
102 /**
103 * Display the contents of a specific topic ID in an output buffer
104 * and return to ensure that post/page contents are displayed first.
105 *
106 * @since bbPress (r3031)
107 *
108 * @param array $attr
109 * @param string $content
110 * @uses get_template_part()
111 * @return string
112 */
113 function pg_display_topic( $attr, $content = '' ) {
114
115 // Sanity check required info
116 if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) )
117 return $content;
118
119 // Unset globals
120 pg_unset_globals();
121
122 // Set passed attribute to $forum_id for clarity
123 $topic_id = bbpress()->current_topic_id = $attr['id'];
124 $forum_id = bbp_get_topic_forum_id( $topic_id );
125
126 // Bail if ID passed is not a topic
127 if ( !bbp_is_topic( $topic_id ) )
128 return $content;
129
130 // Reset the queries if not in theme compat
131 if ( !bbp_is_theme_compat_active() ) {
132
133 $bbp = bbpress();
134
135 // Reset necessary forum_query attributes for topics loop to function
136 $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
137 $bbp->forum_query->in_the_loop = true;
138 $bbp->forum_query->post = get_post( $forum_id );
139
140 // Reset necessary topic_query attributes for topics loop to function
141 $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
142 $bbp->topic_query->in_the_loop = true;
143 $bbp->topic_query->post = get_post( $topic_id );
144 }
145
146 // Start output buffer
147 pg_start( 'bbp_single_topic' );
148
149 //check if pg user cannot view post
150 $post_id = $attr['id'] ;
151 $post_type = get_post_type( $post_id ) ;
152 $forum_id = private_groups_get_forum_id_from_post_id($post_id, $post_type );
153 if (!private_groups_can_user_view_post_id($forum_id) || topic_permissions_check ($post_id) == false) {
154 if (!empty($attr['message'])) {
155 echo $attr['message'] ;
156 }
157 return pg_end() ;
158 }
159
160 // Check forum caps
161 if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
162 bbp_get_template_part( 'content', 'single-topic' );
163
164 // Forum is private and user does not have caps
165 } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
166 bbp_get_template_part( 'feedback', 'no-access' );
167 }
168
169 // Return contents of output buffer
170 return pg_end();
171 }
172
173
174
175
176 /**
177 * Display the contents of a specific reply ID in an output buffer
178 * and return to ensure that post/page contents are displayed first.
179 *
180 * @since bbPress (r3031)
181 *
182 * @param array $attr
183 * @param string $content
184 * @uses get_template_part()
185 * @return string
186 */
187 function pg_display_reply( $attr, $content = '' ) {
188
189 // Sanity check required info
190 if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) )
191 return $content;
192
193 // Unset globals
194 pg_unset_globals();
195
196 // Set passed attribute to $reply_id for clarity
197 $reply_id = bbpress()->current_reply_id = $attr['id'];
198 $forum_id = bbp_get_reply_forum_id( $reply_id );
199
200 // Bail if ID passed is not a reply
201 if ( !bbp_is_reply( $reply_id ) )
202 return $content;
203
204 // Reset the queries if not in theme compat
205 if ( !bbp_is_theme_compat_active() ) {
206
207 $bbp = bbpress();
208
209 // Reset necessary forum_query attributes for replys loop to function
210 $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
211 $bbp->forum_query->in_the_loop = true;
212 $bbp->forum_query->post = get_post( $forum_id );
213
214 // Reset necessary reply_query attributes for replys loop to function
215 $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
216 $bbp->reply_query->in_the_loop = true;
217 $bbp->reply_query->post = get_post( $reply_id );
218 }
219
220 // Start output buffer
221 pg_start( 'bbp_single_reply' );
222
223 //check if pg user cannot view post
224 $post_type = get_post_type( $reply_id ) ;
225 $forum_id = private_groups_get_forum_id_from_post_id($reply_id, $post_type );
226 if (!private_groups_can_user_view_post_id($forum_id) || topic_permissions_check ($reply_id) == false) {
227 if (!empty($attr['message'])) {
228 echo $attr['message'] ;
229 }
230 return pg_end() ;
231 }
232
233 // Check forum caps
234 if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
235 bbp_get_template_part( 'content', 'single-reply' );
236
237 // Forum is private and user does not have caps
238 } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
239 bbp_get_template_part( 'feedback', 'no-access' );
240 }
241
242 // Return contents of output buffer
243 return pg_end();
244 }
245
246 //*********************** START END UNSET PG VERSIONS *****************
247
248 function pg_start( $query_name = '' ) {
249
250 // Set query name
251 bbp_set_query_name( $query_name );
252
253 // Start output buffer
254 ob_start();
255 }
256
257 function pg_end() {
258
259 // Unset globals
260 pg_unset_globals();
261
262 // Reset the query name
263 bbp_reset_query_name();
264
265 // Return and flush the output buffer
266 return ob_get_clean();
267 }
268
269 function pg_unset_globals() {
270 $bbp = bbpress();
271
272 // Unset global queries
273 $bbp->forum_query = new WP_Query();
274 $bbp->topic_query = new WP_Query();
275 $bbp->reply_query = new WP_Query();
276 $bbp->search_query = new WP_Query();
277
278 // Unset global ID's
279 $bbp->current_view_id = 0;
280 $bbp->current_forum_id = 0;
281 $bbp->current_topic_id = 0;
282 $bbp->current_reply_id = 0;
283 $bbp->current_topic_tag_id = 0;
284
285 // Reset the post data
286 wp_reset_postdata();
287 }