PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
← All changes | includes/common/shortcodes.php +710 -571 2.22.6.17 View file →
@@ -7,731 +7,870 @@
7 7 * @subpackage Shortcodes
8 8 */
9 9
10 10 // Exit if accessed directly
11 -if ( !defined( 'ABSPATH' ) ) exit;
11 +defined( 'ABSPATH' ) || exit;
12 12
13 -if ( !class_exists( 'BBP_Shortcodes' ) ) :
13 +if ( ! class_exists( 'BBP_Shortcodes' ) ) :
14 14 /**
15 15 * bbPress Shortcode Class
16 16 *
17 - * @since bbPress (r3031)
17 + * @since 2.0.0 bbPress (r3031)
18 18 */
19 19 class BBP_Shortcodes {
20 20
21 - /** Vars ******************************************************************/
21 + /** Vars ******************************************************************/
22 22
23 - /**
24 - * @var array Shortcode => function
25 - */
26 - public $codes = array();
23 + /**
24 + * @var array Shortcode => function
25 + */
26 + public $codes = array();
27 27
28 - /** Functions *************************************************************/
28 + /** Functions *************************************************************/
29 29
30 - /**
31 - * Add the register_shortcodes action to bbp_init
32 - *
33 - * @since bbPress (r3031)
34 - *
35 - * @uses setup_globals()
36 - * @uses add_shortcodes()
37 - */
38 - public function __construct() {
39 - $this->setup_globals();
40 - $this->add_shortcodes();
41 - }
30 + /**
31 + * Add the register_shortcodes action to bbp_init
32 + *
33 + * @since 2.0.0 bbPress (r3031)
34 + *
35 + */
36 + public function __construct() {
37 + $this->setup_globals();
38 + $this->add_shortcodes();
39 + }
42 40
43 - /**
44 - * Shortcode globals
45 - *
46 - * @since bbPress (r3143)
47 - * @access private
48 - *
49 - * @uses apply_filters()
50 - */
51 - private function setup_globals() {
41 + /**
42 + * Shortcode globals
43 + *
44 + * @since 2.0.0 bbPress (r3143)
45 + *
46 + * @access private
47 + */
48 + private function setup_globals() {
52 49
53 - // Setup the shortcodes
54 - $this->codes = apply_filters( 'bbp_shortcodes', array(
50 + // phpcs:disable PEAR.Functions.FunctionCallSignature.CloseBracketLine
55 51
56 - /** Forums ********************************************************/
52 + // Setup the shortcodes
53 + $this->codes = apply_filters(
54 + 'bbp_shortcodes',
55 + array(
57 56
58 - 'bbp-forum-index' => array( $this, 'display_forum_index' ), // Forum Index
59 - 'bbp-forum-form' => array( $this, 'display_forum_form' ), // Topic form
60 - 'bbp-single-forum' => array( $this, 'display_forum' ), // Specific forum - pass an 'id' attribute
57 + /** Forums ********************************************************/
61 58
62 - /** Topics ********************************************************/
59 + 'bbp-forum-index' => array( $this, 'display_forum_index' ), // Forum Index
60 + 'bbp-forum-form' => array( $this, 'display_forum_form' ), // Topic form
61 + 'bbp-single-forum' => array( $this, 'display_forum' ), // Specific forum - pass an 'id' attribute
63 62
64 - 'bbp-topic-index' => array( $this, 'display_topic_index' ), // Topic index
65 - 'bbp-topic-form' => array( $this, 'display_topic_form' ), // Topic form
66 - 'bbp-single-topic' => array( $this, 'display_topic' ), // Specific topic - pass an 'id' attribute
63 + /** Topics ********************************************************/
67 64
68 - /** Topic Tags ****************************************************/
65 + 'bbp-topic-index' => array( $this, 'display_topic_index' ), // Topic index
66 + 'bbp-topic-form' => array( $this, 'display_topic_form' ), // Topic form
67 + 'bbp-single-topic' => array( $this, 'display_topic' ), // Specific topic - pass an 'id' attribute
69 68
70 - 'bbp-topic-tags' => array( $this, 'display_topic_tags' ), // All topic tags in a cloud
71 - 'bbp-single-tag' => array( $this, 'display_topics_of_tag' ), // Topics of Tag
69 + /** Topic Tags ****************************************************/
72 70
73 - /** Replies *******************************************************/
71 + 'bbp-topic-tags' => array( $this, 'display_topic_tags' ), // All topic tags in a cloud
72 + 'bbp-single-tag' => array( $this, 'display_topics_of_tag' ), // Topics of Tag
74 73
75 - 'bbp-reply-form' => array( $this, 'display_reply_form' ), // Reply form
76 - 'bbp-single-reply' => array( $this, 'display_reply' ), // Specific reply - pass an 'id' attribute
74 + /** Replies *******************************************************/
77 75
78 - /** Views *********************************************************/
76 + 'bbp-reply-form' => array( $this, 'display_reply_form' ), // Reply form
77 + 'bbp-single-reply' => array( $this, 'display_reply' ), // Specific reply - pass an 'id' attribute
79 78
80 - 'bbp-single-view' => array( $this, 'display_view' ), // Single view
79 + /** Views *********************************************************/
81 80
82 - /** Account *******************************************************/
81 + 'bbp-single-view' => array( $this, 'display_view' ), // Single view
83 82
84 - 'bbp-login' => array( $this, 'display_login' ), // Login
85 - 'bbp-register' => array( $this, 'display_register' ), // Register
86 - 'bbp-lost-pass' => array( $this, 'display_lost_pass' ), // Lost Password
87 - ) );
88 - }
83 + /** Search ********************************************************/
89 84
90 - /**
91 - * Register the bbPress shortcodes
92 - *
93 - * @since bbPress (r3031)
94 - *
95 - * @uses add_shortcode()
96 - * @uses do_action()
97 - */
98 - private function add_shortcodes() {
99 - foreach( (array) $this->codes as $code => $function ) {
100 - add_shortcode( $code, $function );
101 - }
102 - }
85 + 'bbp-search-form' => array( $this, 'display_search_form' ), // Search form
86 + 'bbp-search' => array( $this, 'display_search' ), // Search
103 87
104 - /**
105 - * Unset some globals in the $bbp object that hold query related info
106 - *
107 - * @since bbPress (r3034)
108 - */
109 - private function unset_globals() {
110 - $bbp = bbpress();
88 + /** Account *******************************************************/
111 89
112 - // Unset global queries
113 - $bbp->forum_query = new stdClass;
114 - $bbp->topic_query = new stdClass;
115 - $bbp->reply_query = new stdClass;
90 + 'bbp-login' => array( $this, 'display_login' ), // Login
91 + 'bbp-register' => array( $this, 'display_register' ), // Register
92 + 'bbp-lost-pass' => array( $this, 'display_lost_pass' ), // Lost Password
116 93
117 - // Unset global ID's
118 - $bbp->current_forum_id = 0;
119 - $bbp->current_topic_id = 0;
120 - $bbp->current_reply_id = 0;
121 - $bbp->current_topic_tag_id = 0;
94 + /** Others *******************************************************/
122 95
123 - // Reset the post data
124 - wp_reset_postdata();
125 - }
96 + 'bbp-stats' => array( $this, 'display_stats' ), // Stats
97 + )
98 + );
126 99
127 - /** Output Buffers ********************************************************/
100 + // phpcs:enable
101 + }
128 102
129 - /**
130 - * Start an output buffer.
131 - *
132 - * This is used to put the contents of the shortcode into a variable rather
133 - * than outputting the HTML at run-time. This allows shortcodes to appear
134 - * in the correct location in the_content() instead of when it's created.
135 - *
136 - * @since bbPress (r3079)
137 - *
138 - * @param string $query_name
139 - *
140 - * @uses bbp_set_query_name()
141 - * @uses ob_start()
142 - */
143 - private function start( $query_name = '' ) {
103 + /**
104 + * Register the bbPress shortcodes
105 + *
106 + * @since 2.0.0 bbPress (r3031)
107 + */
108 + private function add_shortcodes() {
109 + foreach ( (array) $this->codes as $code => $function ) {
110 + add_shortcode( $code, $function );
111 + }
112 + }
144 113
145 - // Set query name
146 - bbp_set_query_name( $query_name );
114 + /**
115 + * Unset some globals in the $bbp object that hold query related info
116 + *
117 + * @since 2.0.0 bbPress (r3034)
118 + */
119 + private function unset_globals() {
120 + $bbp = bbpress();
147 121
148 - // Remove 'bbp_replace_the_content' filter to prevent infinite loops
149 - remove_filter( 'the_content', 'bbp_replace_the_content' );
122 + // Unset global queries
123 + $bbp->forum_query = new WP_Query();
124 + $bbp->topic_query = new WP_Query();
125 + $bbp->reply_query = new WP_Query();
126 + $bbp->search_query = new WP_Query();
150 127
151 - // Start output buffer
152 - ob_start();
153 - }
128 + // Unset global ID's
129 + $bbp->current_view_id = 0;
130 + $bbp->current_forum_id = 0;
131 + $bbp->current_topic_id = 0;
132 + $bbp->current_reply_id = 0;
133 + $bbp->current_topic_tag_id = 0;
154 134
155 - /**
156 - * Return the contents of the output buffer and flush its contents.
157 - *
158 - * @since bbPress( r3079)
159 - *
160 - * @uses BBP_Shortcodes::unset_globals() Cleans up global values
161 - * @return string Contents of output buffer.
162 - */
163 - private function end() {
135 + // Reset the post data
136 + wp_reset_postdata();
137 + }
164 138
165 - // Put output into usable variable
166 - $output = ob_get_contents();
139 + /** Output Buffers ********************************************************/
167 140
168 - // Unset globals
169 - $this->unset_globals();
141 + /**
142 + * Start an output buffer.
143 + *
144 + * This is used to put the contents of the shortcode into a variable rather
145 + * than outputting the HTML at run-time. This allows shortcodes to appear
146 + * in the correct location in the_content() instead of when it's created.
147 + *
148 + * @since 2.0.0 bbPress (r3079)
149 + *
150 + * @param string $query_name
151 + */
152 + private function start( $query_name = '' ) {
170 153
171 - // Flush the output buffer
172 - ob_end_clean();
154 + // Set query name
155 + bbp_set_query_name( $query_name );
173 156
174 - // Reset the query name
175 - bbp_reset_query_name();
157 + // Start output buffer
158 + ob_start();
159 + }
176 160
177 - // Add 'bbp_replace_the_content' filter back (@see $this::start())
178 - add_filter( 'the_content', 'bbp_replace_the_content' );
161 + /**
162 + * Return the contents of the output buffer and flush its contents.
163 + *
164 + * @since 2.0.0 bbPress (r3079)
165 + *
166 + * @return string Contents of output buffer.
167 + */
168 + private function end() {
179 169
180 - return $output;
181 - }
170 + // Unset globals
171 + $this->unset_globals();
182 172
183 - /** Forum shortcodes ******************************************************/
173 + // Get the query name, for filter
174 + $query_name = bbp_get_query_name();
184 175
185 - /**
186 - * Display an index of all visible root level forums in an output buffer
187 - * and return to ensure that post/page contents are displayed first.
188 - *
189 - * @since bbPress (r3031)
190 - *
191 - * @param array $attr
192 - * @param string $content
193 - * @uses bbp_has_forums()
194 - * @uses get_template_part()
195 - * @return string
196 - */
197 - public function display_forum_index() {
176 + // Reset the query name
177 + bbp_reset_query_name();
198 178
199 - // Unset globals
200 - $this->unset_globals();
179 + // Return and flush the output buffer
180 + $output = ob_get_clean();
201 181
202 - // Start output buffer
203 - $this->start( 'bbp_forum_archive' );
182 + /**
183 + * Filters the contents of the output buffer before returning.
184 + *
185 + * @since 2.0.0 bbPress (r3079)
186 + *
187 + * @param string $output The contents of the output buffer.
188 + * @param string $query_name The query name used for this output.
189 + */
190 + return apply_filters( 'bbp_display_shortcode', $output, $query_name );
191 + }
204 192
205 - bbp_get_template_part( 'content', 'archive-forum' );
193 + /** Forum shortcodes ******************************************************/
206 194
207 - // Return contents of output buffer
208 - return $this->end();
209 - }
195 + /**
196 + * Display an index of all visible root level forums in an output buffer
197 + * and return to ensure that post/page contents are displayed first.
198 + *
199 + * @since 2.0.0 bbPress (r3031)
200 + *
201 + * @return string
202 + */
203 + public function display_forum_index() {
210 204
211 - /**
212 - * Display the contents of a specific forum ID in an output buffer
213 - * and return to ensure that post/page contents are displayed first.
214 - *
215 - * @since bbPress (r3031)
216 - *
217 - * @param array $attr
218 - * @param string $content
219 - * @uses get_template_part()
220 - * @uses bbp_single_forum_description()
221 - * @return string
222 - */
223 - public function display_forum( $attr, $content = '' ) {
205 + // Unset globals
206 + $this->unset_globals();
224 207
225 - // Sanity check required info
226 - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) )
227 - return $content;
208 + // Start output buffer
209 + $this->start( 'bbp_forum_archive' );
228 210
229 - // Set passed attribute to $forum_id for clarity
230 - $forum_id = bbpress()->current_forum_id = $attr['id'];
211 + bbp_get_template_part( 'content', 'archive-forum' );
231 212
232 - // Bail if ID passed is not a forum
233 - if ( !bbp_is_forum( $forum_id ) )
234 - return $content;
213 + // Return contents of output buffer
214 + return $this->end();
215 + }
235 216
236 - // Start output buffer
237 - $this->start( 'bbp_single_forum' );
217 + /**
218 + * Display the contents of a specific forum ID in an output buffer
219 + * and return to ensure that post/page contents are displayed first.
220 + *
221 + * @since 2.0.0 bbPress (r3031)
222 + *
223 + * @param array $attr
224 + * @param string $content
225 + * @return string
226 + */
227 + public function display_forum( $attr, $content = '' ) {
238 228
239 - // Check forum caps
240 - if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
241 - bbp_get_template_part( 'content', 'single-forum' );
229 + // Sanity check required info
230 + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
231 + return $content;
232 + }
242 233
243 - // Forum is private and user does not have caps
244 - } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
245 - bbp_get_template_part( 'feedback', 'no-access' );
246 - }
234 + // Set passed attribute to $forum_id for clarity
235 + $forum_id = bbpress()->current_forum_id = $attr['id'];
247 236
248 - // Return contents of output buffer
249 - return $this->end();
250 - }
237 + // Bail if ID passed is not a forum
238 + if ( ! bbp_is_forum( $forum_id ) ) {
239 + return $content;
240 + }
251 241
252 - /**
253 - * Display the forum form in an output buffer and return to ensure
254 - * post/page contents are displayed first.
255 - *
256 - * @since bbPress (r3566)
257 - *
258 - * @uses get_template_part()
259 - */
260 - public function display_forum_form() {
242 + // Start output buffer
243 + $this->start( 'bbp_single_forum' );
261 244
262 - // Start output buffer
263 - $this->start( 'bbp_forum_form' );
245 + // Check forum caps
246 + if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
247 + bbp_get_template_part( 'content', 'single-forum' );
264 248
265 - // Output templates
266 - bbp_get_template_part( 'form', 'forum' );
249 + // Forum is private and user does not have caps
250 + } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
251 + bbp_get_template_part( 'feedback', 'no-access' );
252 + }
267 253
268 - // Return contents of output buffer
269 - return $this->end();
270 - }
254 + // Return contents of output buffer
255 + return $this->end();
256 + }
271 257
272 - /** Topic shortcodes ******************************************************/
258 + /**
259 + * Display the forum form in an output buffer and return to ensure
260 + * post/page contents are displayed first.
261 + *
262 + * @since 2.1.0 bbPress (r3566)
263 + */
264 + public function display_forum_form() {
273 265
274 - /**
275 - * Display an index of all visible root level topics in an output buffer
276 - * and return to ensure that post/page contents are displayed first.
277 - *
278 - * @since bbPress (r3031)
279 - *
280 - * @param array $attr
281 - * @param string $content
282 - * @uses bbp_get_hidden_forum_ids()
283 - * @uses get_template_part()
284 - * @return string
285 - */
286 - public function display_topic_index() {
266 + // Start output buffer
267 + $this->start( 'bbp_forum_form' );
287 268
288 - // Unset globals
289 - $this->unset_globals();
269 + // Output templates
270 + bbp_get_template_part( 'form', 'forum' );
290 271
291 - // Filter the query
292 - if ( ! bbp_is_topic_archive() ) {
293 - add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topic_index_query' ) );
294 - }
272 + // Return contents of output buffer
273 + return $this->end();
274 + }
295 275
296 - // Start output buffer
297 - $this->start( 'bbp_topic_archive' );
276 + /** Topic shortcodes ******************************************************/
298 277
299 - // Output template
300 - bbp_get_template_part( 'content', 'archive-topic' );
278 + /**
279 + * Display an index of all visible root level topics in an output buffer
280 + * and return to ensure that post/page contents are displayed first.
281 + *
282 + * @since 2.0.0 bbPress (r3031)
283 + *
284 + * @return string
285 + */
286 + public function display_topic_index() {
301 287
302 - // Return contents of output buffer
303 - return $this->end();
304 - }
288 + // Unset globals
289 + $this->unset_globals();
305 290
306 - /**
307 - * Display the contents of a specific topic ID in an output buffer
308 - * and return to ensure that post/page contents are displayed first.
309 - *
310 - * @since bbPress (r3031)
311 - *
312 - * @param array $attr
313 - * @param string $content
314 - * @uses get_template_part()
315 - * @return string
316 - */
317 - public function display_topic( $attr, $content = '' ) {
291 + // Filter the query
292 + if ( ! bbp_is_topic_archive() ) {
293 + add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topic_index_query' ) );
294 + }
318 295
319 - // Sanity check required info
320 - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) )
321 - return $content;
296 + // Start output buffer
297 + $this->start( 'bbp_topic_archive' );
322 298
323 - // Unset globals
324 - $this->unset_globals();
299 + // Output template
300 + bbp_get_template_part( 'content', 'archive-topic' );
325 301
326 - // Set passed attribute to $forum_id for clarity
327 - $topic_id = bbpress()->current_topic_id = $attr['id'];
328 - $forum_id = bbp_get_topic_forum_id( $topic_id );
302 + // Return contents of output buffer
303 + return $this->end();
304 + }
329 305
330 - // Bail if ID passed is not a topic
331 - if ( !bbp_is_topic( $topic_id ) )
332 - return $content;
306 + /**
307 + * Display the contents of a specific topic ID in an output buffer
308 + * and return to ensure that post/page contents are displayed first.
309 + *
310 + * @since 2.0.0 bbPress (r3031)
311 + *
312 + * @param array $attr
313 + * @param string $content
314 + * @return string
315 + */
316 + public function display_topic( $attr, $content = '' ) {
333 317
334 - // Reset the queries if not in theme compat
335 - if ( !bbp_is_theme_compat_active() ) {
318 + // Sanity check required info
319 + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
320 + return $content;
321 + }
336 322
337 - $bbp = bbpress();
323 + // Unset globals
324 + $this->unset_globals();
338 325
339 - // Reset necessary forum_query attributes for topics loop to function
340 - $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
341 - $bbp->forum_query->in_the_loop = true;
342 - $bbp->forum_query->post = get_post( $forum_id );
326 + // Set passed attribute to $forum_id for clarity
327 + $topic_id = bbpress()->current_topic_id = $attr['id'];
328 + $forum_id = bbp_get_topic_forum_id( $topic_id );
343 329
344 - // Reset necessary topic_query attributes for topics loop to function
345 - $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
346 - $bbp->topic_query->in_the_loop = true;
347 - $bbp->topic_query->post = get_post( $topic_id );
348 - }
330 + // Bail if ID passed is not a topic
331 + if ( ! bbp_is_topic( $topic_id ) ) {
332 + return $content;
333 + }
349 334
350 - // Start output buffer
351 - $this->start( 'bbp_single_topic' );
335 + // Reset the queries if not in theme compat
336 + if ( ! bbp_is_theme_compat_active() ) {
352 337
353 - // Check forum caps
354 - if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
355 - bbp_get_template_part( 'content', 'single-topic' );
338 + $bbp = bbpress();
356 339
357 - // Forum is private and user does not have caps
358 - } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
359 - bbp_get_template_part( 'feedback', 'no-access' );
360 - }
340 + // Reset necessary forum_query attributes for topics loop to function
341 + $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
342 + $bbp->forum_query->in_the_loop = true;
343 + $bbp->forum_query->post = get_post( $forum_id );
361 344
362 - // Return contents of output buffer
363 - return $this->end();
364 - }
345 + // Reset necessary topic_query attributes for topics loop to function
346 + $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
347 + $bbp->topic_query->in_the_loop = true;
348 + $bbp->topic_query->post = get_post( $topic_id );
349 + }
365 350
366 - /**
367 - * Display the topic form in an output buffer and return to ensure
368 - * post/page contents are displayed first.
369 - *
370 - * @since bbPress (r3031)
371 - *
372 - * @uses get_template_part()
373 - */
374 - public function display_topic_form() {
351 + // Start output buffer
352 + $this->start( 'bbp_single_topic' );
375 353
376 - // Start output buffer
377 - $this->start( 'bbp_topic_form' );
354 + // Check forum caps
355 + if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
356 + bbp_get_template_part( 'content', 'single-topic' );
378 357
379 - // Output templates
380 - bbp_get_template_part( 'form', 'topic' );
358 + // Forum is private and user does not have caps
359 + } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
360 + bbp_get_template_part( 'feedback', 'no-access' );
361 + }
381 362
382 - // Return contents of output buffer
383 - return $this->end();
384 - }
363 + // Return contents of output buffer
364 + return $this->end();
365 + }
385 366
386 - /** Replies ***************************************************************/
367 + /**
368 + * Display the topic form in an output buffer and return to ensure
369 + * post/page contents are displayed first.
370 + *
371 + * Supports 'forum_id' attribute to display the topic form for a particular
372 + * forum. This currently has styling issues from not being wrapped in
373 + * <div id="bbpress-forums" class="bbpress-wrapper"></div> which will need to be sorted out later.
374 + *
375 + * @since 2.0.0 bbPress (r3031)
376 + *
377 + * @param array $attr
378 + * @param string $content
379 + * @return string
380 + */
381 + public function display_topic_form( $attr = array(), $content = '' ) {
387 382
388 - /**
389 - * Display the contents of a specific reply ID in an output buffer
390 - * and return to ensure that post/page contents are displayed first.
391 - *
392 - * @since bbPress (r3031)
393 - *
394 - * @param array $attr
395 - * @param string $content
396 - * @uses get_template_part()
397 - * @return string
398 - */
399 - public function display_reply( $attr, $content = '' ) {
383 + // Sanity check supplied info
384 + if ( ! empty( $content ) || ( ! empty( $attr['forum_id'] ) && ( ! is_numeric( $attr['forum_id'] ) || ! bbp_is_forum( $attr['forum_id'] ) ) ) ) {
385 + return $content;
386 + }
400 387
401 - // Sanity check required info
402 - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) )
403 - return $content;
388 + // Unset globals
389 + $this->unset_globals();
404 390
405 - // Unset globals
406 - $this->unset_globals();
391 + // If forum id is set, use the 'bbp_single_forum' query name
392 + if ( ! empty( $attr['forum_id'] ) ) {
407 393
408 - // Set passed attribute to $reply_id for clarity
409 - $reply_id = bbpress()->current_reply_id = $attr['id'];
410 - $forum_id = bbp_get_reply_forum_id( $reply_id );
394 + // Set the global current_forum_id for future requests
395 + bbpress()->current_forum_id = $forum_id = bbp_get_forum_id( $attr['forum_id'] );
411 396
412 - // Bail if ID passed is not a reply
413 - if ( !bbp_is_reply( $reply_id ) )
414 - return $content;
397 + // Start output buffer
398 + $this->start( 'bbp_single_forum' );
415 399
416 - // Reset the queries if not in theme compat
417 - if ( !bbp_is_theme_compat_active() ) {
400 + // No forum id was passed
401 + } else {
418 402
419 - $bbp = bbpress();
403 + // Set the $forum_id variable to satisfy checks below
404 + $forum_id = 0;
420 405
421 - // Reset necessary forum_query attributes for replys loop to function
422 - $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
423 - $bbp->forum_query->in_the_loop = true;
424 - $bbp->forum_query->post = get_post( $forum_id );
406 + // Start output buffer
407 + $this->start( 'bbp_topic_form' );
408 + }
425 409
426 - // Reset necessary reply_query attributes for replys loop to function
427 - $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
428 - $bbp->reply_query->in_the_loop = true;
429 - $bbp->reply_query->post = get_post( $reply_id );
430 - }
410 + // If the forum id is set, check forum caps else display normal topic form
411 + if ( empty( $forum_id ) || bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
412 + bbp_get_template_part( 'form', 'topic' );
431 413
432 - // Start output buffer
433 - $this->start( 'bbp_single_reply' );
414 + // Forum is private and user does not have caps
415 + } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
416 + bbp_get_template_part( 'feedback', 'no-access' );
417 + }
434 418
435 - // Check forum caps
436 - if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
437 - bbp_get_template_part( 'content', 'single-reply' );
419 + // Return contents of output buffer
420 + return $this->end();
421 + }
438 422
439 - // Forum is private and user does not have caps
440 - } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
441 - bbp_get_template_part( 'feedback', 'no-access' );
442 - }
423 + /** Replies ***************************************************************/
443 424
444 - // Return contents of output buffer
445 - return $this->end();
446 - }
425 + /**
426 + * Display the contents of a specific reply ID in an output buffer
427 + * and return to ensure that post/page contents are displayed first.
428 + *
429 + * @since 2.0.0 bbPress (r3031)
430 + *
431 + * @param array $attr
432 + * @param string $content
433 + * @return string
434 + */
435 + public function display_reply( $attr, $content = '' ) {
447 436
448 - /**
449 - * Display the reply form in an output buffer and return to ensure
450 - * post/page contents are displayed first.
451 - *
452 - * @since bbPress (r3031)
453 - *
454 - * @uses get_template_part()
455 - */
456 - public function display_reply_form() {
437 + // Sanity check required info
438 + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
439 + return $content;
440 + }
457 441
458 - // Start output buffer
459 - $this->start( 'bbp_reply_form' );
442 + // Unset globals
443 + $this->unset_globals();
460 444
461 - // Output templates
462 - bbp_get_template_part( 'form', 'reply' );
445 + // Set passed attribute to $reply_id for clarity
446 + $reply_id = bbpress()->current_reply_id = $attr['id'];
447 + $forum_id = bbp_get_reply_forum_id( $reply_id );
463 448
464 - // Return contents of output buffer
465 - return $this->end();
466 - }
449 + // Bail if ID passed is not a reply
450 + if ( ! bbp_is_reply( $reply_id ) ) {
451 + return $content;
452 + }
467 453
468 - /** Topic Tags ************************************************************/
454 + // Reset the queries if not in theme compat
455 + if ( ! bbp_is_theme_compat_active() ) {
469 456
470 - /**
471 - * Display a tag cloud of all topic tags in an output buffer and return to
472 - * ensure that post/page contents are displayed first.
473 - *
474 - * @since bbPress (r3110)
475 - *
476 - * @return string
477 - */
478 - public function display_topic_tags() {
457 + $bbp = bbpress();
479 458
480 - // Unset globals
481 - $this->unset_globals();
459 + // Reset necessary forum_query attributes for reply loop to function
460 + $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
461 + $bbp->forum_query->in_the_loop = true;
462 + $bbp->forum_query->post = get_post( $forum_id );
482 463
483 - // Start output buffer
484 - $this->start( 'bbp_topic_tags' );
464 + // Reset necessary reply_query attributes for reply loop to function
465 + $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
466 + $bbp->reply_query->in_the_loop = true;
467 + $bbp->reply_query->post = get_post( $reply_id );
468 + }
485 469
486 - // Output the topic tags
487 - wp_tag_cloud( array(
488 - 'smallest' => 9,
489 - 'largest' => 38,
490 - 'number' => 80,
491 - 'taxonomy' => bbp_get_topic_tag_tax_id()
492 - ) );
470 + // Start output buffer
471 + $this->start( 'bbp_single_reply' );
493 472
494 - // Return contents of output buffer
495 - return $this->end();
496 - }
473 + // Check forum caps
474 + if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
475 + bbp_get_template_part( 'content', 'single-reply' );
497 476
498 - /**
499 - * Display the contents of a specific topic tag in an output buffer
500 - * and return to ensure that post/page contents are displayed first.
501 - *
502 - * @since bbPress (r3110)
503 - *
504 - * @param array $attr
505 - * @param string $content
506 - * @uses get_template_part()
507 - * @return string
508 - */
509 - public function display_topics_of_tag( $attr, $content = '' ) {
477 + // Forum is private and user does not have caps
478 + } elseif ( bbp_is_forum_private( $forum_id, false ) ) {
479 + bbp_get_template_part( 'feedback', 'no-access' );
480 + }
510 481
511 - // Sanity check required info
512 - if ( !empty( $content ) || ( empty( $attr['id'] ) || !is_numeric( $attr['id'] ) ) )
513 - return $content;
482 + // Return contents of output buffer
483 + return $this->end();
484 + }
514 485
515 - // Unset globals
516 - $this->unset_globals();
486 + /**
487 + * Display the reply form in an output buffer and return to ensure
488 + * post/page contents are displayed first.
489 + *
490 + * @since 2.0.0 bbPress (r3031)
491 + */
492 + public function display_reply_form() {
517 493
518 - // Filter the query
519 - if ( ! bbp_is_topic_tag() ) {
520 - add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topics_of_tag_query' ) );
521 - }
494 + // Start output buffer
495 + $this->start( 'bbp_reply_form' );
522 496
523 - // Start output buffer
524 - $this->start( 'bbp_topic_tag' );
497 + // Output templates
498 + bbp_get_template_part( 'form', 'reply' );
525 499
526 - // Set passed attribute to $ag_id for clarity
527 - bbpress()->current_topic_tag_id = $tag_id = $attr['id'];
500 + // Return contents of output buffer
501 + return $this->end();
502 + }
528 503
529 - // Output template
530 - bbp_get_template_part( 'content', 'archive-topic' );
504 + /** Topic Tags ************************************************************/
531 505
532 - // Return contents of output buffer
533 - return $this->end();
534 - }
506 + /**
507 + * Display a tag cloud of all topic tags in an output buffer and return to
508 + * ensure that post/page contents are displayed first.
509 + *
510 + * @since 2.0.0 bbPress (r3110)
511 + *
512 + * @return string
513 + */
514 + public function display_topic_tags() {
535 515
536 - /**
537 - * Display the contents of a specific topic tag in an output buffer
538 - * and return to ensure that post/page contents are displayed first.
539 - *
540 - * @since bbPress (r3346)
541 - *
542 - * @param array $attr
543 - * @param string $content
544 - * @uses get_template_part()
545 - * @return string
546 - */
547 - public function display_topic_tag_form() {
516 + // Unset globals
517 + $this->unset_globals();
548 518
549 - // Unset globals
550 - $this->unset_globals();
519 + // Start output buffer
520 + $this->start( 'bbp_topic_tags' );
551 521
552 - // Start output buffer
553 - $this->start( 'bbp_topic_tag_edit' );
522 + // Output the topic tags
523 + wp_tag_cloud(
524 + array(
525 + 'smallest' => 9,
526 + 'largest' => 38,
527 + 'number' => 80,
528 + 'taxonomy' => bbp_get_topic_tag_tax_id()
529 + )
530 + );
554 531
555 - // Output template
556 - bbp_get_template_part( 'content', 'topic-tag-edit' );
532 + // Return contents of output buffer
533 + return $this->end();
534 + }
557 535
558 - // Return contents of output buffer
559 - return $this->end();
560 - }
536 + /**
537 + * Display the contents of a specific topic tag in an output buffer
538 + * and return to ensure that post/page contents are displayed first.
539 + *
540 + * @since 2.0.0 bbPress (r3110)
541 + *
542 + * @param array $attr
543 + * @param string $content
544 + * @return string
545 + */
546 + public function display_topics_of_tag( $attr, $content = '' ) {
561 547
562 - /** Views *****************************************************************/
548 + // Sanity check required info
549 + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
550 + return $content;
551 + }
563 552
564 - /**
565 - * Display the contents of a specific view in an output buffer and return to
566 - * ensure that post/page contents are displayed first.
567 - *
568 - * @since bbPress (r3031)
569 - *
570 - * @param array $attr
571 - * @param string $content
572 - * @uses get_template_part()
573 - * @uses bbp_single_forum_description()
574 - * @return string
575 - */
576 - public function display_view( $attr, $content = '' ) {
553 + // Unset globals
554 + $this->unset_globals();
577 555
578 - // Sanity check required info
579 - if ( empty( $attr['id'] ) )
580 - return $content;
556 + // Filter the query
557 + if ( ! bbp_is_topic_tag() ) {
558 + add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topics_of_tag_query' ) );
559 + }
581 560
582 - // Set passed attribute to $view_id for clarity
583 - $view_id = $attr['id'];
561 + // Start output buffer
562 + $this->start( 'bbp_topic_tag' );
584 563
585 - // Start output buffer
586 - $this->start( 'bbp_single_view' );
564 + // Set passed attribute to $ag_id for clarity
565 + bbpress()->current_topic_tag_id = $tag_id = $attr['id'];
587 566
588 - // Unset globals
589 - $this->unset_globals();
567 + // Output template
568 + bbp_get_template_part( 'content', 'archive-topic' );
590 569
591 - // Load the view
592 - bbp_view_query( $view_id );
570 + // Return contents of output buffer
571 + return $this->end();
572 + }
593 573
594 - // Output template
595 - bbp_get_template_part( 'content', 'single-view' );
574 + /**
575 + * Display the contents of a specific topic tag in an output buffer
576 + * and return to ensure that post/page contents are displayed first.
577 + *
578 + * @since 2.0.0 bbPress (r3346)
579 + *
580 + * @return string
581 + */
582 + public function display_topic_tag_form() {
596 583
597 - // Return contents of output buffer
598 - return $this->end();
599 - }
584 + // Unset globals
585 + $this->unset_globals();
600 586
601 - /** Account ***************************************************************/
587 + // Start output buffer
588 + $this->start( 'bbp_topic_tag_edit' );
602 589
603 - /**
604 - * Display a login form
605 - *
606 - * @since bbPress (r3302)
607 - *
608 - * @return string
609 - */
610 - public function display_login() {
590 + // Output template
591 + bbp_get_template_part( 'content', 'topic-tag-edit' );
611 592
612 - // Unset globals
613 - $this->unset_globals();
593 + // Return contents of output buffer
594 + return $this->end();
595 + }
614 596
615 - // Start output buffer
616 - $this->start( 'bbp_login' );
597 + /** Views *****************************************************************/
617 598
618 - // Output templates
619 - if ( !is_user_logged_in() )
620 - bbp_get_template_part( 'form', 'user-login' );
621 - else
622 - bbp_get_template_part( 'feedback', 'logged-in' );
599 + /**
600 + * Display the contents of a specific view in an output buffer and return to
601 + * ensure that post/page contents are displayed first.
602 + *
603 + * @since 2.0.0 bbPress (r3031)
604 + *
605 + * @param array $attr
606 + * @param string $content
607 + * @return string
608 + */
609 + public function display_view( $attr, $content = '' ) {
623 610
624 - // Return contents of output buffer
625 - return $this->end();
626 - }
611 + // Sanity check required info
612 + if ( empty( $attr['id'] ) ) {
613 + return $content;
614 + }
627 615
628 - /**
629 - * Display a register form
630 - *
631 - * @since bbPress (r3302)
632 - *
633 - * @return string
634 - */
635 - public function display_register() {
616 + // Set passed attribute to $view_id for clarity
617 + $view_id = $attr['id'];
636 618
637 - // Unset globals
638 - $this->unset_globals();
619 + // Start output buffer
620 + $this->start( 'bbp_single_view' );
639 621
640 - // Start output buffer
641 - $this->start( 'bbp_register' );
622 + // Unset globals
623 + $this->unset_globals();
642 624
643 - // Output templates
644 - if ( !is_user_logged_in() )
645 - bbp_get_template_part( 'form', 'user-register' );
646 - else
647 - bbp_get_template_part( 'feedback', 'logged-in' );
625 + // Set the current view ID
626 + bbpress()->current_view_id = $view_id;
648 627
649 - // Return contents of output buffer
650 - return $this->end();
651 - }
628 + // Load the view
629 + bbp_view_query( $view_id );
652 630
653 - /**
654 - * Display a lost password form
655 - *
656 - * @since bbPress (r3302)
657 - *
658 - * @return string
659 - */
660 - public function display_lost_pass() {
631 + // Output template
632 + bbp_get_template_part( 'content', 'single-view' );
661 633
662 - // Unset globals
663 - $this->unset_globals();
634 + // Return contents of output buffer
635 + return $this->end();
636 + }
664 637
665 - // Start output buffer
666 - $this->start( 'bbp_lost_pass' );
638 + /** Search ****************************************************************/
667 639
668 - // Output templates
669 - if ( !is_user_logged_in() )
670 - bbp_get_template_part( 'form', 'user-lost-pass' );
671 - else
672 - bbp_get_template_part( 'feedback', 'logged-in' );
673 -
674 - // Return contents of output buffer
675 - return $this->end();
676 - }
640 + /**
641 + * Display the search form in an output buffer and return to ensure
642 + * post/page contents are displayed first.
643 + *
644 + * @since 2.3.0 bbPress (r4585)
645 + */
646 + public function display_search_form() {
677 647
678 - /** Other *****************************************************************/
648 + // Bail if search is disabled
649 + if ( ! bbp_allow_search() ) {
650 + return;
651 + }
679 652
680 - /**
681 - * Display a breadcrumb
682 - *
683 - * @since bbPress (r3302)
684 - *
685 - * @return string
686 - */
687 - public function display_breadcrumb() {
653 + // Start output buffer
654 + $this->start( 'bbp_search_form' );
688 655
689 - // Unset globals
690 - $this->unset_globals();
656 + // Output templates
657 + bbp_get_template_part( 'form', 'search' );
691 658
692 - // Start output buffer
693 - $this->start();
659 + // Return contents of output buffer
660 + return $this->end();
661 + }
694 662
695 - // Output breadcrumb
696 - bbp_breadcrumb();
663 + /**
664 + * Display the contents of search results in an output buffer and return to
665 + * ensure that post/page contents are displayed first.
666 + *
667 + * @since 2.3.0 bbPress (r4579)
668 + *
669 + * @param array $attr
670 + * @param string $content
671 + */
672 + public function display_search( $attr, $content = '' ) {
697 673
698 - // Return contents of output buffer
699 - return $this->end();
700 - }
674 + // Sanity check required info
675 + if ( ! empty( $content ) ) {
676 + return $content;
677 + }
701 678
702 - /** Query Filters *********************************************************/
679 + // Bail if search is disabled
680 + if ( ! bbp_allow_search() ) {
681 + return;
682 + }
703 683
704 - /**
705 - * Filter the query for the topic index
706 - *
707 - * @since bbPress (r3637)
708 - *
709 - * @param array $args
710 - * @return array
711 - */
712 - public function display_topic_index_query( $args = array() ) {
713 - $args['author'] = 0;
714 - $args['show_stickies'] = true;
715 - $args['order'] = 'DESC';
716 - return $args;
717 - }
684 + // Trim search attribute if it's set
685 + if ( isset( $attr['search'] ) ) {
686 + $attr['search'] = trim( $attr['search'] );
687 + }
718 688
719 - /**
720 - * Filter the query for topic tags
721 - *
722 - * @since bbPress (r3637)
723 - *
724 - * @param array $args
725 - * @return array
726 - */
727 - public function display_topics_of_tag_query( $args = array() ) {
728 - $args['tax_query'] = array( array(
729 - 'taxonomy' => bbp_get_topic_tag_tax_id(),
730 - 'field' => 'id',
731 - 'terms' => bbpress()->current_topic_tag_id
732 - ) );
689 + // Set passed attribute to $search_terms for clarity
690 + $search_terms = empty( $attr['search'] )
691 + ? bbp_get_search_terms()
692 + : $attr['search'];
733 693
734 - return $args;
735 - }
694 + // Get the rewrite ID (one time, to avoid repeated calls)
695 + $rewrite_id = bbp_get_search_rewrite_id();
696 +
697 + // Unset globals
698 + $this->unset_globals();
699 +
700 + // Set terms for query
701 + set_query_var( $rewrite_id, $search_terms );
702 +
703 + // Start output buffer
704 + $this->start( $rewrite_id );
705 +
706 + // Output template
707 + bbp_get_template_part( 'content', 'search' );
708 +
709 + // Return contents of output buffer
710 + return $this->end();
711 + }
712 +
713 + /** Account ***************************************************************/
714 +
715 + /**
716 + * Display a login form
717 + *
718 + * @since 2.0.0 bbPress (r3302)
719 + *
720 + * @return string
721 + */
722 + public function display_login() {
723 +
724 + // Unset globals
725 + $this->unset_globals();
726 +
727 + // Start output buffer
728 + $this->start( 'bbp_login' );
729 +
730 + // Output templates
731 + if ( ! is_user_logged_in() ) {
732 + bbp_get_template_part( 'form', 'user-login' );
733 + } else {
734 + bbp_get_template_part( 'feedback', 'logged-in' );
735 + }
736 +
737 + // Return contents of output buffer
738 + return $this->end();
739 + }
740 +
741 + /**
742 + * Display a register form
743 + *
744 + * @since 2.0.0 bbPress (r3302)
745 + *
746 + * @return string
747 + */
748 + public function display_register() {
749 +
750 + // Unset globals
751 + $this->unset_globals();
752 +
753 + // Start output buffer
754 + $this->start( 'bbp_register' );
755 +
756 + // Output templates
757 + if ( ! is_user_logged_in() ) {
758 + bbp_get_template_part( 'form', 'user-register' );
759 + } else {
760 + bbp_get_template_part( 'feedback', 'logged-in' );
761 + }
762 +
763 + // Return contents of output buffer
764 + return $this->end();
765 + }
766 +
767 + /**
768 + * Display a lost password form
769 + *
770 + * @since 2.0.0 bbPress (r3302)
771 + *
772 + * @return string
773 + */
774 + public function display_lost_pass() {
775 +
776 + // Unset globals
777 + $this->unset_globals();
778 +
779 + // Start output buffer
780 + $this->start( 'bbp_lost_pass' );
781 +
782 + // Output templates
783 + if ( ! is_user_logged_in() ) {
784 + bbp_get_template_part( 'form', 'user-lost-pass' );
785 + } else {
786 + bbp_get_template_part( 'feedback', 'logged-in' );
787 + }
788 +
789 + // Return contents of output buffer
790 + return $this->end();
791 + }
792 +
793 + /** Other *****************************************************************/
794 +
795 + /**
796 + * Display forum statistics
797 + *
798 + * @since 2.3.0 bbPress (r4509)
799 + *
800 + * @return string
801 + */
802 + public function display_stats() {
803 +
804 + // Unset globals
805 + $this->unset_globals();
806 +
807 + // Start output buffer
808 + $this->start();
809 +
810 + // Output statistics
811 + bbp_get_template_part( 'content', 'statistics' );
812 +
813 + // Return contents of output buffer
814 + return $this->end();
815 + }
816 +
817 + /**
818 + * Display a breadcrumb
819 + *
820 + * @since 2.0.0 bbPress (r3302)
821 + *
822 + * @return string
823 + */
824 + public function display_breadcrumb() {
825 +
826 + // Unset globals
827 + $this->unset_globals();
828 +
829 + // Start output buffer
830 + $this->start();
831 +
832 + // Output breadcrumb
833 + bbp_breadcrumb();
834 +
835 + // Return contents of output buffer
836 + return $this->end();
837 + }
838 +
839 + /** Query Filters *********************************************************/
840 +
841 + /**
842 + * Filter the query for the topic index
843 + *
844 + * @since 2.1.0 bbPress (r3637)
845 + *
846 + * @param array $args
847 + * @return array
848 + */
849 + public function display_topic_index_query( $args = array() ) {
850 + $args['author'] = 0;
851 + $args['show_stickies'] = true;
852 + $args['order'] = 'DESC';
853 + return $args;
854 + }
855 +
856 + /**
857 + * Filter the query for topic tags
858 + *
859 + * @since 2.1.0 bbPress (r3637)
860 + *
861 + * @param array $args
862 + * @return array
863 + */
864 + public function display_topics_of_tag_query( $args = array() ) {
865 + $args['tax_query'] = array(
866 + array(
867 + 'taxonomy' => bbp_get_topic_tag_tax_id(),
868 + 'field' => 'id',
869 + 'terms' => bbpress()->current_topic_tag_id
870 + )
871 + );
872 +
873 + return $args;
874 + }
736 875 }
737 876 endif;