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/core/template-loader.php +109 -157 trunk2.6.17 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2
3 3 /**
4 - * bbPress Template Loader.
4 + * bbPress Template Loader
5 5 *
6 6 * @package bbPress
7 7 * @subpackage TemplateLoader
8 8 */
@@ -10,13 +10,13 @@
10 10 // Exit if accessed directly
11 11 defined( 'ABSPATH' ) || exit;
12 12
13 13 /**
14 - * Possibly intercept the template being loaded.
14 + * Possibly intercept the template being loaded
15 15 *
16 16 * Listens to the 'template_include' filter and waits for any bbPress specific
17 17 * template condition to be met. If one is met and the template file exists,
18 - * it will be used; otherwise.
18 + * it will be used; otherwise
19 19 *
20 20 * Note that the _edit() checks are ahead of their counterparts, to prevent them
21 21 * from being stomped on accident.
22 22 *
@@ -23,65 +23,87 @@
23 23 * @since 2.0.0 bbPress (r3032)
24 24 *
25 25 * @param string $template
26 26 *
27 - * @return string The path to the template file that is being used.
27 + * @return string The path to the template file that is being used
28 28 */
29 29 function bbp_template_include_theme_supports( $template = '' ) {
30 30
31 - // Default return value
32 - $retval = $template;
31 + // Editing a user
32 + if ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
33 33
34 - // Get the templates
35 - $bbp_templates = bbp_get_template_include_templates();
34 + // User favorites
35 + elseif ( bbp_is_favorites() && ( $new_template = bbp_get_favorites_template() ) ) :
36 36
37 - // Loop through each of the template conditionals
38 - if ( ! empty( $bbp_templates ) ) {
39 - foreach ( $bbp_templates as $checker => $getter ) {
37 + // User favorites
38 + elseif ( bbp_is_subscriptions() && ( $new_template = bbp_get_subscriptions_template() ) ) :
40 39
41 - // Skip if check fails
42 - if ( ! function_exists( $checker ) || ! call_user_func( $checker ) ) {
43 - continue;
44 - }
40 + // Viewing a user
41 + elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
45 42
46 - // Maybe get a template file
47 - $new_template = function_exists( $getter )
48 - ? call_user_func( $getter )
49 - : '';
43 + // Single View
44 + elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
50 45
51 - // Skip if new template not found
52 - if ( empty( $new_template ) ) {
53 - continue;
54 - }
46 + // Search
47 + elseif ( bbp_is_search() && ( $new_template = bbp_get_search_template() ) ) :
55 48
56 - // A bbPress template file was located, so set the return value
57 - // that will override the WordPress template, and switches off
58 - // theme compatibility.
59 - $retval = bbp_set_template_included( $new_template );
49 + // Forum edit
50 + elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) :
60 51
61 - // Exit the loop
62 - break;
63 - }
52 + // Single Forum
53 + elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) :
54 +
55 + // Forum Archive
56 + elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) :
57 +
58 + // Topic merge
59 + elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
60 +
61 + // Topic split
62 + elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
63 +
64 + // Topic edit
65 + elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
66 +
67 + // Single Topic
68 + elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) :
69 +
70 + // Topic Archive
71 + elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) :
72 +
73 + // Reply move
74 + elseif ( bbp_is_reply_move() && ( $new_template = bbp_get_reply_move_template() ) ) :
75 +
76 + // Editing a reply
77 + elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
78 +
79 + // Single Reply
80 + elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) :
81 +
82 + // Editing a topic tag
83 + elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
84 +
85 + // Viewing a topic tag
86 + elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
87 + endif;
88 +
89 + // A bbPress template file was located, so override the WordPress template
90 + // and use it to switch off theme compatibility.
91 + if ( ! empty( $new_template ) ) {
92 + $template = bbp_set_template_included( $new_template );
64 93 }
65 94
66 - /**
67 - * Filters the path to the template file that is being used.
68 - *
69 - * @since 2.0.0 bbPress (r3032)
70 - *
71 - * @param string $retval Path to the filtered template file.
72 - * @param string $template Path to the original template file.
73 - */
74 - return apply_filters( 'bbp_template_include_theme_supports', $retval, $template );
95 + // Filter & return
96 + return apply_filters( 'bbp_template_include_theme_supports', $template );
75 97 }
76 98
77 99 /**
78 - * Set the included template.
100 + * Set the included template
79 101 *
80 102 * @since 2.4.0 bbPress (r4975)
81 103 *
82 - * @param mixed $template Default false.
83 - * @return mixed False if empty. Template name if template included.
104 + * @param mixed $template Default false
105 + * @return mixed False if empty. Template name if template included
84 106 */
85 107 function bbp_set_template_included( $template = false ) {
86 108 bbpress()->theme_compat->bbpress_template = $template;
87 109
@@ -92,9 +114,9 @@
92 114 * Is a bbPress template being included?
93 115 *
94 116 * @since 2.4.0 bbPress (r4975)
95 117 *
96 - * @return bool True if yes, false if no.
118 + * @return bool True if yes, false if no
97 119 */
98 120 function bbp_is_template_included() {
99 121 return ! empty( bbpress()->theme_compat->bbpress_template );
100 122 }
@@ -106,9 +128,9 @@
106 128 * functions.php file.
107 129 *
108 130 * @since 2.1.0 bbPress (r3732)
109 131 *
110 - * @global string $pagenow The filename of the current screen.
132 + * @global string $pagenow
111 133 */
112 134 function bbp_load_theme_functions() {
113 135 global $pagenow;
114 136
@@ -124,13 +146,13 @@
124 146
125 147 /** Individual Templates ******************************************************/
126 148
127 149 /**
128 - * Get the user profile template.
150 + * Get the user profile template
129 151 *
130 152 * @since 2.0.0 bbPress (r3311)
131 153 *
132 - * @return string Path to template file.
154 + * @return string Path to template file
133 155 */
134 156 function bbp_get_single_user_template() {
135 157 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
136 158 $user_id = bbp_get_displayed_user_id();
@@ -143,13 +165,13 @@
143 165 return bbp_get_query_template( 'profile', $templates );
144 166 }
145 167
146 168 /**
147 - * Get the user profile edit template.
169 + * Get the user profile edit template
148 170 *
149 171 * @since 2.0.0 bbPress (r3311)
150 172 *
151 - * @return string Path to template file.
173 + * @return string Path to template file
152 174 */
153 175 function bbp_get_single_user_edit_template() {
154 176 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
155 177 $user_id = bbp_get_displayed_user_id();
@@ -163,13 +185,13 @@
163 185 return bbp_get_query_template( 'profile_edit', $templates );
164 186 }
165 187
166 188 /**
167 - * Get the user favorites template.
189 + * Get the user favorites template
168 190 *
169 191 * @since 2.2.0 bbPress (r4225)
170 192 *
171 - * @return string Path to template file.
193 + * @return string Path to template file
172 194 */
173 195 function bbp_get_favorites_template() {
174 196 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
175 197 $user_id = bbp_get_displayed_user_id();
@@ -184,13 +206,13 @@
184 206 return bbp_get_query_template( 'favorites', $templates );
185 207 }
186 208
187 209 /**
188 - * Get the user subscriptions template.
210 + * Get the user subscriptions template
189 211 *
190 212 * @since 2.2.0 bbPress (r4225)
191 213 *
192 - * @return string Path to template file.
214 + * @return string Path to template file
193 215 */
194 216 function bbp_get_subscriptions_template() {
195 217 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
196 218 $user_id = bbp_get_displayed_user_id();
@@ -205,13 +227,13 @@
205 227 return bbp_get_query_template( 'subscriptions', $templates );
206 228 }
207 229
208 230 /**
209 - * Get the view template.
231 + * Get the view template
210 232 *
211 233 * @since 2.0.0 bbPress (r3311)
212 234 *
213 - * @return string Path to template file.
235 + * @return string Path to template file
214 236 */
215 237 function bbp_get_single_view_template() {
216 238 $view_id = bbp_get_view_id();
217 239 $templates = array(
@@ -223,13 +245,13 @@
223 245 return bbp_get_query_template( 'single_view', $templates );
224 246 }
225 247
226 248 /**
227 - * Get the search template.
249 + * Get the search template
228 250 *
229 251 * @since 2.3.0 bbPress (r4579)
230 252 *
231 - * @return string Path to template file.
253 + * @return string Path to template file
232 254 */
233 255 function bbp_get_search_template() {
234 256 $templates = array(
235 257 'page-forum-search.php', // Single Search
@@ -238,13 +260,13 @@
238 260 return bbp_get_query_template( 'single_search', $templates );
239 261 }
240 262
241 263 /**
242 - * Get the single forum template.
264 + * Get the single forum template
243 265 *
244 266 * @since 2.1.0 bbPress (r3922)
245 267 *
246 - * @return string Path to template file.
268 + * @return string Path to template file
247 269 */
248 270 function bbp_get_single_forum_template() {
249 271 $templates = array(
250 272 'single-' . bbp_get_forum_post_type() . '.php' // Single Forum
@@ -252,13 +274,13 @@
252 274 return bbp_get_query_template( 'single_forum', $templates );
253 275 }
254 276
255 277 /**
256 - * Get the forum archive template.
278 + * Get the forum archive template
257 279 *
258 280 * @since 2.1.0 bbPress (r3922)
259 281 *
260 - * @return string Path to template file.
282 + * @return string Path to template file
261 283 */
262 284 function bbp_get_forum_archive_template() {
263 285 $templates = array(
264 286 'archive-' . bbp_get_forum_post_type() . '.php' // Forum Archive
@@ -266,13 +288,13 @@
266 288 return bbp_get_query_template( 'forum_archive', $templates );
267 289 }
268 290
269 291 /**
270 - * Get the forum edit template.
292 + * Get the forum edit template
271 293 *
272 294 * @since 2.1.0 bbPress (r3566)
273 295 *
274 - * @return string Path to template file.
296 + * @return string Path to template file
275 297 */
276 298 function bbp_get_forum_edit_template() {
277 299 $templates = array(
278 300 'single-' . bbp_get_forum_post_type() . '-edit.php' // Single Forum Edit
@@ -280,13 +302,13 @@
280 302 return bbp_get_query_template( 'forum_edit', $templates );
281 303 }
282 304
283 305 /**
284 - * Get the single topic template.
306 + * Get the single topic template
285 307 *
286 308 * @since 2.1.0 bbPress (r3922)
287 309 *
288 - * @return string Path to template file.
310 + * @return string Path to template file
289 311 */
290 312 function bbp_get_single_topic_template() {
291 313 $templates = array(
292 314 'single-' . bbp_get_topic_post_type() . '.php'
@@ -294,13 +316,13 @@
294 316 return bbp_get_query_template( 'single_topic', $templates );
295 317 }
296 318
297 319 /**
298 - * Get the topic archive template.
320 + * Get the topic archive template
299 321 *
300 322 * @since 2.1.0 bbPress (r3922)
301 323 *
302 - * @return string Path to template file.
324 + * @return string Path to template file
303 325 */
304 326 function bbp_get_topic_archive_template() {
305 327 $templates = array(
306 328 'archive-' . bbp_get_topic_post_type() . '.php' // Topic Archive
@@ -308,13 +330,13 @@
308 330 return bbp_get_query_template( 'topic_archive', $templates );
309 331 }
310 332
311 333 /**
312 - * Get the topic edit template.
334 + * Get the topic edit template
313 335 *
314 336 * @since 2.0.0 bbPress (r3311)
315 337 *
316 - * @return string Path to template file.
338 + * @return string Path to template file
317 339 */
318 340 function bbp_get_topic_edit_template() {
319 341 $templates = array(
320 342 'single-' . bbp_get_topic_post_type() . '-edit.php' // Single Topic Edit
@@ -322,13 +344,13 @@
322 344 return bbp_get_query_template( 'topic_edit', $templates );
323 345 }
324 346
325 347 /**
326 - * Get the topic split template.
348 + * Get the topic split template
327 349 *
328 350 * @since 2.0.0 bbPress (r3311)
329 351 *
330 - * @return string Path to template file.
352 + * @return string Path to template file
331 353 */
332 354 function bbp_get_topic_split_template() {
333 355 $templates = array(
334 356 'single-' . bbp_get_topic_post_type() . '-split.php', // Topic Split
@@ -336,13 +358,13 @@
336 358 return bbp_get_query_template( 'topic_split', $templates );
337 359 }
338 360
339 361 /**
340 - * Get the topic merge template.
362 + * Get the topic merge template
341 363 *
342 364 * @since 2.0.0 bbPress (r3311)
343 365 *
344 - * @return string Path to template file.
366 + * @return string Path to template file
345 367 */
346 368 function bbp_get_topic_merge_template() {
347 369 $templates = array(
348 370 'single-' . bbp_get_topic_post_type() . '-merge.php', // Topic Merge
@@ -350,13 +372,13 @@
350 372 return bbp_get_query_template( 'topic_merge', $templates );
351 373 }
352 374
353 375 /**
354 - * Get the single reply template.
376 + * Get the single reply template
355 377 *
356 378 * @since 2.1.0 bbPress (r3922)
357 379 *
358 - * @return string Path to template file.
380 + * @return string Path to template file
359 381 */
360 382 function bbp_get_single_reply_template() {
361 383 $templates = array(
362 384 'single-' . bbp_get_reply_post_type() . '.php'
@@ -364,13 +386,13 @@
364 386 return bbp_get_query_template( 'single_reply', $templates );
365 387 }
366 388
367 389 /**
368 - * Get the reply edit template.
390 + * Get the reply edit template
369 391 *
370 392 * @since 2.0.0 bbPress (r3311)
371 393 *
372 -* @return string Path to template file.
394 +* @return string Path to template file
373 395 */
374 396 function bbp_get_reply_edit_template() {
375 397 $templates = array(
376 398 'single-' . bbp_get_reply_post_type() . '-edit.php' // Single Reply Edit
@@ -378,13 +400,13 @@
378 400 return bbp_get_query_template( 'reply_edit', $templates );
379 401 }
380 402
381 403 /**
382 - * Get the reply move template.
404 + * Get the reply move template
383 405 *
384 406 * @since 2.3.0 bbPress (r4521)
385 407 *
386 - * @return string Path to template file.
408 + * @return string Path to template file
387 409 */
388 410 function bbp_get_reply_move_template() {
389 411 $templates = array(
390 412 'single-' . bbp_get_reply_post_type() . '-move.php', // Reply move
@@ -392,13 +414,13 @@
392 414 return bbp_get_query_template( 'reply_move', $templates );
393 415 }
394 416
395 417 /**
396 - * Get the topic template.
418 + * Get the topic template
397 419 *
398 420 * @since 2.0.0 bbPress (r3311)
399 421 *
400 - * @return string Path to template file.
422 + * @return string Path to template file
401 423 */
402 424 function bbp_get_topic_tag_template() {
403 425 $tt_slug = bbp_get_topic_tag_slug();
404 426 $tt_id = bbp_get_topic_tag_tax_id();
@@ -409,13 +431,13 @@
409 431 return bbp_get_query_template( 'topic_tag', $templates );
410 432 }
411 433
412 434 /**
413 - * Get the topic edit template.
435 + * Get the topic edit template
414 436 *
415 437 * @since 2.0.0 bbPress (r3311)
416 438 *
417 - * @return string Path to template file.
439 + * @return string Path to template file
418 440 */
419 441 function bbp_get_topic_tag_edit_template() {
420 442 $tt_slug = bbp_get_topic_tag_slug();
421 443 $tt_id = bbp_get_topic_tag_tax_id();
@@ -426,15 +448,16 @@
426 448 return bbp_get_query_template( 'topic_tag_edit', $templates );
427 449 }
428 450
429 451 /**
430 - * Get the template to use as the wrapper for bbPress template parts.
452 + * Get the templates to use as the endpoint for bbPress template parts
431 453 *
432 - * @since 2.7.0 bbPress (r7393)
454 + * @since 2.0.0 bbPress (r3311)
455 + * @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack
433 456 *
434 - * @return string Path to template file.
457 + * @return string Path to template file
435 458 */
436 -function bbp_get_theme_compat_template() {
459 +function bbp_get_theme_compat_templates() {
437 460 $templates = array(
438 461 'plugin-bbpress.php',
439 462 'bbpress.php',
440 463 'forums.php',
@@ -461,76 +484,5 @@
461 484 $template = ABSPATH . WPINC . '/template-canvas.php';
462 485
463 486 // Filter & return
464 487 return apply_filters( 'bbp_get_theme_canvas_template', $template );
465 -}
466 -
467 -/**
468 - * Get the array of _is_ functions and their template finders.
469 - *
470 - * This function abstracts the template checkers & getters to allow third-party
471 - * plugins to add their own bbPress component functionality more easily.
472 - *
473 - * @since 2.7.0 bbPress (r7393)
474 - *
475 - * @return array Key => Value array of checkers & getters.
476 - */
477 -function bbp_get_template_include_templates() {
478 -
479 - // Possible templates: checker => getter
480 - $templates = array(
481 -
482 - // User
483 - 'bbp_is_single_user_edit' => 'bbp_get_single_user_edit_template',
484 - 'bbp_is_favorites' => 'bbp_get_favorites_template',
485 - 'bbp_is_subscriptions' => 'bbp_get_subscriptions_template',
486 - 'bbp_is_single_user' => 'bbp_get_single_user_template',
487 -
488 - // Topic view
489 - 'bbp_is_single_view' => 'bbp_get_single_view_template',
490 -
491 - // Search
492 - 'bbp_is_search' => 'bbp_get_search_template',
493 -
494 - // Forum
495 - 'bbp_is_forum_edit' => 'bbp_get_forum_edit_template',
496 - 'bbp_is_single_forum' => 'bbp_get_single_forum_template',
497 - 'bbp_is_forum_archive' => 'bbp_get_forum_archive_template',
498 -
499 - // Topic
500 - 'bbp_is_topic_merge' => 'bbp_get_topic_merge_template',
501 - 'bbp_is_topic_split' => 'bbp_get_topic_split_template',
502 - 'bbp_is_topic_edit' => 'bbp_get_topic_edit_template',
503 - 'bbp_is_single_topic' => 'bbp_get_single_topic_template',
504 - 'bbp_is_topic_archive' => 'bbp_get_topic_archive_template',
505 -
506 - // Reply
507 - 'bbp_is_reply_move' => 'bbp_get_reply_move_template',
508 - 'bbp_is_reply_edit' => 'bbp_get_reply_edit_template',
509 - 'bbp_is_single_reply' => 'bbp_get_single_reply_template',
510 -
511 - // Topic tag
512 - 'bbp_is_topic_tag_edit' => 'bbp_get_topic_tag_edit_template',
513 - 'bbp_is_topic_tag' => 'bbp_get_topic_tag_template',
514 - );
515 -
516 - // Filter & return
517 - return (array) apply_filters( 'bbp_get_template_include_templates', $templates );
518 -}
519 -
520 -/** Deprecated ****************************************************************/
521 -
522 -/**
523 - * Get the templates to use as the endpoint for bbPress template parts.
524 - *
525 - * This function was deprecated because it was named plural when it should have
526 - * been singular, as it only returns the path to a single file.
527 - *
528 - * @since 2.0.0 bbPress (r3311)
529 - * @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack
530 - * @deprecated 2.7.0 bbPress (r7393)
531 - *
532 - * @return string Path to template file.
533 - */
534 -function bbp_get_theme_compat_templates() {
535 - return bbp_get_theme_compat_template();
536 488 }