PluginProbe
bbPress / 2.1
bbPress v2.1
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 / bbp-includes / bbp-template-loader.php

bbp-template-loader.php in bbPress 2.1, at bbp-includes/bbp-template-loader.php

423 lines 11.9 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 // Viewing a user
53 elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
54
55 // Single View
56 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
57
58 // Forum edit
59 elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) :
60
61 // Single Forum
62 elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) :
63
64 // Forum Archive
65 elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) :
66
67 // Topic merge
68 elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
69
70 // Topic split
71 elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
72
73 // Topic edit
74 elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
75
76 // Single Topic
77 elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) :
78
79 // Topic Archive
80 elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) :
81
82 // Editing a reply
83 elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
84
85 // Single Reply
86 elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) :
87
88 // Editing a topic tag
89 elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
90
91 // Viewing a topic tag
92 elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
93 endif;
94
95 // bbPress template file exists
96 if ( !empty( $new_template ) ) {
97
98 // Override the WordPress template with a bbPress one
99 $template = $new_template;
100
101 // @see: bbp_template_include_theme_compat()
102 bbpress()->theme_compat->bbpress_template = true;
103 }
104
105 return apply_filters( 'bbp_template_include_theme_supports', $template );
106 }
107
108 /** Custom Functions **********************************************************/
109
110 /**
111 * Attempt to load a custom bbPress functions file, similar to each themes
112 * functions.php file.
113 *
114 * @since bbPress (r3732)
115 *
116 * @global string $pagenow
117 * @uses bbp_locate_template()
118 */
119 function bbp_load_theme_functions() {
120 global $pagenow;
121
122 if ( ! defined( 'WP_INSTALLING' ) || ( !empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
123 bbp_locate_template( 'bbpress-functions.php', true );
124 }
125 }
126
127 /** Individual Templates ******************************************************/
128
129 /**
130 * Get the user profile template
131 *
132 * @since bbPress (r3311)
133 *
134 * @uses bbp_get_displayed_user_id()
135 * @uses bbp_get_query_template()
136 * @return string Path to template file
137 */
138 function bbp_get_single_user_template() {
139 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
140 $user_id = bbp_get_displayed_user_id();
141 $templates = array(
142 'single-user-' . $nicename . '.php', // Single User nicename
143 'single-user-' . $user_id . '.php', // Single User ID
144 'single-user.php', // Single User
145 'user.php', // User
146 );
147 return bbp_get_query_template( 'profile', $templates );
148 }
149
150 /**
151 * Get the user profile edit template
152 *
153 * @since bbPress (r3311)
154 *
155 * @uses bbp_get_displayed_user_id()
156 * @uses bbp_get_query_template()
157 * @return string Path to template file
158 */
159 function bbp_get_single_user_edit_template() {
160 $nicename = bbp_get_displayed_user_field( 'user_nicename' );
161 $user_id = bbp_get_displayed_user_id();
162 $templates = array(
163 'single-user-edit-' . $nicename . '.php', // Single User Edt nicename
164 'single-user-edit-' . $user_id . '.php', // Single User Edit ID
165 'single-user-edit.php', // Single User Edit
166 'user-edit.php', // User Edit
167 'user.php', // User
168 );
169 return bbp_get_query_template( 'profile_edit', $templates );
170 }
171
172 /**
173 * Get the view template
174 *
175 * @since bbPress (r3311)
176 *
177 * @uses bbp_get_view_id()
178 * @uses bbp_get_query_template()
179 * @return string Path to template file
180 */
181 function bbp_get_single_view_template() {
182 $view_id = bbp_get_view_id();
183 $templates = array(
184 'single-view-' . $view_id . '.php', // Single View ID
185 'view-' . $view_id . '.php', // View ID
186 'single-view.php', // Single View
187 'view.php', // View
188 );
189 return bbp_get_query_template( 'single_view', $templates );
190 }
191
192 /**
193 * Get the single forum template
194 *
195 * @since bbPress (r3922)
196 *
197 * @uses bbp_get_forum_post_type()
198 * @uses bbp_get_query_template()
199 * @return string Path to template file
200 */
201 function bbp_get_single_forum_template() {
202 $templates = array(
203 'single-' . bbp_get_forum_post_type() . '.php' // Single Forum
204 );
205 return bbp_get_query_template( 'single_forum', $templates );
206 }
207
208 /**
209 * Get the forum archive template
210 *
211 * @since bbPress (r3922)
212 *
213 * @uses bbp_get_forum_post_type()
214 * @uses bbp_get_query_template()
215 * @return string Path to template file
216 */
217 function bbp_get_forum_archive_template() {
218 $templates = array(
219 'archive-' . bbp_get_forum_post_type() . '.php' // Forum Archive
220 );
221 return bbp_get_query_template( 'forum_archive', $templates );
222 }
223
224 /**
225 * Get the forum edit template
226 *
227 * @since bbPress (r3566)
228 *
229 * @uses bbp_get_topic_post_type()
230 * @uses bbp_get_query_template()
231 * @return string Path to template file
232 */
233 function bbp_get_forum_edit_template() {
234 $post_type = bbp_get_forum_post_type();
235 $templates = array(
236 'single-' . $post_type . '-edit.php', // Single Forum Edit
237 'single-' . $post_type . '.php', // Single Forum
238 );
239 return bbp_get_query_template( 'forum_edit', $templates );
240 }
241
242 /**
243 * Get the single topic template
244 *
245 * @since bbPress (r3922)
246 *
247 * @uses bbp_get_topic_post_type()
248 * @uses bbp_get_query_template()
249 * @return string Path to template file
250 */
251 function bbp_get_single_topic_template() {
252 $templates = array(
253 'single-' . bbp_get_topic_post_type() . '.php'
254 );
255 return bbp_get_query_template( 'single_topic', $templates );
256 }
257
258 /**
259 * Get the topic archive template
260 *
261 * @since bbPress (r3922)
262 *
263 * @uses bbp_get_topic_post_type()
264 * @uses bbp_get_query_template()
265 * @return string Path to template file
266 */
267 function bbp_get_topic_archive_template() {
268 $templates = array(
269 'archive-' . bbp_get_topic_post_type() . '.php' // Topic Archive
270 );
271 return bbp_get_query_template( 'topic_archive', $templates );
272 }
273
274 /**
275 * Get the topic edit template
276 *
277 * @since bbPress (r3311)
278 *
279 * @uses bbp_get_topic_post_type()
280 * @uses bbp_get_query_template()
281 * @return string Path to template file
282 */
283 function bbp_get_topic_edit_template() {
284 $post_type = bbp_get_topic_post_type();
285 $templates = array(
286 'single-' . $post_type . '-edit.php', // Single Topic Edit
287 'single-' . $post_type . '.php', // Single Topic
288 );
289 return bbp_get_query_template( 'topic_edit', $templates );
290 }
291
292 /**
293 * Get the topic split template
294 *
295 * @since bbPress (r3311)
296 *
297 * @uses bbp_get_topic_post_type()
298 * @uses bbp_get_query_template()
299 * @return string Path to template file
300 */
301 function bbp_get_topic_split_template() {
302 $post_type = bbp_get_topic_post_type();
303 $templates = array(
304 'single-' . $post_type . '-split.php', // Topic Split
305 );
306 return bbp_get_query_template( 'topic_split', $templates );
307 }
308
309 /**
310 * Get the topic merge template
311 *
312 * @since bbPress (r3311)
313 *
314 * @uses bbp_get_topic_post_type()
315 * @uses bbp_get_query_template()
316 * @return string Path to template file
317 */
318 function bbp_get_topic_merge_template() {
319 $post_type = bbp_get_topic_post_type();
320 $templates = array(
321 'single-' . $post_type . '-merge.php', // Topic Merge
322 );
323 return bbp_get_query_template( 'topic_merge', $templates );
324 }
325
326 /**
327 * Get the single reply template
328 *
329 * @since bbPress (r3922)
330 *
331 * @uses bbp_get_reply_post_type()
332 * @uses bbp_get_query_template()
333 * @return string Path to template file
334 */
335 function bbp_get_single_reply_template() {
336 $templates = array(
337 'single-' . bbp_get_reply_post_type() . '.php'
338 );
339 return bbp_get_query_template( 'single_reply', $templates );
340 }
341
342 /**
343 * Get the reply edit template
344 *
345 * @since bbPress (r3311)
346 *
347 * @uses bbp_get_reply_post_type()
348 * @uses bbp_get_query_template()
349 * @return string Path to template file
350 */
351 function bbp_get_reply_edit_template() {
352 $post_type = bbp_get_reply_post_type();
353 $templates = array(
354 'single-' . $post_type . '-edit.php', // Single Reply Edit
355 'single-' . $post_type . '.php', // Single Reply
356 );
357 return bbp_get_query_template( 'reply_edit', $templates );
358 }
359
360 /**
361 * Get the topic template
362 *
363 * @since bbPress (r3311)
364 *
365 * @uses bbp_get_topic_tag_tax_id()
366 * @uses bbp_get_query_template()
367 * @return string Path to template file
368 */
369 function bbp_get_topic_tag_template() {
370 $tt_slug = bbp_get_topic_tag_slug();
371 $tt_id = bbp_get_topic_tag_tax_id();
372 $templates = array(
373 'taxonomy-' . $tt_slug . '.php', // Single Topic Tag slug
374 'taxonomy-' . $tt_id . '.php', // Single Topic Tag ID
375 );
376 return bbp_get_query_template( 'topic_tag', $templates );
377 }
378
379 /**
380 * Get the topic edit template
381 *
382 * @since bbPress (r3311)
383 *
384 * @uses bbp_get_topic_tag_tax_id()
385 * @uses bbp_get_query_template()
386 * @return string Path to template file
387 */
388 function bbp_get_topic_tag_edit_template() {
389 $tt_slug = bbp_get_topic_tag_slug();
390 $tt_id = bbp_get_topic_tag_tax_id();
391 $templates = array(
392 'taxonomy-' . $tt_slug . '-edit.php', // Single Topic Tag Edit slug
393 'taxonomy-' . $tt_id . '-edit.php', // Single Topic Tag Edit ID
394 'taxonomy-' . $tt_slug . '.php', // Single Topic Tag slug
395 'taxonomy-' . $tt_id . '.php', // Single Topic Tag ID
396 );
397 return bbp_get_query_template( 'topic_tag_edit', $templates );
398 }
399
400 /**
401 * Get the templates to use as the endpoint for bbPress template parts
402 *
403 * @since bbPress (r3311)
404 *
405 * @uses apply_filters()
406 * @uses bbp_set_theme_compat_templates()
407 * @uses bbp_get_query_template()
408 * @return string Path to template file
409 */
410 function bbp_get_theme_compat_templates() {
411 $templates = array(
412 'plugin-bbpress.php',
413 'bbpress.php',
414 'forums.php',
415 'forum.php',
416 'generic.php',
417 'page.php',
418 'single.php',
419 'index.php'
420 );
421 return bbp_get_query_template( 'bbpress', $templates );
422 }
423