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 +125 -105 2.2.12.6.17 View file →
@@ -7,9 +7,9 @@
7 7 * @subpackage TemplateLoader
8 8 */
9 9
10 10 // Exit if accessed directly
11 -if ( !defined( 'ABSPATH' ) ) exit;
11 +defined( 'ABSPATH' ) || exit;
12 12
13 13 /**
14 14 * Possibly intercept the template being loaded
15 15 *
@@ -14,104 +14,114 @@
14 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 - * @since bbPress (r3032)
23 + * @since 2.0.0 bbPress (r3032)
24 24 *
25 25 * @param string $template
26 26 *
27 - * @uses bbp_is_single_user() To check if page is single user
28 - * @uses bbp_get_single_user_template() To get user template
29 - * @uses bbp_is_single_user_edit() To check if page is single user edit
30 - * @uses bbp_get_single_user_edit_template() To get user edit template
31 - * @uses bbp_is_single_view() To check if page is single view
32 - * @uses bbp_get_single_view_template() To get view template
33 - * @uses bbp_is_forum_edit() To check if page is forum edit
34 - * @uses bbp_get_forum_edit_template() To get forum edit template
35 - * @uses bbp_is_topic_merge() To check if page is topic merge
36 - * @uses bbp_get_topic_merge_template() To get topic merge template
37 - * @uses bbp_is_topic_split() To check if page is topic split
38 - * @uses bbp_get_topic_split_template() To get topic split template
39 - * @uses bbp_is_topic_edit() To check if page is topic edit
40 - * @uses bbp_get_topic_edit_template() To get topic edit template
41 - * @uses bbp_is_reply_edit() To check if page is reply edit
42 - * @uses bbp_get_reply_edit_template() To get reply edit template
43 - * @uses bbp_set_theme_compat_template() To set the global theme compat template
44 - *
45 27 * @return string The path to the template file that is being used
46 28 */
47 29 function bbp_template_include_theme_supports( $template = '' ) {
48 30
49 31 // Editing a user
50 - if ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
32 + if ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
51 33
52 34 // User favorites
53 - elseif ( bbp_is_favorites() && ( $new_template = bbp_get_favorites_template() ) ) :
35 + elseif ( bbp_is_favorites() && ( $new_template = bbp_get_favorites_template() ) ) :
54 36
55 37 // User favorites
56 - elseif ( bbp_is_subscriptions() && ( $new_template = bbp_get_subscriptions_template() ) ) :
38 + elseif ( bbp_is_subscriptions() && ( $new_template = bbp_get_subscriptions_template() ) ) :
57 39
58 40 // Viewing a user
59 - elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
41 + elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
60 42
61 43 // Single View
62 - elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
44 + elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
63 45
46 + // Search
47 + elseif ( bbp_is_search() && ( $new_template = bbp_get_search_template() ) ) :
48 +
64 49 // Forum edit
65 - elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) :
50 + elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) :
66 51
67 52 // Single Forum
68 - elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) :
53 + elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) :
69 54
70 55 // Forum Archive
71 - elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) :
56 + elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) :
72 57
73 58 // Topic merge
74 - elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
59 + elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
75 60
76 61 // Topic split
77 - elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
62 + elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
78 63
79 64 // Topic edit
80 - elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
65 + elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
81 66
82 67 // Single Topic
83 - elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) :
68 + elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) :
84 69
85 70 // Topic Archive
86 - elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) :
71 + elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) :
87 72
73 + // Reply move
74 + elseif ( bbp_is_reply_move() && ( $new_template = bbp_get_reply_move_template() ) ) :
75 +
88 76 // Editing a reply
89 - elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
77 + elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
90 78
91 79 // Single Reply
92 - elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) :
80 + elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) :
93 81
94 82 // Editing a topic tag
95 - elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
83 + elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
96 84
97 85 // Viewing a topic tag
98 - elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
86 + elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
99 87 endif;
100 88
101 - // bbPress template file exists
102 - if ( !empty( $new_template ) ) {
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 );
93 + }
103 94
104 - // Override the WordPress template with a bbPress one
105 - $template = $new_template;
95 + // Filter & return
96 + return apply_filters( 'bbp_template_include_theme_supports', $template );
97 +}
106 98
107 - // @see: bbp_template_include_theme_compat()
108 - bbpress()->theme_compat->bbpress_template = true;
109 - }
99 +/**
100 + * Set the included template
101 + *
102 + * @since 2.4.0 bbPress (r4975)
103 + *
104 + * @param mixed $template Default false
105 + * @return mixed False if empty. Template name if template included
106 + */
107 +function bbp_set_template_included( $template = false ) {
108 + bbpress()->theme_compat->bbpress_template = $template;
110 109
111 - return apply_filters( 'bbp_template_include_theme_supports', $template );
110 + return bbpress()->theme_compat->bbpress_template;
112 111 }
113 112
113 +/**
114 + * Is a bbPress template being included?
115 + *
116 + * @since 2.4.0 bbPress (r4975)
117 + *
118 + * @return bool True if yes, false if no
119 + */
120 +function bbp_is_template_included() {
121 + return ! empty( bbpress()->theme_compat->bbpress_template );
122 +}
123 +
114 124 /** Custom Functions **********************************************************/
115 125
116 126 /**
117 127 * Attempt to load a custom bbPress functions file, similar to each themes
@@ -116,21 +126,21 @@
116 126 /**
117 127 * Attempt to load a custom bbPress functions file, similar to each themes
118 128 * functions.php file.
119 129 *
120 - * @since bbPress (r3732)
130 + * @since 2.1.0 bbPress (r3732)
121 131 *
122 132 * @global string $pagenow
123 - * @uses bbp_locate_template()
124 133 */
125 134 function bbp_load_theme_functions() {
126 135 global $pagenow;
127 136
128 137 // If bbPress is being deactivated, do not load any more files
129 - if ( bbp_is_deactivation() )
138 + if ( bbp_is_deactivation() ) {
130 139 return;
140 + }
131 141
132 - if ( ! defined( 'WP_INSTALLING' ) || ( !empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
142 + if ( ! defined( 'WP_INSTALLING' ) || ( ! empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
133 143 bbp_locate_template( 'bbpress-functions.php', true );
134 144 }
135 145 }
136 146
@@ -138,12 +148,10 @@
138 148
139 149 /**
140 150 * Get the user profile template
141 151 *
142 - * @since bbPress (r3311)
152 + * @since 2.0.0 bbPress (r3311)
143 153 *
144 - * @uses bbp_get_displayed_user_id()
145 - * @uses bbp_get_query_template()
146 154 * @return string Path to template file
147 155 */
148 156 function bbp_get_single_user_template() {
149 157 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
@@ -159,12 +167,10 @@
159 167
160 168 /**
161 169 * Get the user profile edit template
162 170 *
163 - * @since bbPress (r3311)
171 + * @since 2.0.0 bbPress (r3311)
164 172 *
165 - * @uses bbp_get_displayed_user_id()
166 - * @uses bbp_get_query_template()
167 173 * @return string Path to template file
168 174 */
169 175 function bbp_get_single_user_edit_template() {
170 176 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
@@ -181,12 +187,10 @@
181 187
182 188 /**
183 189 * Get the user favorites template
184 190 *
185 - * @since bbPress (r4225)
191 + * @since 2.2.0 bbPress (r4225)
186 192 *
187 - * @uses bbp_get_displayed_user_id()
188 - * @uses bbp_get_query_template()
189 193 * @return string Path to template file
190 194 */
191 195 function bbp_get_favorites_template() {
192 196 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
@@ -204,12 +208,10 @@
204 208
205 209 /**
206 210 * Get the user subscriptions template
207 211 *
208 - * @since bbPress (r4225)
212 + * @since 2.2.0 bbPress (r4225)
209 213 *
210 - * @uses bbp_get_displayed_user_id()
211 - * @uses bbp_get_query_template()
212 214 * @return string Path to template file
213 215 */
214 216 function bbp_get_subscriptions_template() {
215 217 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
@@ -227,12 +229,10 @@
227 229
228 230 /**
229 231 * Get the view template
230 232 *
231 - * @since bbPress (r3311)
233 + * @since 2.0.0 bbPress (r3311)
232 234 *
233 - * @uses bbp_get_view_id()
234 - * @uses bbp_get_query_template()
235 235 * @return string Path to template file
236 236 */
237 237 function bbp_get_single_view_template() {
238 238 $view_id = bbp_get_view_id();
@@ -245,14 +245,27 @@
245 245 return bbp_get_query_template( 'single_view', $templates );
246 246 }
247 247
248 248 /**
249 + * Get the search template
250 + *
251 + * @since 2.3.0 bbPress (r4579)
252 + *
253 + * @return string Path to template file
254 + */
255 +function bbp_get_search_template() {
256 + $templates = array(
257 + 'page-forum-search.php', // Single Search
258 + 'forum-search.php', // Search
259 + );
260 + return bbp_get_query_template( 'single_search', $templates );
261 +}
262 +
263 +/**
249 264 * Get the single forum template
250 265 *
251 - * @since bbPress (r3922)
266 + * @since 2.1.0 bbPress (r3922)
252 267 *
253 - * @uses bbp_get_forum_post_type()
254 - * @uses bbp_get_query_template()
255 268 * @return string Path to template file
256 269 */
257 270 function bbp_get_single_forum_template() {
258 271 $templates = array(
@@ -263,12 +276,10 @@
263 276
264 277 /**
265 278 * Get the forum archive template
266 279 *
267 - * @since bbPress (r3922)
280 + * @since 2.1.0 bbPress (r3922)
268 281 *
269 - * @uses bbp_get_forum_post_type()
270 - * @uses bbp_get_query_template()
271 282 * @return string Path to template file
272 283 */
273 284 function bbp_get_forum_archive_template() {
274 285 $templates = array(
@@ -279,12 +290,10 @@
279 290
280 291 /**
281 292 * Get the forum edit template
282 293 *
283 - * @since bbPress (r3566)
294 + * @since 2.1.0 bbPress (r3566)
284 295 *
285 - * @uses bbp_get_topic_post_type()
286 - * @uses bbp_get_query_template()
287 296 * @return string Path to template file
288 297 */
289 298 function bbp_get_forum_edit_template() {
290 299 $templates = array(
@@ -295,12 +304,10 @@
295 304
296 305 /**
297 306 * Get the single topic template
298 307 *
299 - * @since bbPress (r3922)
308 + * @since 2.1.0 bbPress (r3922)
300 309 *
301 - * @uses bbp_get_topic_post_type()
302 - * @uses bbp_get_query_template()
303 310 * @return string Path to template file
304 311 */
305 312 function bbp_get_single_topic_template() {
306 313 $templates = array(
@@ -311,12 +318,10 @@
311 318
312 319 /**
313 320 * Get the topic archive template
314 321 *
315 - * @since bbPress (r3922)
322 + * @since 2.1.0 bbPress (r3922)
316 323 *
317 - * @uses bbp_get_topic_post_type()
318 - * @uses bbp_get_query_template()
319 324 * @return string Path to template file
320 325 */
321 326 function bbp_get_topic_archive_template() {
322 327 $templates = array(
@@ -327,12 +332,10 @@
327 332
328 333 /**
329 334 * Get the topic edit template
330 335 *
331 - * @since bbPress (r3311)
336 + * @since 2.0.0 bbPress (r3311)
332 337 *
333 - * @uses bbp_get_topic_post_type()
334 - * @uses bbp_get_query_template()
335 338 * @return string Path to template file
336 339 */
337 340 function bbp_get_topic_edit_template() {
338 341 $templates = array(
@@ -343,12 +346,10 @@
343 346
344 347 /**
345 348 * Get the topic split template
346 349 *
347 - * @since bbPress (r3311)
350 + * @since 2.0.0 bbPress (r3311)
348 351 *
349 - * @uses bbp_get_topic_post_type()
350 - * @uses bbp_get_query_template()
351 352 * @return string Path to template file
352 353 */
353 354 function bbp_get_topic_split_template() {
354 355 $templates = array(
@@ -359,12 +360,10 @@
359 360
360 361 /**
361 362 * Get the topic merge template
362 363 *
363 - * @since bbPress (r3311)
364 + * @since 2.0.0 bbPress (r3311)
364 365 *
365 - * @uses bbp_get_topic_post_type()
366 - * @uses bbp_get_query_template()
367 366 * @return string Path to template file
368 367 */
369 368 function bbp_get_topic_merge_template() {
370 369 $templates = array(
@@ -375,12 +374,10 @@
375 374
376 375 /**
377 376 * Get the single reply template
378 377 *
379 - * @since bbPress (r3922)
378 + * @since 2.1.0 bbPress (r3922)
380 379 *
381 - * @uses bbp_get_reply_post_type()
382 - * @uses bbp_get_query_template()
383 380 * @return string Path to template file
384 381 */
385 382 function bbp_get_single_reply_template() {
386 383 $templates = array(
@@ -391,12 +388,10 @@
391 388
392 389 /**
393 390 * Get the reply edit template
394 391 *
395 - * @since bbPress (r3311)
392 + * @since 2.0.0 bbPress (r3311)
396 393 *
397 - * @uses bbp_get_reply_post_type()
398 - * @uses bbp_get_query_template()
399 394 * @return string Path to template file
400 395 */
401 396 function bbp_get_reply_edit_template() {
402 397 $templates = array(
@@ -405,14 +400,26 @@
405 400 return bbp_get_query_template( 'reply_edit', $templates );
406 401 }
407 402
408 403 /**
404 + * Get the reply move template
405 + *
406 + * @since 2.3.0 bbPress (r4521)
407 + *
408 + * @return string Path to template file
409 + */
410 +function bbp_get_reply_move_template() {
411 + $templates = array(
412 + 'single-' . bbp_get_reply_post_type() . '-move.php', // Reply move
413 + );
414 + return bbp_get_query_template( 'reply_move', $templates );
415 +}
416 +
417 +/**
409 418 * Get the topic template
410 419 *
411 - * @since bbPress (r3311)
420 + * @since 2.0.0 bbPress (r3311)
412 421 *
413 - * @uses bbp_get_topic_tag_tax_id()
414 - * @uses bbp_get_query_template()
415 422 * @return string Path to template file
416 423 */
417 424 function bbp_get_topic_tag_template() {
418 425 $tt_slug = bbp_get_topic_tag_slug();
@@ -426,12 +433,10 @@
426 433
427 434 /**
428 435 * Get the topic edit template
429 436 *
430 - * @since bbPress (r3311)
437 + * @since 2.0.0 bbPress (r3311)
431 438 *
432 - * @uses bbp_get_topic_tag_tax_id()
433 - * @uses bbp_get_query_template()
434 439 * @return string Path to template file
435 440 */
436 441 function bbp_get_topic_tag_edit_template() {
437 442 $tt_slug = bbp_get_topic_tag_slug();
@@ -445,13 +450,11 @@
445 450
446 451 /**
447 452 * Get the templates to use as the endpoint for bbPress template parts
448 453 *
449 - * @since bbPress (r3311)
454 + * @since 2.0.0 bbPress (r3311)
455 + * @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack
450 456 *
451 - * @uses apply_filters()
452 - * @uses bbp_set_theme_compat_templates()
453 - * @uses bbp_get_query_template()
454 457 * @return string Path to template file
455 458 */
456 459 function bbp_get_theme_compat_templates() {
457 460 $templates = array(
@@ -461,8 +464,25 @@
461 464 'forum.php',
462 465 'generic.php',
463 466 'page.php',
464 467 'single.php',
468 + 'singular.php',
465 469 'index.php'
466 470 );
467 471 return bbp_get_query_template( 'bbpress', $templates );
472 +}
473 +
474 +/**
475 + * Get the theme canvas template, used for Block Themes.
476 + *
477 + * @since 2.6.17 bbPress
478 + *
479 + * @return string Path to canvas file.
480 + */
481 +function bbp_get_theme_canvas_template() {
482 +
483 + // Default WordPress Canvas
484 + $template = ABSPATH . WPINC . '/template-canvas.php';
485 +
486 + // Filter & return
487 + return apply_filters( 'bbp_get_theme_canvas_template', $template );
468 488 }