PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/bbpress/includes/core/template-loader.php

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