PluginProbe
bbPress / 2.2.2
bbPress v2.2.2
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 2.2.2 All 71 releases
bbpress / includes / core / template-loader.php

template-loader.php in bbPress 2.2.2, at includes/core/template-loader.php

469 lines 13.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Template Loader
5 *
6 * @package bbPress
7 * @subpackage TemplateLoader
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Possibly intercept the template being loaded
15 *
16 * Listens to the 'template_include' filter and waits for any bbPress specific
17 * template condition to be met. If one is met and the template file exists,
18 * it will be used; otherwise
19 *
20 * Note that the _edit() checks are ahead of their counterparts, to prevent them
21 * from being stomped on accident.
22 *
23 * @since bbPress (r3032)
24 *
25 * @param string $template
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 * @return string The path to the template file that is being used
46 */
47 function bbp_template_include_theme_supports( $template = '' ) {
48
49 // Editing a user
50 if ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
51
52 // User favorites
53 elseif ( bbp_is_favorites() && ( $new_template = bbp_get_favorites_template() ) ) :
54
55 // User favorites
56 elseif ( bbp_is_subscriptions() && ( $new_template = bbp_get_subscriptions_template() ) ) :
57
58 // Viewing a user
59 elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
60
61 // Single View
62 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
63
64 // Forum edit
65 elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) :
66
67 // Single Forum
68 elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) :
69
70 // Forum Archive
71 elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) :
72
73 // Topic merge
74 elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
75
76 // Topic split
77 elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
78
79 // Topic edit
80 elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
81
82 // Single Topic
83 elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) :
84
85 // Topic Archive
86 elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) :
87
88 // Editing a reply
89 elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
90
91 // Single Reply
92 elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) :
93
94 // Editing a topic tag
95 elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
96
97 // Viewing a topic tag
98 elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
99 endif;
100
101 // bbPress template file exists
102 if ( !empty( $new_template ) ) {
103
104 // Override the WordPress template with a bbPress one
105 $template = $new_template;
106
107 // @see: bbp_template_include_theme_compat()
108 bbpress()->theme_compat->bbpress_template = true;
109 }
110
111 return apply_filters( 'bbp_template_include_theme_supports', $template );
112 }
113
114 /** Custom Functions **********************************************************/
115
116 /**
117 * Attempt to load a custom bbPress functions file, similar to each themes
118 * functions.php file.
119 *
120 * @since bbPress (r3732)
121 *
122 * @global string $pagenow
123 * @uses bbp_locate_template()
124 */
125 function bbp_load_theme_functions() {
126 global $pagenow;
127
128 // If bbPress is being deactivated, do not load any more files
129 if ( bbp_is_deactivation() )
130 return;
131
132 if ( ! defined( 'WP_INSTALLING' ) || ( !empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
133 bbp_locate_template( 'bbpress-functions.php', true );
134 }
135 }
136
137 /** Individual Templates ******************************************************/
138
139 /**
140 * Get the user profile template
141 *
142 * @since bbPress (r3311)
143 *
144 * @uses bbp_get_displayed_user_id()
145 * @uses bbp_get_query_template()
146 * @return string Path to template file
147 */
148 function bbp_get_single_user_template() {
149 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
150 $user_id = bbp_get_displayed_user_id();
151 $templates = array(
152 'single-user-' . $nicename . '.php', // Single User nicename
153 'single-user-' . $user_id . '.php', // Single User ID
154 'single-user.php', // Single User
155 'user.php', // User
156 );
157 return bbp_get_query_template( 'profile', $templates );
158 }
159
160 /**
161 * Get the user profile edit template
162 *
163 * @since bbPress (r3311)
164 *
165 * @uses bbp_get_displayed_user_id()
166 * @uses bbp_get_query_template()
167 * @return string Path to template file
168 */
169 function bbp_get_single_user_edit_template() {
170 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
171 $user_id = bbp_get_displayed_user_id();
172 $templates = array(
173 'single-user-edit-' . $nicename . '.php', // Single User Edit nicename
174 'single-user-edit-' . $user_id . '.php', // Single User Edit ID
175 'single-user-edit.php', // Single User Edit
176 'user-edit.php', // User Edit
177 'user.php', // User
178 );
179 return bbp_get_query_template( 'profile_edit', $templates );
180 }
181
182 /**
183 * Get the user favorites template
184 *
185 * @since bbPress (r4225)
186 *
187 * @uses bbp_get_displayed_user_id()
188 * @uses bbp_get_query_template()
189 * @return string Path to template file
190 */
191 function bbp_get_favorites_template() {
192 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
193 $user_id = bbp_get_displayed_user_id();
194 $templates = array(
195 'single-user-favorites-' . $nicename . '.php', // Single User Favs nicename
196 'single-user-favorites-' . $user_id . '.php', // Single User Favs ID
197 'favorites-' . $nicename . '.php', // Favorites nicename
198 'favorites-' . $user_id . '.php', // Favorites ID
199 'favorites.php', // Favorites
200 'user.php', // User
201 );
202 return bbp_get_query_template( 'favorites', $templates );
203 }
204
205 /**
206 * Get the user subscriptions template
207 *
208 * @since bbPress (r4225)
209 *
210 * @uses bbp_get_displayed_user_id()
211 * @uses bbp_get_query_template()
212 * @return string Path to template file
213 */
214 function bbp_get_subscriptions_template() {
215 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
216 $user_id = bbp_get_displayed_user_id();
217 $templates = array(
218 'single-user-subscriptions-' . $nicename . '.php', // Single User Subs nicename
219 'single-user-subscriptions-' . $user_id . '.php', // Single User Subs ID
220 'subscriptions-' . $nicename . '.php', // Subscriptions nicename
221 'subscriptions-' . $user_id . '.php', // Subscriptions ID
222 'subscriptions.php', // Subscriptions
223 'user.php', // User
224 );
225 return bbp_get_query_template( 'subscriptions', $templates );
226 }
227
228 /**
229 * Get the view template
230 *
231 * @since bbPress (r3311)
232 *
233 * @uses bbp_get_view_id()
234 * @uses bbp_get_query_template()
235 * @return string Path to template file
236 */
237 function bbp_get_single_view_template() {
238 $view_id = bbp_get_view_id();
239 $templates = array(
240 'single-view-' . $view_id . '.php', // Single View ID
241 'view-' . $view_id . '.php', // View ID
242 'single-view.php', // Single View
243 'view.php', // View
244 );
245 return bbp_get_query_template( 'single_view', $templates );
246 }
247
248 /**
249 * Get the single forum template
250 *
251 * @since bbPress (r3922)
252 *
253 * @uses bbp_get_forum_post_type()
254 * @uses bbp_get_query_template()
255 * @return string Path to template file
256 */
257 function bbp_get_single_forum_template() {
258 $templates = array(
259 'single-' . bbp_get_forum_post_type() . '.php' // Single Forum
260 );
261 return bbp_get_query_template( 'single_forum', $templates );
262 }
263
264 /**
265 * Get the forum archive template
266 *
267 * @since bbPress (r3922)
268 *
269 * @uses bbp_get_forum_post_type()
270 * @uses bbp_get_query_template()
271 * @return string Path to template file
272 */
273 function bbp_get_forum_archive_template() {
274 $templates = array(
275 'archive-' . bbp_get_forum_post_type() . '.php' // Forum Archive
276 );
277 return bbp_get_query_template( 'forum_archive', $templates );
278 }
279
280 /**
281 * Get the forum edit template
282 *
283 * @since bbPress (r3566)
284 *
285 * @uses bbp_get_topic_post_type()
286 * @uses bbp_get_query_template()
287 * @return string Path to template file
288 */
289 function bbp_get_forum_edit_template() {
290 $templates = array(
291 'single-' . bbp_get_forum_post_type() . '-edit.php' // Single Forum Edit
292 );
293 return bbp_get_query_template( 'forum_edit', $templates );
294 }
295
296 /**
297 * Get the single topic template
298 *
299 * @since bbPress (r3922)
300 *
301 * @uses bbp_get_topic_post_type()
302 * @uses bbp_get_query_template()
303 * @return string Path to template file
304 */
305 function bbp_get_single_topic_template() {
306 $templates = array(
307 'single-' . bbp_get_topic_post_type() . '.php'
308 );
309 return bbp_get_query_template( 'single_topic', $templates );
310 }
311
312 /**
313 * Get the topic archive template
314 *
315 * @since bbPress (r3922)
316 *
317 * @uses bbp_get_topic_post_type()
318 * @uses bbp_get_query_template()
319 * @return string Path to template file
320 */
321 function bbp_get_topic_archive_template() {
322 $templates = array(
323 'archive-' . bbp_get_topic_post_type() . '.php' // Topic Archive
324 );
325 return bbp_get_query_template( 'topic_archive', $templates );
326 }
327
328 /**
329 * Get the topic edit template
330 *
331 * @since bbPress (r3311)
332 *
333 * @uses bbp_get_topic_post_type()
334 * @uses bbp_get_query_template()
335 * @return string Path to template file
336 */
337 function bbp_get_topic_edit_template() {
338 $templates = array(
339 'single-' . bbp_get_topic_post_type() . '-edit.php' // Single Topic Edit
340 );
341 return bbp_get_query_template( 'topic_edit', $templates );
342 }
343
344 /**
345 * Get the topic split template
346 *
347 * @since bbPress (r3311)
348 *
349 * @uses bbp_get_topic_post_type()
350 * @uses bbp_get_query_template()
351 * @return string Path to template file
352 */
353 function bbp_get_topic_split_template() {
354 $templates = array(
355 'single-' . bbp_get_topic_post_type() . '-split.php', // Topic Split
356 );
357 return bbp_get_query_template( 'topic_split', $templates );
358 }
359
360 /**
361 * Get the topic merge template
362 *
363 * @since bbPress (r3311)
364 *
365 * @uses bbp_get_topic_post_type()
366 * @uses bbp_get_query_template()
367 * @return string Path to template file
368 */
369 function bbp_get_topic_merge_template() {
370 $templates = array(
371 'single-' . bbp_get_topic_post_type() . '-merge.php', // Topic Merge
372 );
373 return bbp_get_query_template( 'topic_merge', $templates );
374 }
375
376 /**
377 * Get the single reply template
378 *
379 * @since bbPress (r3922)
380 *
381 * @uses bbp_get_reply_post_type()
382 * @uses bbp_get_query_template()
383 * @return string Path to template file
384 */
385 function bbp_get_single_reply_template() {
386 $templates = array(
387 'single-' . bbp_get_reply_post_type() . '.php'
388 );
389 return bbp_get_query_template( 'single_reply', $templates );
390 }
391
392 /**
393 * Get the reply edit template
394 *
395 * @since bbPress (r3311)
396 *
397 * @uses bbp_get_reply_post_type()
398 * @uses bbp_get_query_template()
399 * @return string Path to template file
400 */
401 function bbp_get_reply_edit_template() {
402 $templates = array(
403 'single-' . bbp_get_reply_post_type() . '-edit.php' // Single Reply Edit
404 );
405 return bbp_get_query_template( 'reply_edit', $templates );
406 }
407
408 /**
409 * Get the topic template
410 *
411 * @since bbPress (r3311)
412 *
413 * @uses bbp_get_topic_tag_tax_id()
414 * @uses bbp_get_query_template()
415 * @return string Path to template file
416 */
417 function bbp_get_topic_tag_template() {
418 $tt_slug = bbp_get_topic_tag_slug();
419 $tt_id = bbp_get_topic_tag_tax_id();
420 $templates = array(
421 'taxonomy-' . $tt_slug . '.php', // Single Topic Tag slug
422 'taxonomy-' . $tt_id . '.php', // Single Topic Tag ID
423 );
424 return bbp_get_query_template( 'topic_tag', $templates );
425 }
426
427 /**
428 * Get the topic edit template
429 *
430 * @since bbPress (r3311)
431 *
432 * @uses bbp_get_topic_tag_tax_id()
433 * @uses bbp_get_query_template()
434 * @return string Path to template file
435 */
436 function bbp_get_topic_tag_edit_template() {
437 $tt_slug = bbp_get_topic_tag_slug();
438 $tt_id = bbp_get_topic_tag_tax_id();
439 $templates = array(
440 'taxonomy-' . $tt_slug . '-edit.php', // Single Topic Tag Edit slug
441 'taxonomy-' . $tt_id . '-edit.php' // Single Topic Tag Edit ID
442 );
443 return bbp_get_query_template( 'topic_tag_edit', $templates );
444 }
445
446 /**
447 * Get the templates to use as the endpoint for bbPress template parts
448 *
449 * @since bbPress (r3311)
450 *
451 * @uses apply_filters()
452 * @uses bbp_set_theme_compat_templates()
453 * @uses bbp_get_query_template()
454 * @return string Path to template file
455 */
456 function bbp_get_theme_compat_templates() {
457 $templates = array(
458 'plugin-bbpress.php',
459 'bbpress.php',
460 'forums.php',
461 'forum.php',
462 'generic.php',
463 'page.php',
464 'single.php',
465 'index.php'
466 );
467 return bbp_get_query_template( 'bbpress', $templates );
468 }
469