PageRenderTime 63ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/bbpress/includes/common/template-tags.php

https://github.com/bfay/maniacal-kitten
PHP | 2581 lines | 981 code | 480 blank | 1120 comment | 244 complexity | d845eb1757e3406416cef352542ad724 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 Common Template Tags
  4. *
  5. * Common template tags are ones that are used by more than one component, like
  6. * forums, topics, replies, users, topic tags, etc...
  7. *
  8. * @package bbPress
  9. * @subpackage TemplateTags
  10. */
  11. // Exit if accessed directly
  12. if ( !defined( 'ABSPATH' ) ) exit;
  13. /** URLs **********************************************************************/
  14. /**
  15. * Ouput the forum URL
  16. *
  17. * @since bbPress (r3979)
  18. *
  19. * @uses bbp_get_forums_url() To get the forums URL
  20. * @param string $path Additional path with leading slash
  21. */
  22. function bbp_forums_url( $path = '/' ) {
  23. echo bbp_get_forums_url( $path );
  24. }
  25. /**
  26. * Return the forum URL
  27. *
  28. * @since bbPress (r3979)
  29. *
  30. * @uses home_url() To get the home URL
  31. * @uses bbp_get_root_slug() To get the forum root location
  32. * @param string $path Additional path with leading slash
  33. */
  34. function bbp_get_forums_url( $path = '/' ) {
  35. return home_url( bbp_get_root_slug() . $path );
  36. }
  37. /**
  38. * Ouput the forum URL
  39. *
  40. * @since bbPress (r3979)
  41. *
  42. * @uses bbp_get_topics_url() To get the topics URL
  43. * @param string $path Additional path with leading slash
  44. */
  45. function bbp_topics_url( $path = '/' ) {
  46. echo bbp_get_topics_url( $path );
  47. }
  48. /**
  49. * Return the forum URL
  50. *
  51. * @since bbPress (r3979)
  52. *
  53. * @uses home_url() To get the home URL
  54. * @uses bbp_get_topic_archive_slug() To get the topics archive location
  55. * @param string $path Additional path with leading slash
  56. * @return The URL to the topics archive
  57. */
  58. function bbp_get_topics_url( $path = '/' ) {
  59. return home_url( bbp_get_topic_archive_slug() . $path );
  60. }
  61. /** Add-on Actions ************************************************************/
  62. /**
  63. * Add our custom head action to wp_head
  64. *
  65. * @since bbPress (r2464)
  66. *
  67. * @uses do_action() Calls 'bbp_head'
  68. */
  69. function bbp_head() {
  70. do_action( 'bbp_head' );
  71. }
  72. /**
  73. * Add our custom head action to wp_head
  74. *
  75. * @since bbPress (r2464)
  76. *
  77. * @uses do_action() Calls 'bbp_footer'
  78. */
  79. function bbp_footer() {
  80. do_action( 'bbp_footer' );
  81. }
  82. /** is_ ***********************************************************************/
  83. /**
  84. * Check if current site is public
  85. *
  86. * @since bbPress (r3398)
  87. *
  88. * @param int $site_id
  89. * @uses get_current_blog_id()
  90. * @uses get_blog_option()
  91. * @uses apply_filters()
  92. * @return bool True if site is public, false if private
  93. */
  94. function bbp_is_site_public( $site_id = 0 ) {
  95. // Get the current site ID
  96. if ( empty( $site_id ) )
  97. $site_id = get_current_blog_id();
  98. // Get the site visibility setting
  99. $public = get_blog_option( $site_id, 'blog_public', 1 );
  100. return (bool) apply_filters( 'bbp_is_site_public', $public, $site_id );
  101. }
  102. /**
  103. * Check if current page is a bbPress forum
  104. *
  105. * @since bbPress (r2549)
  106. *
  107. * @param int $post_id Possible post_id to check
  108. * @uses bbp_get_forum_post_type() To get the forum post type
  109. * @return bool True if it's a forum page, false if not
  110. */
  111. function bbp_is_forum( $post_id = 0 ) {
  112. // Assume false
  113. $retval = false;
  114. // Supplied ID is a forum
  115. if ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_type( $post_id ) ))
  116. $retval = true;
  117. return (bool) apply_filters( 'bbp_is_forum', $retval, $post_id );
  118. }
  119. /**
  120. * Check if we are viewing a forum archive.
  121. *
  122. * @since bbPress (r3251)
  123. *
  124. * @uses is_post_type_archive() To check if we are looking at the forum archive
  125. * @uses bbp_get_forum_post_type() To get the forum post type ID
  126. *
  127. * @return bool
  128. */
  129. function bbp_is_forum_archive() {
  130. // Default to false
  131. $retval = false;
  132. // In forum archive
  133. if ( is_post_type_archive( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_forum_archive' ) )
  134. $retval = true;
  135. return (bool) apply_filters( 'bbp_is_forum_archive', $retval );
  136. }
  137. /**
  138. * Viewing a single forum
  139. *
  140. * @since bbPress (r3338)
  141. *
  142. * @uses is_single()
  143. * @uses bbp_get_forum_post_type()
  144. * @uses get_post_type()
  145. * @uses apply_filters()
  146. *
  147. * @return bool
  148. */
  149. function bbp_is_single_forum() {
  150. // Assume false
  151. $retval = false;
  152. // Edit is not a single forum
  153. if ( bbp_is_forum_edit() )
  154. return false;
  155. // Single and a match
  156. if ( is_singular( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_single_forum' ) )
  157. $retval = true;
  158. return (bool) apply_filters( 'bbp_is_single_forum', $retval );
  159. }
  160. /**
  161. * Check if current page is a forum edit page
  162. *
  163. * @since bbPress (r3553)
  164. *
  165. * @uses WP_Query Checks if WP_Query::bbp_is_forum_edit is true
  166. * @return bool True if it's the forum edit page, false if not
  167. */
  168. function bbp_is_forum_edit() {
  169. global $wp_query, $pagenow;
  170. // Assume false
  171. $retval = false;
  172. // Check query
  173. if ( !empty( $wp_query->bbp_is_forum_edit ) && ( $wp_query->bbp_is_forum_edit == true ) )
  174. $retval = true;
  175. // Editing in admin
  176. elseif ( is_admin() && ( 'post.php' == $pagenow ) && ( get_post_type() == bbp_get_forum_post_type() ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  177. $retval = true;
  178. return (bool) apply_filters( 'bbp_is_forum_edit', $retval );
  179. }
  180. /**
  181. * Check if current page is a bbPress topic
  182. *
  183. * @since bbPress (r2549)
  184. *
  185. * @param int $post_id Possible post_id to check
  186. * @uses bbp_get_topic_post_type() To get the topic post type
  187. * @uses get_post_type() To get the post type of the post id
  188. * @return bool True if it's a topic page, false if not
  189. */
  190. function bbp_is_topic( $post_id = 0 ) {
  191. // Assume false
  192. $retval = false;
  193. // Supplied ID is a topic
  194. if ( !empty( $post_id ) && ( bbp_get_topic_post_type() == get_post_type( $post_id ) ) )
  195. $retval = true;
  196. return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id );
  197. }
  198. /**
  199. * Viewing a single topic
  200. *
  201. * @since bbPress (r3338)
  202. *
  203. * @uses is_single()
  204. * @uses bbp_get_topic_post_type()
  205. * @uses get_post_type()
  206. * @uses apply_filters()
  207. *
  208. * @return bool
  209. */
  210. function bbp_is_single_topic() {
  211. // Assume false
  212. $retval = false;
  213. // Edit is not a single topic
  214. if ( bbp_is_topic_edit() )
  215. return false;
  216. // Single and a match
  217. if ( is_singular( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_single_topic' ) )
  218. $retval = true;
  219. return (bool) apply_filters( 'bbp_is_single_topic', $retval );
  220. }
  221. /**
  222. * Check if we are viewing a topic archive.
  223. *
  224. * @since bbPress (r3251)
  225. *
  226. * @uses is_post_type_archive() To check if we are looking at the topic archive
  227. * @uses bbp_get_topic_post_type() To get the topic post type ID
  228. *
  229. * @return bool
  230. */
  231. function bbp_is_topic_archive() {
  232. // Default to false
  233. $retval = false;
  234. // In topic archive
  235. if ( is_post_type_archive( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_topic_archive' ) )
  236. $retval = true;
  237. return (bool) apply_filters( 'bbp_is_topic_archive', $retval );
  238. }
  239. /**
  240. * Check if current page is a topic edit page
  241. *
  242. * @since bbPress (r2753)
  243. *
  244. * @uses WP_Query Checks if WP_Query::bbp_is_topic_edit is true
  245. * @return bool True if it's the topic edit page, false if not
  246. */
  247. function bbp_is_topic_edit() {
  248. global $wp_query, $pagenow;
  249. // Assume false
  250. $retval = false;
  251. // Check query
  252. if ( !empty( $wp_query->bbp_is_topic_edit ) && ( $wp_query->bbp_is_topic_edit == true ) )
  253. $retval = true;
  254. // Editing in admin
  255. elseif ( is_admin() && ( 'post.php' == $pagenow ) && ( get_post_type() == bbp_get_topic_post_type() ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  256. $retval = true;
  257. return (bool) apply_filters( 'bbp_is_topic_edit', $retval );
  258. }
  259. /**
  260. * Check if current page is a topic merge page
  261. *
  262. * @since bbPress (r2756)
  263. *
  264. * @uses bbp_is_topic_edit() To check if it's a topic edit page
  265. * @return bool True if it's the topic merge page, false if not
  266. */
  267. function bbp_is_topic_merge() {
  268. // Assume false
  269. $retval = false;
  270. // Check topic edit and GET params
  271. if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) )
  272. return true;
  273. return (bool) apply_filters( 'bbp_is_topic_merge', $retval );
  274. }
  275. /**
  276. * Check if current page is a topic split page
  277. *
  278. * @since bbPress (r2756)
  279. *
  280. * @uses bbp_is_topic_edit() To check if it's a topic edit page
  281. * @return bool True if it's the topic split page, false if not
  282. */
  283. function bbp_is_topic_split() {
  284. // Assume false
  285. $retval = false;
  286. // Check topic edit and GET params
  287. if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) )
  288. $retval = true;
  289. return (bool) apply_filters( 'bbp_is_topic_split', $retval );
  290. }
  291. /**
  292. * Check if the current page is a topic tag
  293. *
  294. * @since bbPress (r3311)
  295. *
  296. * @return bool True if it's a topic tag, false if not
  297. */
  298. function bbp_is_topic_tag() {
  299. // Bail if topic-tags are off
  300. if ( ! bbp_allow_topic_tags() )
  301. return false;
  302. // Return false if editing a topic tag
  303. if ( bbp_is_topic_tag_edit() )
  304. return false;
  305. // Assume false
  306. $retval = false;
  307. // Check tax and query vars
  308. if ( is_tax( bbp_get_topic_tag_tax_id() ) || !empty( bbpress()->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) )
  309. $retval = true;
  310. return (bool) apply_filters( 'bbp_is_topic_tag', $retval );
  311. }
  312. /**
  313. * Check if the current page is editing a topic tag
  314. *
  315. * @since bbPress (r3346)
  316. *
  317. * @uses WP_Query Checks if WP_Query::bbp_is_topic_tag_edit is true
  318. * @return bool True if editing a topic tag, false if not
  319. */
  320. function bbp_is_topic_tag_edit() {
  321. global $wp_query, $pagenow, $taxnow;
  322. // Bail if topic-tags are off
  323. if ( ! bbp_allow_topic_tags() )
  324. return false;
  325. // Assume false
  326. $retval = false;
  327. // Check query
  328. if ( !empty( $wp_query->bbp_is_topic_tag_edit ) && ( true == $wp_query->bbp_is_topic_tag_edit ) )
  329. $retval = true;
  330. // Editing in admin
  331. elseif ( is_admin() && ( 'edit-tags.php' == $pagenow ) && ( bbp_get_topic_tag_tax_id() == $taxnow ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  332. $retval = true;
  333. return (bool) apply_filters( 'bbp_is_topic_tag_edit', $retval );
  334. }
  335. /**
  336. * Check if the current post type is one of bbPress's
  337. *
  338. * @since bbPress (r3311)
  339. *
  340. * @param mixed $the_post Optional. Post object or post ID.
  341. * @uses get_post_type()
  342. * @uses bbp_get_forum_post_type()
  343. * @uses bbp_get_topic_post_type()
  344. * @uses bbp_get_reply_post_type()
  345. *
  346. * @return bool
  347. */
  348. function bbp_is_custom_post_type( $the_post = false ) {
  349. // Assume false
  350. $retval = false;
  351. // Viewing one of the bbPress post types
  352. if ( in_array( get_post_type( $the_post ), array(
  353. bbp_get_forum_post_type(),
  354. bbp_get_topic_post_type(),
  355. bbp_get_reply_post_type()
  356. ) ) )
  357. $retval = true;
  358. return (bool) apply_filters( 'bbp_is_custom_post_type', $retval, $the_post );
  359. }
  360. /**
  361. * Check if current page is a bbPress reply
  362. *
  363. * @since bbPress (r2549)
  364. *
  365. * @param int $post_id Possible post_id to check
  366. * @uses bbp_get_reply_post_type() To get the reply post type
  367. * @uses get_post_type() To get the post type of the post id
  368. * @return bool True if it's a reply page, false if not
  369. */
  370. function bbp_is_reply( $post_id = 0 ) {
  371. // Assume false
  372. $retval = false;
  373. // Supplied ID is a reply
  374. if ( !empty( $post_id ) && ( bbp_get_reply_post_type() == get_post_type( $post_id ) ) )
  375. $retval = true;
  376. return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id );
  377. }
  378. /**
  379. * Check if current page is a reply edit page
  380. *
  381. * @since bbPress (r2753)
  382. *
  383. * @uses WP_Query Checks if WP_Query::bbp_is_reply_edit is true
  384. * @return bool True if it's the reply edit page, false if not
  385. */
  386. function bbp_is_reply_edit() {
  387. global $wp_query, $pagenow;
  388. // Assume false
  389. $retval = false;
  390. // Check query
  391. if ( !empty( $wp_query->bbp_is_reply_edit ) && ( true == $wp_query->bbp_is_reply_edit ) )
  392. $retval = true;
  393. // Editing in admin
  394. elseif ( is_admin() && ( 'post.php' == $pagenow ) && ( get_post_type() == bbp_get_reply_post_type() ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  395. $retval = true;
  396. return (bool) apply_filters( 'bbp_is_reply_edit', $retval );
  397. }
  398. /**
  399. * Check if current page is a reply move page
  400. *
  401. * @uses bbp_is_reply_move() To check if it's a reply move page
  402. * @return bool True if it's the reply move page, false if not
  403. */
  404. function bbp_is_reply_move() {
  405. // Assume false
  406. $retval = false;
  407. // Check reply edit and GET params
  408. if ( bbp_is_reply_edit() && !empty( $_GET['action'] ) && ( 'move' == $_GET['action'] ) )
  409. $retval = true;
  410. return (bool) apply_filters( 'bbp_is_reply_move', $retval );
  411. }
  412. /**
  413. * Viewing a single reply
  414. *
  415. * @since bbPress (r3344)
  416. *
  417. * @uses is_single()
  418. * @uses bbp_get_reply_post_type()
  419. * @uses get_post_type()
  420. * @uses apply_filters()
  421. *
  422. * @return bool
  423. */
  424. function bbp_is_single_reply() {
  425. // Assume false
  426. $retval = false;
  427. // Edit is not a single reply
  428. if ( bbp_is_reply_edit() )
  429. return false;
  430. // Single and a match
  431. if ( is_singular( bbp_get_reply_post_type() ) || ( bbp_is_query_name( 'bbp_single_reply' ) ) )
  432. $retval = true;
  433. return (bool) apply_filters( 'bbp_is_single_reply', $retval );
  434. }
  435. /**
  436. * Check if current page is a bbPress user's favorites page (profile page)
  437. *
  438. * @since bbPress (r2652)
  439. *
  440. * @return bool True if it's the favorites page, false if not
  441. */
  442. function bbp_is_favorites() {
  443. global $wp_query;
  444. // Assume false
  445. $retval = false;
  446. // Check query
  447. if ( !empty( $wp_query->bbp_is_single_user_favs ) && ( true == $wp_query->bbp_is_single_user_favs ) )
  448. $retval = true;
  449. return (bool) apply_filters( 'bbp_is_favorites', $retval );
  450. }
  451. /**
  452. * Check if current page is a bbPress user's subscriptions page (profile page)
  453. *
  454. * @since bbPress (r2652)
  455. *
  456. * @return bool True if it's the subscriptions page, false if not
  457. */
  458. function bbp_is_subscriptions() {
  459. global $wp_query;
  460. // Assume false
  461. $retval = false;
  462. // Check query
  463. if ( !empty( $wp_query->bbp_is_single_user_subs ) && ( true == $wp_query->bbp_is_single_user_subs ) )
  464. $retval = true;
  465. return (bool) apply_filters( 'bbp_is_subscriptions', $retval );
  466. }
  467. /**
  468. * Check if current page shows the topics created by a bbPress user (profile
  469. * page)
  470. *
  471. * @since bbPress (r2688)
  472. *
  473. * @return bool True if it's the topics created page, false if not
  474. */
  475. function bbp_is_topics_created() {
  476. global $wp_query;
  477. // Assume false
  478. $retval = false;
  479. // Check query
  480. if ( !empty( $wp_query->bbp_is_single_user_topics ) && ( true == $wp_query->bbp_is_single_user_topics ) )
  481. $retval = true;
  482. return (bool) apply_filters( 'bbp_is_topics_created', $retval );
  483. }
  484. /**
  485. * Check if current page shows the topics created by a bbPress user (profile
  486. * page)
  487. *
  488. * @since bbPress (r4225)
  489. *
  490. * @return bool True if it's the topics created page, false if not
  491. */
  492. function bbp_is_replies_created() {
  493. global $wp_query;
  494. // Assume false
  495. $retval = false;
  496. // Check query
  497. if ( !empty( $wp_query->bbp_is_single_user_replies ) && ( true == $wp_query->bbp_is_single_user_replies ) )
  498. $retval = true;
  499. return (bool) apply_filters( 'bbp_is_replies_created', $retval );
  500. }
  501. /**
  502. * Check if current page is the currently logged in users author page
  503. *
  504. * @since bbPress (r2688)
  505. * @uses bbp_is_single_user() Check query variable
  506. * @uses is_user_logged_in() Must be logged in to be home
  507. * @uses bbp_get_displayed_user_id()
  508. * @uses bbp_get_current_user_id()
  509. * @return bool True if it's the user's home, false if not
  510. */
  511. function bbp_is_user_home() {
  512. global $wp_query;
  513. // Assume false
  514. $retval = false;
  515. // Check query
  516. if ( !empty( $wp_query->bbp_is_single_user_home ) && ( true == $wp_query->bbp_is_single_user_home ) )
  517. $retval = true;
  518. return (bool) apply_filters( 'bbp_is_user_home', $retval );
  519. }
  520. /**
  521. * Check if current page is the currently logged in users author edit page
  522. *
  523. * @since bbPress (r3918)
  524. * @uses bbp_is_single_user_edit() Check query variable
  525. * @uses is_user_logged_in() Must be logged in to be home
  526. * @uses bbp_get_displayed_user_id()
  527. * @uses bbp_get_current_user_id()
  528. * @return bool True if it's the user's home, false if not
  529. */
  530. function bbp_is_user_home_edit() {
  531. // Assume false
  532. $retval = false;
  533. if ( bbp_is_user_home() && bbp_is_single_user_edit() )
  534. $retval = true;
  535. return (bool) apply_filters( 'bbp_is_user_home_edit', $retval );
  536. }
  537. /**
  538. * Check if current page is a user profile page
  539. *
  540. * @since bbPress (r2688)
  541. *
  542. * @uses WP_Query Checks if WP_Query::bbp_is_single_user is set to true
  543. * @return bool True if it's a user's profile page, false if not
  544. */
  545. function bbp_is_single_user() {
  546. global $wp_query;
  547. // Assume false
  548. $retval = false;
  549. // Check query
  550. if ( !empty( $wp_query->bbp_is_single_user ) && ( true == $wp_query->bbp_is_single_user ) )
  551. $retval = true;
  552. return (bool) apply_filters( 'bbp_is_single_user', $retval );
  553. }
  554. /**
  555. * Check if current page is a user profile edit page
  556. *
  557. * @since bbPress (r2688)
  558. *
  559. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_edit is set to true
  560. * @return bool True if it's a user's profile edit page, false if not
  561. */
  562. function bbp_is_single_user_edit() {
  563. global $wp_query;
  564. // Assume false
  565. $retval = false;
  566. // Check query
  567. if ( !empty( $wp_query->bbp_is_single_user_edit ) && ( true == $wp_query->bbp_is_single_user_edit ) )
  568. $retval = true;
  569. return (bool) apply_filters( 'bbp_is_single_user_edit', $retval );
  570. }
  571. /**
  572. * Check if current page is a user profile page
  573. *
  574. * @since bbPress (r4225)
  575. *
  576. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_profile is set to true
  577. * @return bool True if it's a user's profile page, false if not
  578. */
  579. function bbp_is_single_user_profile() {
  580. global $wp_query;
  581. // Assume false
  582. $retval = false;
  583. // Check query
  584. if ( !empty( $wp_query->bbp_is_single_user_profile ) && ( true == $wp_query->bbp_is_single_user_profile ) )
  585. $retval = true;
  586. return (bool) apply_filters( 'bbp_is_single_user_profile', $retval );
  587. }
  588. /**
  589. * Check if current page is a user topics created page
  590. *
  591. * @since bbPress (r4225)
  592. *
  593. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_topics is set to true
  594. * @return bool True if it's a user's topics page, false if not
  595. */
  596. function bbp_is_single_user_topics() {
  597. global $wp_query;
  598. // Assume false
  599. $retval = false;
  600. // Check query
  601. if ( !empty( $wp_query->bbp_is_single_user_topics ) && ( true == $wp_query->bbp_is_single_user_topics ) )
  602. $retval = true;
  603. return (bool) apply_filters( 'bbp_is_single_user_topics', $retval );
  604. }
  605. /**
  606. * Check if current page is a user replies created page
  607. *
  608. * @since bbPress (r4225)
  609. *
  610. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_replies is set to true
  611. * @return bool True if it's a user's replies page, false if not
  612. */
  613. function bbp_is_single_user_replies() {
  614. global $wp_query;
  615. // Assume false
  616. $retval = false;
  617. // Check query
  618. if ( !empty( $wp_query->bbp_is_single_user_replies ) && ( true == $wp_query->bbp_is_single_user_replies ) )
  619. $retval = true;
  620. return (bool) apply_filters( 'bbp_is_single_user_replies', $retval );
  621. }
  622. /**
  623. * Check if current page is a view page
  624. *
  625. * @since bbPress (r2789)
  626. *
  627. * @global WP_Query $wp_query To check if WP_Query::bbp_is_view is true
  628. * @uses bbp_is_query_name() To get the query name
  629. * @return bool Is it a view page?
  630. */
  631. function bbp_is_single_view() {
  632. global $wp_query;
  633. // Assume false
  634. $retval = false;
  635. // Check query
  636. if ( !empty( $wp_query->bbp_is_view ) && ( true == $wp_query->bbp_is_view ) )
  637. $retval = true;
  638. // Check query name
  639. if ( empty( $retval ) && bbp_is_query_name( 'bbp_single_view' ) )
  640. $retval = true;
  641. return (bool) apply_filters( 'bbp_is_single_view', $retval );
  642. }
  643. /**
  644. * Check if current page is a search page
  645. *
  646. * @since bbPress (r4579)
  647. *
  648. * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true
  649. * @uses bbp_is_query_name() To get the query name
  650. * @return bool Is it a search page?
  651. */
  652. function bbp_is_search() {
  653. global $wp_query;
  654. // Assume false
  655. $retval = false;
  656. // Check query
  657. if ( !empty( $wp_query->bbp_is_search ) && ( true == $wp_query->bbp_is_search ) )
  658. $retval = true;
  659. // Check query name
  660. if ( empty( $retval ) && bbp_is_query_name( 'bbp_search' ) )
  661. $retval = true;
  662. // Check $_GET
  663. if ( empty( $retval ) && isset( $_GET[bbp_get_search_rewrite_id()] ) )
  664. $retval = true;
  665. return (bool) apply_filters( 'bbp_is_search', $retval );
  666. }
  667. /**
  668. * Check if current page is an edit page
  669. *
  670. * @since bbPress (r3585)
  671. *
  672. * @uses WP_Query Checks if WP_Query::bbp_is_edit is true
  673. * @return bool True if it's the edit page, false if not
  674. */
  675. function bbp_is_edit() {
  676. global $wp_query;
  677. // Assume false
  678. $retval = false;
  679. // Check query
  680. if ( !empty( $wp_query->bbp_is_edit ) && ( $wp_query->bbp_is_edit == true ) )
  681. $retval = true;
  682. return (bool) apply_filters( 'bbp_is_edit', $retval );
  683. }
  684. /**
  685. * Use the above is_() functions to output a body class for each scenario
  686. *
  687. * @since bbPress (r2926)
  688. *
  689. * @param array $wp_classes
  690. * @param array $custom_classes
  691. * @uses bbp_is_single_forum()
  692. * @uses bbp_is_single_topic()
  693. * @uses bbp_is_topic_edit()
  694. * @uses bbp_is_topic_merge()
  695. * @uses bbp_is_topic_split()
  696. * @uses bbp_is_single_reply()
  697. * @uses bbp_is_reply_edit()
  698. * @uses bbp_is_reply_move()
  699. * @uses bbp_is_single_view()
  700. * @uses bbp_is_single_user_edit()
  701. * @uses bbp_is_single_user()
  702. * @uses bbp_is_user_home()
  703. * @uses bbp_is_subscriptions()
  704. * @uses bbp_is_favorites()
  705. * @uses bbp_is_topics_created()
  706. * @uses bbp_is_forum_archive()
  707. * @uses bbp_is_topic_archive()
  708. * @uses bbp_is_topic_tag()
  709. * @uses bbp_is_topic_tag_edit()
  710. * @uses bbp_get_topic_tag_tax_id()
  711. * @uses bbp_get_topic_tag_slug()
  712. * @uses bbp_get_topic_tag_id()
  713. * @return array Body Classes
  714. */
  715. function bbp_body_class( $wp_classes, $custom_classes = false ) {
  716. $bbp_classes = array();
  717. /** Archives **************************************************************/
  718. if ( bbp_is_forum_archive() ) {
  719. $bbp_classes[] = bbp_get_forum_post_type() . '-archive';
  720. } elseif ( bbp_is_topic_archive() ) {
  721. $bbp_classes[] = bbp_get_topic_post_type() . '-archive';
  722. /** Topic Tags ************************************************************/
  723. } elseif ( bbp_is_topic_tag() ) {
  724. $bbp_classes[] = bbp_get_topic_tag_tax_id();
  725. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug();
  726. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id();
  727. } elseif ( bbp_is_topic_tag_edit() ) {
  728. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit';
  729. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit';
  730. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id() . '-edit';
  731. /** Components ************************************************************/
  732. } elseif ( bbp_is_single_forum() ) {
  733. $bbp_classes[] = bbp_get_forum_post_type();
  734. } elseif ( bbp_is_single_topic() ) {
  735. $bbp_classes[] = bbp_get_topic_post_type();
  736. } elseif ( bbp_is_single_reply() ) {
  737. $bbp_classes[] = bbp_get_reply_post_type();
  738. } elseif ( bbp_is_topic_edit() ) {
  739. $bbp_classes[] = bbp_get_topic_post_type() . '-edit';
  740. } elseif ( bbp_is_topic_merge() ) {
  741. $bbp_classes[] = bbp_get_topic_post_type() . '-merge';
  742. } elseif ( bbp_is_topic_split() ) {
  743. $bbp_classes[] = bbp_get_topic_post_type() . '-split';
  744. } elseif ( bbp_is_reply_edit() ) {
  745. $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
  746. } elseif ( bbp_is_reply_move() ) {
  747. $bbp_classes[] = bbp_get_reply_post_type() . '-move';
  748. } elseif ( bbp_is_single_view() ) {
  749. $bbp_classes[] = 'bbp-view';
  750. /** User ******************************************************************/
  751. } elseif ( bbp_is_single_user_edit() ) {
  752. $bbp_classes[] = 'bbp-user-edit';
  753. $bbp_classes[] = 'single';
  754. $bbp_classes[] = 'singular';
  755. } elseif ( bbp_is_single_user() ) {
  756. $bbp_classes[] = 'bbp-user-page';
  757. $bbp_classes[] = 'single';
  758. $bbp_classes[] = 'singular';
  759. } elseif ( bbp_is_user_home() ) {
  760. $bbp_classes[] = 'bbp-user-home';
  761. $bbp_classes[] = 'single';
  762. $bbp_classes[] = 'singular';
  763. } elseif ( bbp_is_user_home_edit() ) {
  764. $bbp_classes[] = 'bbp-user-home-edit';
  765. $bbp_classes[] = 'single';
  766. $bbp_classes[] = 'singular';
  767. } elseif ( bbp_is_topics_created() ) {
  768. $bbp_classes[] = 'bbp-topics-created';
  769. $bbp_classes[] = 'single';
  770. $bbp_classes[] = 'singular';
  771. } elseif ( bbp_is_favorites() ) {
  772. $bbp_classes[] = 'bbp-favorites';
  773. $bbp_classes[] = 'single';
  774. $bbp_classes[] = 'singular';
  775. } elseif ( bbp_is_subscriptions() ) {
  776. $bbp_classes[] = 'bbp-subscriptions';
  777. $bbp_classes[] = 'single';
  778. $bbp_classes[] = 'singular';
  779. /** Search ****************************************************************/
  780. } elseif ( bbp_is_search() ) {
  781. $bbp_classes[] = 'bbp-search';
  782. $bbp_classes[] = 'forum-search';
  783. }
  784. /** Clean up **************************************************************/
  785. // Add bbPress class if we are within a bbPress page
  786. if ( !empty( $bbp_classes ) ) {
  787. $bbp_classes[] = 'bbpress';
  788. }
  789. // Merge WP classes with bbPress classes and remove any duplicates
  790. $classes = array_unique( array_merge( (array) $bbp_classes, (array) $wp_classes ) );
  791. // Deprecated filter (do not use)
  792. $classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
  793. return apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
  794. }
  795. /**
  796. * Use the above is_() functions to return if in any bbPress page
  797. *
  798. * @since bbPress (r3344)
  799. *
  800. * @uses bbp_is_single_forum()
  801. * @uses bbp_is_single_topic()
  802. * @uses bbp_is_topic_edit()
  803. * @uses bbp_is_topic_merge()
  804. * @uses bbp_is_topic_split()
  805. * @uses bbp_is_single_reply()
  806. * @uses bbp_is_reply_edit()
  807. * @uses bbp_is_reply_move()
  808. * @uses bbp_is_single_view()
  809. * @uses bbp_is_single_user_edit()
  810. * @uses bbp_is_single_user()
  811. * @uses bbp_is_user_home()
  812. * @uses bbp_is_subscriptions()
  813. * @uses bbp_is_favorites()
  814. * @uses bbp_is_topics_created()
  815. * @return bool In a bbPress page
  816. */
  817. function is_bbpress() {
  818. // Defalt to false
  819. $retval = false;
  820. /** Archives **************************************************************/
  821. if ( bbp_is_forum_archive() ) {
  822. $retval = true;
  823. } elseif ( bbp_is_topic_archive() ) {
  824. $retval = true;
  825. /** Topic Tags ************************************************************/
  826. } elseif ( bbp_is_topic_tag() ) {
  827. $retval = true;
  828. } elseif ( bbp_is_topic_tag_edit() ) {
  829. $retval = true;
  830. /** Components ************************************************************/
  831. } elseif ( bbp_is_single_forum() ) {
  832. $retval = true;
  833. } elseif ( bbp_is_single_topic() ) {
  834. $retval = true;
  835. } elseif ( bbp_is_single_reply() ) {
  836. $retval = true;
  837. } elseif ( bbp_is_topic_edit() ) {
  838. $retval = true;
  839. } elseif ( bbp_is_topic_merge() ) {
  840. $retval = true;
  841. } elseif ( bbp_is_topic_split() ) {
  842. $retval = true;
  843. } elseif ( bbp_is_reply_edit() ) {
  844. $retval = true;
  845. } elseif ( bbp_is_reply_move() ) {
  846. $retval = true;
  847. } elseif ( bbp_is_single_view() ) {
  848. $retval = true;
  849. /** User ******************************************************************/
  850. } elseif ( bbp_is_single_user_edit() ) {
  851. $retval = true;
  852. } elseif ( bbp_is_single_user() ) {
  853. $retval = true;
  854. } elseif ( bbp_is_user_home() ) {
  855. $retval = true;
  856. } elseif ( bbp_is_user_home_edit() ) {
  857. $retval = true;
  858. } elseif ( bbp_is_topics_created() ) {
  859. $retval = true;
  860. } elseif ( bbp_is_favorites() ) {
  861. $retval = true;
  862. } elseif ( bbp_is_subscriptions() ) {
  863. $retval = true;
  864. /** Search ****************************************************************/
  865. } elseif ( bbp_is_search() ) {
  866. $retval = true;
  867. }
  868. /** Done ******************************************************************/
  869. return (bool) apply_filters( 'is_bbpress', $retval );
  870. }
  871. /** Forms *********************************************************************/
  872. /**
  873. * Output the login form action url
  874. *
  875. * @since bbPress (r2815)
  876. *
  877. * @param string $url Pass a URL to redirect to
  878. * @uses add_query_arg() To add a arg to the url
  879. * @uses site_url() Toget the site url
  880. * @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args
  881. */
  882. function bbp_wp_login_action( $args = '' ) {
  883. // Parse arguments against default values
  884. $r = bbp_parse_args( $args, array(
  885. 'action' => '',
  886. 'context' => ''
  887. ), 'login_action' );
  888. // Add action as query arg
  889. if ( !empty( $r['action'] ) ) {
  890. $login_url = add_query_arg( array( 'action' => $r['action'] ), 'wp-login.php' );
  891. // No query arg
  892. } else {
  893. $login_url = 'wp-login.php';
  894. }
  895. $login_url = site_url( $login_url, $r['context'] );
  896. echo apply_filters( 'bbp_wp_login_action', $login_url, $r );
  897. }
  898. /**
  899. * Output hidden request URI field for user forms.
  900. *
  901. * The referer link is the current Request URI from the server super global. To
  902. * check the field manually, use bbp_get_redirect_to().
  903. *
  904. * @since bbPress (r2815)
  905. *
  906. * @param string $redirect_to Pass a URL to redirect to
  907. *
  908. * @uses wp_get_referer() To get the referer
  909. * @uses esc_attr() To escape the url
  910. * @uses apply_filters() Calls 'bbp_redirect_to_field', passes field and to
  911. */
  912. function bbp_redirect_to_field( $redirect_to = '' ) {
  913. // Make sure we are directing somewhere
  914. if ( empty( $redirect_to ) ) {
  915. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  916. $redirect_to = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  917. } else {
  918. $redirect_to = wp_get_referer();
  919. }
  920. }
  921. // Remove loggedout query arg if it's there
  922. $redirect_to = (string) esc_attr( remove_query_arg( 'loggedout', $redirect_to ) );
  923. $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . $redirect_to . '" />';
  924. echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to );
  925. }
  926. /**
  927. * Echo sanitized $_REQUEST value.
  928. *
  929. * Use the $input_type parameter to properly process the value. This
  930. * ensures correct sanitization of the value for the receiving input.
  931. *
  932. * @since bbPress (r2815)
  933. *
  934. * @param string $request Name of $_REQUEST to look for
  935. * @param string $input_type Type of input. Default: text. Accepts:
  936. * textarea|password|select|radio|checkbox
  937. * @uses bbp_get_sanitize_val() To sanitize the value.
  938. */
  939. function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
  940. echo bbp_get_sanitize_val( $request, $input_type );
  941. }
  942. /**
  943. * Return sanitized $_REQUEST value.
  944. *
  945. * Use the $input_type parameter to properly process the value. This
  946. * ensures correct sanitization of the value for the receiving input.
  947. *
  948. * @since bbPress (r2815)
  949. *
  950. * @param string $request Name of $_REQUEST to look for
  951. * @param string $input_type Type of input. Default: text. Accepts:
  952. * textarea|password|select|radio|checkbox
  953. * @uses esc_attr() To escape the string
  954. * @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized
  955. * value, request and input type
  956. * @return string Sanitized value ready for screen display
  957. */
  958. function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
  959. // Check that requested
  960. if ( empty( $_REQUEST[$request] ) )
  961. return false;
  962. // Set request varaible
  963. $pre_ret_val = $_REQUEST[$request];
  964. // Treat different kinds of fields in different ways
  965. switch ( $input_type ) {
  966. case 'text' :
  967. case 'textarea' :
  968. $retval = esc_attr( stripslashes( $pre_ret_val ) );
  969. break;
  970. case 'password' :
  971. case 'select' :
  972. case 'radio' :
  973. case 'checkbox' :
  974. default :
  975. $retval = esc_attr( $pre_ret_val );
  976. break;
  977. }
  978. return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
  979. }
  980. /**
  981. * Output the current tab index of a given form
  982. *
  983. * Use this function to handle the tab indexing of user facing forms within a
  984. * template file. Calling this function will automatically increment the global
  985. * tab index by default.
  986. *
  987. * @since bbPress (r2810)
  988. *
  989. * @param int $auto_increment Optional. Default true. Set to false to prevent
  990. * increment
  991. */
  992. function bbp_tab_index( $auto_increment = true ) {
  993. echo bbp_get_tab_index( $auto_increment );
  994. }
  995. /**
  996. * Output the current tab index of a given form
  997. *
  998. * Use this function to handle the tab indexing of user facing forms
  999. * within a template file. Calling this function will automatically
  1000. * increment the global tab index by default.
  1001. *
  1002. * @since bbPress (r2810)
  1003. *
  1004. * @uses apply_filters Allows return value to be filtered
  1005. * @param int $auto_increment Optional. Default true. Set to false to
  1006. * prevent the increment
  1007. * @return int $bbp->tab_index The global tab index
  1008. */
  1009. function bbp_get_tab_index( $auto_increment = true ) {
  1010. $bbp = bbpress();
  1011. if ( true === $auto_increment )
  1012. ++$bbp->tab_index;
  1013. return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
  1014. }
  1015. /**
  1016. * Output a select box allowing to pick which forum/topic a new topic/reply
  1017. * belongs in.
  1018. *
  1019. * Can be used for any post type, but is mostly used for topics and forums.
  1020. *
  1021. * @since bbPress (r2746)
  1022. *
  1023. * @param mixed $args See {@link bbp_get_dropdown()} for arguments
  1024. */
  1025. function bbp_dropdown( $args = '' ) {
  1026. echo bbp_get_dropdown( $args );
  1027. }
  1028. /**
  1029. * Output a select box allowing to pick which forum/topic a new
  1030. * topic/reply belongs in.
  1031. *
  1032. * @since bbPress (r2746)
  1033. *
  1034. * @param mixed $args The function supports these args:
  1035. * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
  1036. * - selected: Selected ID, to not have any value as selected, pass
  1037. * anything smaller than 0 (due to the nature of select
  1038. * box, the first value would of course be selected -
  1039. * though you can have that as none (pass 'show_none' arg))
  1040. * - sort_column: Sort by? Defaults to 'menu_order, post_title'
  1041. * - post_parent: Post parent. Defaults to 0
  1042. * - post_status: Which all post_statuses to find in? Can be an array
  1043. * or CSV of publish, category, closed, private, spam,
  1044. * trash (based on post type) - if not set, these are
  1045. * automatically determined based on the post_type
  1046. * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
  1047. * all posts
  1048. * - walker: Which walker to use? Defaults to
  1049. * {@link BBP_Walker_Dropdown}
  1050. * - select_id: ID of the select box. Defaults to 'bbp_forum_id'
  1051. * - tab: Tabindex value. False or integer
  1052. * - options_only: Show only <options>? No <select>?
  1053. * - show_none: False or something like __( '(No Forum)', 'bbpress' ),
  1054. * will have value=""
  1055. * - none_found: False or something like
  1056. * __( 'No forums to post to!', 'bbpress' )
  1057. * - disable_categories: Disable forum categories and closed forums?
  1058. * Defaults to true. Only for forums and when
  1059. * the category option is displayed.
  1060. * @uses BBP_Walker_Dropdown() As the default walker to generate the
  1061. * dropdown
  1062. * @uses current_user_can() To check if the current user can read
  1063. * private forums
  1064. * @uses bbp_get_forum_post_type() To get the forum post type
  1065. * @uses bbp_get_topic_post_type() To get the topic post type
  1066. * @uses walk_page_dropdown_tree() To generate the dropdown using the
  1067. * walker
  1068. * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
  1069. * and args
  1070. * @return string The dropdown
  1071. */
  1072. function bbp_get_dropdown( $args = '' ) {
  1073. /** Arguments *********************************************************/
  1074. // Parse arguments against default values
  1075. $r = bbp_parse_args( $args, array(
  1076. 'post_type' => bbp_get_forum_post_type(),
  1077. 'selected' => 0,
  1078. 'sort_column' => 'menu_order',
  1079. 'exclude' => array(),
  1080. 'post_parent' => null,
  1081. 'numberposts' => -1,
  1082. 'orderby' => 'menu_order',
  1083. 'order' => 'ASC',
  1084. 'walker' => '',
  1085. // Output-related
  1086. 'select_id' => 'bbp_forum_id',
  1087. 'tab' => bbp_get_tab_index(),
  1088. 'options_only' => false,
  1089. 'show_none' => false,
  1090. 'none_found' => false,
  1091. 'disable_categories' => true,
  1092. 'disabled' => ''
  1093. ), 'get_dropdown' );
  1094. if ( empty( $r['walker'] ) ) {
  1095. $r['walker'] = new BBP_Walker_Dropdown();
  1096. $r['walker']->tree_type = $r['post_type'];
  1097. }
  1098. // Force 0
  1099. if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) {
  1100. $r['selected'] = 0;
  1101. }
  1102. // Force array
  1103. if ( !empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) {
  1104. $r['exclude'] = explode( ',', $r['exclude'] );
  1105. }
  1106. /** Post Status *******************************************************/
  1107. // Define local variable(s)
  1108. $post_stati = array();
  1109. // Public
  1110. $post_stati[] = bbp_get_public_status_id();
  1111. // Forums
  1112. if ( bbp_get_forum_post_type() == $r['post_type'] ) {
  1113. // Private forums
  1114. if ( current_user_can( 'read_private_forums' ) ) {
  1115. $post_stati[] = bbp_get_private_status_id();
  1116. }
  1117. // Hidden forums
  1118. if ( current_user_can( 'read_hidden_forums' ) ) {
  1119. $post_stati[] = bbp_get_hidden_status_id();
  1120. }
  1121. }
  1122. // Setup the post statuses
  1123. $r['post_status'] = implode( ',', $post_stati );
  1124. /** Setup variables ***************************************************/
  1125. $name = esc_attr( $r['select_id'] );
  1126. $select_id = $name;
  1127. $tab = (int) $r['tab'];
  1128. $retval = '';
  1129. $disabled = disabled( isset( bbpress()->options[$r['disabled']] ), true, false );
  1130. $post_arr = array(
  1131. 'post_type' => $r['post_type'],
  1132. 'post_status' => $r['post_status'],
  1133. 'sort_column' => $r['sort_column'],
  1134. 'exclude' => $r['exclude'],
  1135. 'post_parent' => $r['post_parent'],
  1136. 'numberposts' => $r['numberposts'],
  1137. 'orderby' => $r['orderby'],
  1138. 'order' => $r['order'],
  1139. 'walker' => $r['walker'],
  1140. 'disable_categories' => $r['disable_categories']
  1141. );
  1142. $posts = get_posts( $post_arr );
  1143. /** Drop Down *********************************************************/
  1144. // Items found
  1145. if ( !empty( $posts ) ) {
  1146. if ( empty( $r['options_only'] ) ) {
  1147. $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
  1148. $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . $disabled . '>' . "\n";
  1149. }
  1150. $retval .= !empty( $r['show_none'] ) ? "\t<option value=\"\" class=\"level-0\">" . $r['show_none'] . '</option>' : '';
  1151. $retval .= walk_page_dropdown_tree( $posts, 0, $r );
  1152. if ( empty( $r['options_only'] ) ) {
  1153. $retval .= '</select>';
  1154. }
  1155. // No items found - Display feedback if no custom message was passed
  1156. } elseif ( empty( $r['none_found'] ) ) {
  1157. // Switch the response based on post type
  1158. switch ( $r['post_type'] ) {
  1159. // Topics
  1160. case bbp_get_topic_post_type() :
  1161. $retval = __( 'No topics available', 'bbpress' );
  1162. break;
  1163. // Forums
  1164. case bbp_get_forum_post_type() :
  1165. $retval = __( 'No forums available', 'bbpress' );
  1166. break;
  1167. // Any other
  1168. default :
  1169. $retval = __( 'None available', 'bbpress' );
  1170. break;
  1171. }
  1172. }
  1173. return apply_filters( 'bbp_get_dropdown', $retval, $r );
  1174. }
  1175. /**
  1176. * Output the required hidden fields when creating/editing a forum
  1177. *
  1178. * @since bbPress (r3553)
  1179. *
  1180. * @uses bbp_is_forum_edit() To check if it's the forum edit page
  1181. * @uses wp_nonce_field() To generate hidden nonce fields
  1182. * @uses bbp_forum_id() To output the forum id
  1183. * @uses bbp_is_single_forum() To check if it's a forum page
  1184. * @uses bbp_forum_id() To output the forum id
  1185. */
  1186. function bbp_forum_form_fields() {
  1187. if ( bbp_is_forum_edit() ) : ?>
  1188. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-forum" />
  1189. <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
  1190. <?php
  1191. if ( current_user_can( 'unfiltered_html' ) )
  1192. wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false );
  1193. ?>
  1194. <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() );
  1195. else :
  1196. if ( bbp_is_single_forum() ) : ?>
  1197. <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" />
  1198. <?php endif; ?>
  1199. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" />
  1200. <?php
  1201. if ( current_user_can( 'unfiltered_html' ) )
  1202. wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false );
  1203. ?>
  1204. <?php wp_nonce_field( 'bbp-new-forum' );
  1205. endif;
  1206. }
  1207. /**
  1208. * Output the required hidden fields when creating/editing a topic
  1209. *
  1210. * @since bbPress (r2753)
  1211. *
  1212. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  1213. * @uses wp_nonce_field() To generate hidden nonce fields
  1214. * @uses bbp_topic_id() To output the topic id
  1215. * @uses bbp_is_single_forum() To check if it's a forum page
  1216. * @uses bbp_forum_id() To output the forum id
  1217. */
  1218. function bbp_topic_form_fields() {
  1219. if ( bbp_is_topic_edit() ) : ?>
  1220. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" />
  1221. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
  1222. <?php
  1223. if ( current_user_can( 'unfiltered_html' ) )
  1224. wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
  1225. ?>
  1226. <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
  1227. else :
  1228. if ( bbp_is_single_forum() ) : ?>
  1229. <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
  1230. <?php endif; ?>
  1231. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
  1232. <?php if ( current_user_can( 'unfiltered_html' ) )
  1233. wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false ); ?>
  1234. <?php wp_nonce_field( 'bbp-new-topic' );
  1235. endif;
  1236. }
  1237. /**
  1238. * Output the required hidden fields when creating/editing a reply
  1239. *
  1240. * @since bbPress (r2753)
  1241. *
  1242. * @uses bbp_is_reply_edit() To check if it's the reply edit page
  1243. * @uses wp_nonce_field() To generate hidden nonce fields
  1244. * @uses bbp_reply_id() To output the reply id
  1245. * @uses bbp_topic_id() To output the topic id
  1246. * @uses bbp_forum_id() To output the forum id
  1247. */
  1248. function bbp_reply_form_fields() {
  1249. if ( bbp_is_reply_edit() ) : ?>
  1250. <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php bbp_reply_title(); ?>" />
  1251. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" />
  1252. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" />
  1253. <?php if ( current_user_can( 'unfiltered_html' ) )
  1254. wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false ); ?>
  1255. <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
  1256. else : ?>
  1257. <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" />
  1258. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
  1259. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" />
  1260. <?php if ( current_user_can( 'unfiltered_html' ) )
  1261. wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false ); ?>
  1262. <?php wp_nonce_field( 'bbp-new-reply' );
  1263. // Show redirect field if not viewing a specific topic
  1264. if ( bbp_is_query_name( 'bbp_single_topic' ) ) :
  1265. bbp_redirect_to_field( get_permalink() );
  1266. endif;
  1267. endif;
  1268. }
  1269. /**
  1270. * Output the required hidden fields when editing a user
  1271. *
  1272. * @since bbPress (r2690)
  1273. *
  1274. * @uses bbp_displayed_user_id() To output the displayed user id
  1275. * @uses wp_nonce_field() To generate a hidden nonce field
  1276. * @uses wp_referer_field() To generate a hidden referer field
  1277. */
  1278. function bbp_edit_user_form_fields() {
  1279. ?>
  1280. <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" />
  1281. <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" />
  1282. <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
  1283. }
  1284. /**
  1285. * Merge topic form fields
  1286. *
  1287. * Output the required hidden fields when merging a topic
  1288. *
  1289. * @since bbPress (r2756)
  1290. *
  1291. * @uses wp_nonce_field() To generate a hidden nonce field
  1292. * @uses bbp_topic_id() To output the topic id
  1293. */
  1294. function bbp_merge_topic_form_fields() {
  1295. ?>
  1296. <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" />
  1297. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
  1298. <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
  1299. }
  1300. /**
  1301. * Split topic form fields
  1302. *
  1303. * Output the required hidden fields when splitting a topic
  1304. *
  1305. * @since bbPress (r2756)
  1306. *
  1307. * @uses wp_nonce_field() To generate a hidden nonce field
  1308. */
  1309. function bbp_split_topic_form_fields() {
  1310. ?>
  1311. <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" />
  1312. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
  1313. <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
  1314. }
  1315. /**
  1316. * Move reply form fields
  1317. *
  1318. * Output the required hidden fields when moving a reply
  1319. *
  1320. * @uses wp_nonce_field() To generate a hidden nonce field
  1321. */
  1322. function bbp_move_reply_form_fields() {
  1323. ?>
  1324. <input type="hidden" name="action" id="bbp_post_action" value="bbp-move-reply" />
  1325. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
  1326. <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() );
  1327. }
  1328. /**
  1329. * Output a textarea or TinyMCE if enabled
  1330. *
  1331. * @since bbPress (r3586)
  1332. *
  1333. * @param array $args
  1334. * @uses bbp_get_the_content() To return the content to output
  1335. */
  1336. function bbp_the_content( $args = array() ) {
  1337. echo bbp_get_the_content( $args );
  1338. }
  1339. /**
  1340. * Return a textarea or TinyMCE if enabled
  1341. *
  1342. * @since bbPress (r3586)
  1343. *
  1344. * @param array $args
  1345. *
  1346. * @uses apply_filter() To filter args and output
  1347. * @uses wp_parse_pargs() To compare args
  1348. * @uses bbp_use_wp_editor() To see if WP editor is in use
  1349. * @uses bbp_is_edit() To see if we are editing something
  1350. * @uses wp_editor() To output the WordPress editor
  1351. *
  1352. * @return string HTML from output buffer
  1353. */
  1354. function bbp_get_the_content( $args = array() ) {
  1355. // Parse arguments against default values
  1356. $r = bbp_parse_args( $args, array(
  1357. 'context' => 'topic',
  1358. 'before' => '<div class="bbp-the-content-wrapper">',
  1359. 'after' => '</div>',
  1360. 'wpautop' => true,
  1361. 'media_buttons' => false,
  1362. 'textarea_rows' => '12',
  1363. 'tabindex' => bbp_get_tab_index(),
  1364. 'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags',
  1365. 'editor_class' => 'bbp-the-content',
  1366. 'tinymce' => false,
  1367. 'teeny' => true,
  1368. 'quicktags' => true,
  1369. 'dfw' => false
  1370. ), 'get_the_content' );
  1371. // If using tinymce, remove our escaping and trust tinymce
  1372. if ( bbp_use_wp_editor() && ( true === $r['tinymce'] ) ) {
  1373. remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
  1374. remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
  1375. remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
  1376. }
  1377. // Assume we are not editing
  1378. $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' );
  1379. // Start an output buffor
  1380. ob_start();
  1381. // Output something before the editor
  1382. if ( !empty( $r['before'] ) ) {
  1383. echo $r['before'];
  1384. }
  1385. // Use TinyMCE if available
  1386. if ( bbp_use_wp_editor() ) :
  1387. // Enable additional TinyMCE plugins before outputting the editor
  1388. add_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1389. add_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1390. add_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
  1391. add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
  1392. // Output the editor
  1393. wp_editor( $post_content, 'bbp_' . $r['context'] . '_content', array(
  1394. 'wpautop' => $r['wpautop'],
  1395. 'media_buttons' => $r['media_buttons'],
  1396. 'textarea_rows' => $r['textarea_rows'],
  1397. 'tabindex' => $r['tabindex'],
  1398. 'tabfocus_elements' => $r['tabfocus_elements'],
  1399. 'editor_class' => $r['editor_class'],
  1400. 'tinymce' => $r['tinymce'],
  1401. 'teeny' => $r['teeny'],
  1402. 'quicktags' => $r['quicktags'],
  1403. 'dfw' => $r['dfw'],
  1404. ) );
  1405. // Remove additional TinyMCE plugins after outputting the editor
  1406. remove_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1407. remove_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1408. remove_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
  1409. remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
  1410. /**
  1411. * Fallback to normal textarea.
  1412. *
  1413. * Note that we do not use esc_textarea() here to prevent double
  1414. * escaping the editable output, mucking up existing content.
  1415. */
  1416. else : ?>
  1417. <textarea id="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" class="<?php echo esc_attr( $r['editor_class'] ); ?>" name="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" cols="60" rows="<?php echo esc_attr( $r['textarea_rows'] ); ?>" tabindex="<?php echo esc_attr( $r['tabindex'] ); ?>"><?php echo $post_content; ?></textarea>
  1418. <?php endif;
  1419. // Output something after the editor
  1420. if ( !empty( $r['after'] ) ) {
  1421. echo $r['after'];
  1422. }
  1423. // Put the output into a usable variable
  1424. $output = ob_get_contents();
  1425. // Flush the output buffer
  1426. ob_end_clean();
  1427. return apply_filters( 'bbp_get_the_content', $output, $args, $post_content );
  1428. }
  1429. /**
  1430. * Edit TinyMCE plugins to match core behaviour
  1431. *
  1432. * @since bbPress (r4574)
  1433. *
  1434. * @param array $plugins
  1435. * @see tiny_mce_plugins, teeny_mce_plugins
  1436. * @return array
  1437. */
  1438. function bbp_get_tiny_mce_plugins( $plugins = array() ) {
  1439. // Unset fullscreen
  1440. foreach ( $plugins as $key => $value ) {
  1441. if ( 'fullscreen' == $value ) {
  1442. unset( $plugins[$key] );
  1443. break;
  1444. }
  1445. }
  1446. // Add the tabfocus plugin
  1447. $plugins[] = 'tabfocus';
  1448. return apply_filters( 'bbp_get_tiny_mce_plugins', $plugins );
  1449. }
  1450. /**
  1451. * Edit TeenyMCE buttons to match allowedtags
  1452. *
  1453. * @since bbPress (r4605)
  1454. *
  1455. * @param array $buttons
  1456. * @see teeny_mce_buttons
  1457. * @return array
  1458. */
  1459. function bbp_get_teeny_mce_buttons( $buttons = array() ) {
  1460. // Remove some buttons from TeenyMCE
  1461. $buttons = array_diff( $buttons, array(
  1462. 'underline',
  1463. 'justifyleft',
  1464. 'justifycenter',
  1465. 'justifyright'
  1466. ) );
  1467. // Images
  1468. array_push( $buttons, 'image' );
  1469. return apply_filters( 'bbp_get_teeny_mce_buttons', $buttons );
  1470. }
  1471. /**
  1472. * Edit TinyMCE quicktags buttons to match allowedtags
  1473. *
  1474. * @since bbPress (r4606)
  1475. *
  1476. * @param array $buttons
  1477. * @see quicktags_settings
  1478. * @return array Quicktags settings
  1479. */
  1480. function bbp_get_quicktags_settings( $settings = array() ) {
  1481. // Get buttons out of settings
  1482. $buttons_array = explode( ',', $settings['buttons'] );
  1483. // Diff the ones we don't want out
  1484. $buttons = array_diff( $buttons_array, array(
  1485. 'ins',
  1486. 'more',
  1487. 'spell'
  1488. ) );
  1489. // Put them back into a string in the $settings array
  1490. $settings['buttons'] = implode( ',', $buttons );
  1491. return apply_filters( 'bbp_get_quicktags_settings', $settings );
  1492. }
  1493. /** Views *********************************************************************/
  1494. /**
  1495. * Output the view id
  1496. *
  1497. * @since bbPress (r2789)
  1498. *
  1499. * @param string $view Optional. View id
  1500. * @uses bbp_get_view_id() To get the view id
  1501. */
  1502. function bbp_view_id( $view = '' ) {
  1503. echo bbp_get_view_id( $view );
  1504. }
  1505. /**
  1506. * Get the view id
  1507. *
  1508. * If a view id is supplied, that is used. Otherwise the 'bbp_view'
  1509. * query var is checked for.
  1510. *
  1511. * @since bbPress (r2789)
  1512. *
  1513. * @param string $view Optional. View id.
  1514. * @uses sanitize_title() To sanitize the view id
  1515. * @uses get_query_var() To get the view id from query var 'bbp_view'
  1516. * @return bool|string ID on success, false on failure
  1517. */
  1518. function bbp_get_view_id( $view = '' ) {
  1519. $bbp = bbpress();
  1520. $view = !empty( $view ) ? sanitize_title( $view ) : get_query_var( 'bbp_view' );
  1521. if ( array_key_exists( $view, $bbp->views ) )
  1522. return $view;
  1523. return false;
  1524. }
  1525. /**
  1526. * Output the view name aka title
  1527. *
  1528. * @since bbPress (r2789)
  1529. *
  1530. * @param string $view Optional. View id
  1531. * @uses bbp_get_view_title() To get the view title
  1532. */
  1533. function bbp_view_title( $view = '' ) {
  1534. echo bbp_get_view_title( $view );
  1535. }
  1536. /**
  1537. * Get the view name aka title
  1538. *
  1539. * If a view id is supplied, that is used. Otherwise the bbp_view
  1540. * query var is checked for.
  1541. *
  1542. * @since bbPress (r2789)
  1543. *
  1544. * @param string $view Optional. View id
  1545. * @uses bbp_get_view_id() To get the view id
  1546. * @return bool|string Title on success, false on failure
  1547. */
  1548. function bbp_get_view_title( $view = '' ) {
  1549. $bbp = bbpress();
  1550. $view = bbp_get_view_id( $view );
  1551. if ( empty( $view ) )
  1552. return false;
  1553. return $bbp->views[$view]['title'];
  1554. }
  1555. /**
  1556. * Output the view url
  1557. *
  1558. * @since bbPress (r2789)
  1559. *
  1560. * @param string $view Optional. View id
  1561. * @uses bbp_get_view_url() To get the view url
  1562. */
  1563. function bbp_view_url( $view = false ) {
  1564. echo bbp_get_view_url( $view );
  1565. }
  1566. /**
  1567. * Return the view url
  1568. *
  1569. * @since bbPress (r2789)
  1570. *
  1571. * @param string $view Optional. View id
  1572. * @uses sanitize_title() To sanitize the view id
  1573. * @uses home_url() To get blog home url
  1574. * @uses add_query_arg() To add custom args to the url
  1575. * @uses apply_filters() Calls 'bbp_get_view_url' with the view url,
  1576. * used view id
  1577. * @return string View url (or home url if the view was not found)
  1578. */
  1579. function bbp_get_view_url( $view = false ) {
  1580. global $wp_rewrite;
  1581. $view = bbp_get_view_id( $view );
  1582. if ( empty( $view ) )
  1583. return home_url();
  1584. // Pretty permalinks
  1585. if ( $wp_rewrite->using_permalinks() ) {
  1586. $url = $wp_rewrite->root . bbp_get_view_slug() . '/' . $view;
  1587. $url = home_url( user_trailingslashit( $url ) );
  1588. // Unpretty permalinks
  1589. } else {
  1590. $url = add_query_arg( array( 'bbp_view' => $view ), home_url( '/' ) );
  1591. }
  1592. return apply_filters( 'bbp_get_view_link', $url, $view );
  1593. }
  1594. /** Query *********************************************************************/
  1595. /**
  1596. * Check the passed parameter against the current _bbp_query_name
  1597. *
  1598. * @since bbPress (r2980)
  1599. *
  1600. * @uses bbp_get_query_name() Get the query var '_bbp_query_name'
  1601. * @return bool True if match, false if not
  1602. */
  1603. function bbp_is_query_name( $name = '' ) {
  1604. return (bool) ( bbp_get_query_name() == $name );
  1605. }
  1606. /**
  1607. * Get the '_bbp_query_name' setting
  1608. *
  1609. * @since bbPress (r2695)
  1610. *
  1611. * @uses get_query_var() To get the query var '_bbp_query_name'
  1612. * @return string To return the query var value
  1613. */
  1614. function bbp_get_query_name() {
  1615. return get_query_var( '_bbp_query_name' );
  1616. }
  1617. /**
  1618. * Set the '_bbp_query_name' setting to $name
  1619. *
  1620. * @since bbPress (r2692)
  1621. *
  1622. * @param string $name What to set the query var to
  1623. * @uses set_query_var() To set the query var '_bbp_query_name'
  1624. */
  1625. function bbp_set_query_name( $name = '' ) {
  1626. set_query_var( '_bbp_query_name', $name );
  1627. }
  1628. /**
  1629. * Used to clear the '_bbp_query_name' setting
  1630. *
  1631. * @since bbPress (r2692)
  1632. *
  1633. * @uses bbp_set_query_name() To set the query var '_bbp_query_name' value to ''
  1634. */
  1635. function bbp_reset_query_name() {
  1636. bbp_set_query_name();
  1637. }
  1638. /** Breadcrumbs ***************************************************************/
  1639. /**
  1640. * Output the page title as a breadcrumb
  1641. *
  1642. * @since bbPress (r2589)
  1643. *
  1644. * @param string $sep Separator. Defaults to '&larr;'
  1645. * @param bool $current_page Include the current item
  1646. * @param bool $root Include the root page if one exists
  1647. * @uses bbp_get_breadcrumb() To get the breadcrumb
  1648. */
  1649. function bbp_title_breadcrumb( $args = array() ) {
  1650. echo bbp_get_breadcrumb( $args );
  1651. }
  1652. /**
  1653. * Output a breadcrumb
  1654. *
  1655. * @since bbPress (r2589)
  1656. *
  1657. * @param string $sep Separator. Defaults to '&larr;'
  1658. * @param bool $current_page Include the current item
  1659. * @param bool $root Include the root page if one exists
  1660. * @uses bbp_get_breadcrumb() To get the breadcrumb
  1661. */
  1662. function bbp_breadcrumb( $args = array() ) {
  1663. echo bbp_get_breadcrumb( $args );
  1664. }
  1665. /**
  1666. * Return a breadcrumb ( forum -> topic -> reply )
  1667. *
  1668. * @since bbPress (r2589)
  1669. *
  1670. * @param string $sep Separator. Defaults to '&larr;'
  1671. * @param bool $current_page Include the current item
  1672. * @param bool $root Include the root page if one exists
  1673. *
  1674. * @uses get_post() To get the post
  1675. * @uses bbp_get_forum_permalink() To get the forum link
  1676. * @uses bbp_get_topic_permalink() To get the topic link
  1677. * @uses bbp_get_reply_permalink() To get the reply link
  1678. * @uses get_permalink() To get the permalink
  1679. * @uses bbp_get_forum_post_type() To get the forum post type
  1680. * @uses bbp_get_topic_post_type() To get the topic post type
  1681. * @uses bbp_get_reply_post_type() To get the reply post type
  1682. * @uses bbp_get_forum_title() To get the forum title
  1683. * @uses bbp_get_topic_title() To get the topic title
  1684. * @uses bbp_get_reply_title() To get the reply title
  1685. * @uses get_the_title() To get the title
  1686. * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs
  1687. * @return string Breadcrumbs
  1688. */
  1689. function bbp_get_breadcrumb( $args = array() ) {
  1690. // Turn off breadcrumbs
  1691. if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) )
  1692. return;
  1693. // Define variables
  1694. $front_id = $root_id = 0;
  1695. $ancestors = $crumbs = $tag_data = array();
  1696. $pre_root_text = $pre_front_text = $pre_current_text = '';
  1697. $pre_include_root = $pre_include_home = $pre_include_current = true;
  1698. /** Home Text *********************************************************/
  1699. // No custom home text
  1700. if ( empty( $args['home_text'] ) ) {
  1701. $front_id = get_option( 'page_on_front' );
  1702. // Set home text to page title
  1703. if ( !empty( $front_id ) ) {
  1704. $pre_front_text = get_the_title( $front_id );
  1705. // Default to 'Home'
  1706. } else {
  1707. $pre_front_text = __( 'Home', 'bbpress' );
  1708. }
  1709. }
  1710. /** Root Text *********************************************************/
  1711. // No custom root text
  1712. if ( empty( $args['root_text'] ) ) {
  1713. $page = bbp_get_page_by_path( bbp_get_root_slug() );
  1714. if ( !empty( $page ) ) {
  1715. $root_id = $page->ID;
  1716. }
  1717. $pre_root_text = bbp_get_forum_archive_title();
  1718. }
  1719. /** Includes **********************************************************/
  1720. // Root slug is also the front page
  1721. if ( !empty( $front_id ) && ( $front_id == $root_id ) ) {
  1722. $pre_include_root = false;
  1723. }
  1724. // Don't show root if viewing forum archive
  1725. if ( bbp_is_forum_archive() ) {
  1726. $pre_include_root = false;
  1727. }
  1728. // Don't show root if viewing page in place of forum archive
  1729. if ( !empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id == get_the_ID() ) ) ) {
  1730. $pre_include_root = false;
  1731. }
  1732. /** Current Text ******************************************************/
  1733. // Search page
  1734. if ( bbp_is_search() ) {
  1735. $pre_current_text = bbp_get_search_title();
  1736. // Forum archive
  1737. } elseif ( bbp_is_forum_archive() ) {
  1738. $pre_current_text = bbp_get_forum_archive_title();
  1739. // Topic archive
  1740. } elseif ( bbp_is_topic_archive() ) {
  1741. $pre_current_text = bbp_get_topic_archive_title();
  1742. // View
  1743. } elseif ( bbp_is_single_view() ) {
  1744. $pre_current_text = bbp_get_view_title();
  1745. // Single Forum
  1746. } elseif ( bbp_is_single_forum() ) {
  1747. $pre_current_text = bbp_get_forum_title();
  1748. // Single Topic
  1749. } elseif ( bbp_is_single_topic() ) {
  1750. $pre_current_text = bbp_get_topic_title();
  1751. // Single Topic
  1752. } elseif ( bbp_is_single_reply() ) {
  1753. $pre_current_text = bbp_get_reply_title();
  1754. // Topic Tag (or theme compat topic tag)
  1755. } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && !bbp_is_topic_tag_edit() ) ) {
  1756. // Always include the tag name
  1757. $tag_data[] = bbp_get_topic_tag_name();
  1758. // If capable, include a link to edit the tag
  1759. if ( current_user_can( 'manage_topic_tags' ) ) {
  1760. $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __( '(Edit)', 'bbpress' ) . '</a>';
  1761. }
  1762. // Implode the results of the tag data
  1763. $pre_current_text = sprintf( __( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
  1764. // Edit Topic Tag
  1765. } elseif ( bbp_is_topic_tag_edit() ) {
  1766. $pre_current_text = __( 'Edit', 'bbpress' );
  1767. // Single
  1768. } else {
  1769. $pre_current_text = get_the_title();
  1770. }
  1771. /** Parse Args ********************************************************/
  1772. // Parse args
  1773. $r = bbp_parse_args( $args, array(
  1774. // HTML
  1775. 'before' => '<div class="bbp-breadcrumb"><p>',
  1776. 'after' => '</p></div>',
  1777. // Separator
  1778. 'sep' => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
  1779. 'pad_sep' => 1,
  1780. 'sep_before' => '<span class="bbp-breadcrumb-sep">',
  1781. 'sep_after' => '</span>',
  1782. // Crumbs
  1783. 'crumb_before' => '',
  1784. 'crumb_after' => '',
  1785. // Home
  1786. 'include_home' => $pre_include_home,
  1787. 'home_text' => $pre_front_text,
  1788. // Forum root
  1789. 'include_root' => $pre_include_root,
  1790. 'root_text' => $pre_root_text,
  1791. // Current
  1792. 'include_current' => $pre_include_current,
  1793. 'current_text' => $pre_current_text,
  1794. 'current_before' => '<span class="bbp-breadcrumb-current">',
  1795. 'current_after' => '</span>',
  1796. ), 'get_breadcrumb' );
  1797. /** Ancestors *********************************************************/
  1798. // Get post ancestors
  1799. if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
  1800. $ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) );
  1801. }
  1802. // Do we want to include a link to home?
  1803. if ( !empty( $r['include_home'] ) || empty( $r['home_text'] ) ) {
  1804. $crumbs[] = '<a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>';
  1805. }
  1806. // Do we want to include a link to the forum root?
  1807. if ( !empty( $r['include_root'] ) || empty( $r['root_text'] ) ) {
  1808. // Page exists at root slug path, so use its permalink
  1809. $page = bbp_get_page_by_path( bbp_get_root_slug() );
  1810. if ( !empty( $page ) ) {
  1811. $root_url = get_permalink( $page->ID );
  1812. // Use the root slug
  1813. } else {
  1814. $root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
  1815. }
  1816. // Add the breadcrumb
  1817. $crumbs[] = '<a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>';
  1818. }
  1819. // Ancestors exist
  1820. if ( !empty( $ancestors ) ) {
  1821. // Loop through parents
  1822. foreach( (array) $ancestors as $parent_id ) {
  1823. // Parents
  1824. $parent = get_post( $parent_id );
  1825. // Skip parent if empty or error
  1826. if ( empty( $parent ) || is_wp_error( $parent ) )
  1827. continue;
  1828. // Switch through post_type to ensure correct filters are applied
  1829. switch ( $parent->post_type ) {
  1830. // Forum
  1831. case bbp_get_forum_post_type() :
  1832. $crumbs[] = '<a href="' . bbp_get_forum_permalink( $parent->ID ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>';
  1833. break;
  1834. // Topic
  1835. case bbp_get_topic_post_type() :
  1836. $crumbs[] = '<a href="' . bbp_get_topic_permalink( $parent->ID ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>';
  1837. break;
  1838. // Reply (Note: not in most themes)
  1839. case bbp_get_reply_post_type() :
  1840. $crumbs[] = '<a href="' . bbp_get_reply_permalink( $parent->ID ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>';
  1841. break;
  1842. // WordPress Post/Page/Other
  1843. default :
  1844. $crumbs[] = '<a href="' . get_permalink( $parent->ID ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>';
  1845. break;
  1846. }
  1847. }
  1848. // Edit topic tag
  1849. } elseif ( bbp_is_topic_tag_edit() ) {
  1850. $crumbs[] = '<a href="' . get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) . '" class="bbp-breadcrumb-topic-tag">' . sprintf( __( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>';
  1851. // Search
  1852. } elseif ( bbp_is_search() && bbp_get_search_terms() ) {
  1853. $crumbs[] = '<a href="' . home_url( bbp_get_search_slug() ) . '" class="bbp-breadcrumb-search">' . __( 'Search', 'bbpress' ) . '</a>';
  1854. }
  1855. /** Current ***********************************************************/
  1856. // Add current page to breadcrumb
  1857. if ( !empty( $r['include_current'] ) || empty( $r['pre_current_text'] ) ) {
  1858. $crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after'];
  1859. }
  1860. /** Separator *********************************************************/
  1861. // Wrap the separator in before/after before padding and filter
  1862. if ( ! empty( $r['sep'] ) ) {
  1863. $sep = $r['sep_before'] . $r['sep'] . $r['sep_after'];
  1864. }
  1865. // Pad the separator
  1866. if ( !empty( $r['pad_sep'] ) ) {
  1867. if ( function_exists( 'mb_strlen' ) ) {
  1868. $sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
  1869. } else {
  1870. $sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
  1871. }
  1872. }
  1873. /** Finish Up *********************************************************/
  1874. // Filter the separator and breadcrumb
  1875. $sep = apply_filters( 'bbp_breadcrumb_separator', $sep );
  1876. $crumbs = apply_filters( 'bbp_breadcrumbs', $crumbs );
  1877. // Build the trail
  1878. $trail = !empty( $crumbs ) ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'] , $crumbs ) . $r['crumb_after'] . $r['after'] ) : '';
  1879. return apply_filters( 'bbp_get_breadcrumb', $trail, $crumbs, $r );
  1880. }
  1881. /** Topic Tags ***************************************************************/
  1882. /**
  1883. * Output all of the allowed tags in HTML format with attributes.
  1884. *
  1885. * This is useful for displaying in the post area, which elements and
  1886. * attributes are supported. As well as any plugins which want to display it.
  1887. *
  1888. * @since bbPress (r2780)
  1889. *
  1890. * @uses bbp_get_allowed_tags()
  1891. */
  1892. function bbp_allowed_tags() {
  1893. echo bbp_get_allowed_tags();
  1894. }
  1895. /**
  1896. * Display all of the allowed tags in HTML format with attributes.
  1897. *
  1898. * This is useful for displaying in the post area, which elements and
  1899. * attributes are supported. As well as any plugins which want to display it.
  1900. *
  1901. * @since bbPress (r2780)
  1902. *
  1903. * @uses bbp_kses_allowed_tags() To get the allowed tags
  1904. * @uses apply_filters() Calls 'bbp_allowed_tags' with the tags
  1905. * @return string HTML allowed tags entity encoded.
  1906. */
  1907. function bbp_get_allowed_tags() {
  1908. $allowed = '';
  1909. foreach ( (array) bbp_kses_allowed_tags() as $tag => $attributes ) {
  1910. $allowed .= '<' . $tag;
  1911. if ( 0 < count( $attributes ) ) {
  1912. foreach ( array_keys( $attributes ) as $attribute ) {
  1913. $allowed .= ' ' . $attribute . '=""';
  1914. }
  1915. }
  1916. $allowed .= '> ';
  1917. }
  1918. return apply_filters( 'bbp_get_allowed_tags', htmlentities( $allowed ) );
  1919. }
  1920. /** Errors & Messages *********************************************************/
  1921. /**
  1922. * Display possible errors & messages inside a template file
  1923. *
  1924. * @since bbPress (r2688)
  1925. *
  1926. * @uses WP_Error bbPress::errors::get_error_codes() To get the error codes
  1927. * @uses WP_Error bbPress::errors::get_error_data() To get the error data
  1928. * @uses WP_Error bbPress::errors::get_error_messages() To get the error
  1929. * messages
  1930. * @uses is_wp_error() To check if it's a {@link WP_Error}
  1931. */
  1932. function bbp_template_notices() {
  1933. // Bail if no notices or errors
  1934. if ( !bbp_has_errors() )
  1935. return;
  1936. // Define local variable(s)
  1937. $errors = $messages = array();
  1938. // Get bbPress
  1939. $bbp = bbpress();
  1940. // Loop through notices
  1941. foreach ( $bbp->errors->get_error_codes() as $code ) {
  1942. // Get notice severity
  1943. $severity = $bbp->errors->get_error_data( $code );
  1944. // Loop through notices and separate errors from messages
  1945. foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
  1946. if ( 'message' == $severity ) {
  1947. $messages[] = $error;
  1948. } else {
  1949. $errors[] = $error;
  1950. }
  1951. }
  1952. }
  1953. // Display errors first...
  1954. if ( !empty( $errors ) ) : ?>
  1955. <div class="bbp-template-notice error">
  1956. <p>
  1957. <?php echo implode( "</p>\n<p>", $errors ); ?>
  1958. </p>
  1959. </div>
  1960. <?php endif;
  1961. // ...and messages last
  1962. if ( !empty( $messages ) ) : ?>
  1963. <div class="bbp-template-notice">
  1964. <p>
  1965. <?php echo implode( "</p>\n<p>", $messages ); ?>
  1966. </p>
  1967. </div>
  1968. <?php endif;
  1969. }
  1970. /** Login/logout/register/lost pass *******************************************/
  1971. /**
  1972. * Output the logout link
  1973. *
  1974. * @since bbPress (r2827)
  1975. *
  1976. * @param string $redirect_to Redirect to url
  1977. * @uses bbp_get_logout_link() To get the logout link
  1978. */
  1979. function bbp_logout_link( $redirect_to = '' ) {
  1980. echo bbp_get_logout_link( $redirect_to );
  1981. }
  1982. /**
  1983. * Return the logout link
  1984. *
  1985. * @since bbPress (r2827)
  1986. *
  1987. * @param string $redirect_to Redirect to url
  1988. * @uses wp_logout_url() To get the logout url
  1989. * @uses apply_filters() Calls 'bbp_get_logout_link' with the logout link and
  1990. * redirect to url
  1991. * @return string The logout link
  1992. */
  1993. function bbp_get_logout_link( $redirect_to = '' ) {
  1994. return apply_filters( 'bbp_get_logout_link', '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . __( 'Log Out', 'bbpress' ) . '</a>', $redirect_to );
  1995. }
  1996. /** Title *********************************************************************/
  1997. /**
  1998. * Custom page title for bbPress pages
  1999. *
  2000. * @since bbPress (r2788)
  2001. *
  2002. * @param string $title Optional. The title (not used).
  2003. * @param string $sep Optional, default is '&raquo;'. How to separate the
  2004. * various items within the page title.
  2005. * @param string $seplocation Optional. Direction to display title, 'right'.
  2006. * @uses bbp_is_single_user() To check if it's a user profile page
  2007. * @uses bbp_is_single_user_edit() To check if it's a user profile edit page
  2008. * @uses bbp_is_user_home() To check if the profile page is of the current user
  2009. * @uses get_query_var() To get the user id
  2010. * @uses get_userdata() To get the user data
  2011. * @uses bbp_is_single_forum() To check if it's a forum
  2012. * @uses bbp_get_forum_title() To get the forum title
  2013. * @uses bbp_is_single_topic() To check if it's a topic
  2014. * @uses bbp_get_topic_title() To get the topic title
  2015. * @uses bbp_is_single_reply() To check if it's a reply
  2016. * @uses bbp_get_reply_title() To get the reply title
  2017. * @uses is_tax() To check if it's the tag page
  2018. * @uses get_queried_object() To get the queried object
  2019. * @uses bbp_is_single_view() To check if it's a view
  2020. * @uses bbp_get_view_title() To get the view title
  2021. * @uses apply_filters() Calls 'bbp_raw_title' with the title
  2022. * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title,
  2023. * separator and separator location
  2024. * @return string The tite
  2025. */
  2026. function bbp_title( $title = '', $sep = '&raquo;', $seplocation = '' ) {
  2027. // Store original title to compare
  2028. $_title = $title;
  2029. /** Archives **************************************************************/
  2030. // Forum Archive
  2031. if ( bbp_is_forum_archive() ) {
  2032. $title = bbp_get_forum_archive_title();
  2033. // Topic Archive
  2034. } elseif ( bbp_is_topic_archive() ) {
  2035. $title = bbp_get_topic_archive_title();
  2036. /** Singles ***************************************************************/
  2037. // Forum page
  2038. } elseif ( bbp_is_single_forum() ) {
  2039. $title = sprintf( __( 'Forum: %s', 'bbpress' ), bbp_get_forum_title() );
  2040. // Topic page
  2041. } elseif ( bbp_is_single_topic() ) {
  2042. $title = sprintf( __( 'Topic: %s', 'bbpress' ), bbp_get_topic_title() );
  2043. // Replies
  2044. } elseif ( bbp_is_single_reply() ) {
  2045. $title = bbp_get_reply_title();
  2046. // Topic tag page (or edit)
  2047. } elseif ( bbp_is_topic_tag() || bbp_is_topic_tag_edit() || get_query_var( 'bbp_topic_tag' ) ) {
  2048. $term = get_queried_object();
  2049. $title = sprintf( __( 'Topic Tag: %s', 'bbpress' ), $term->name );
  2050. /** Users *****************************************************************/
  2051. // Profile page
  2052. } elseif ( bbp_is_single_user() ) {
  2053. // Current users profile
  2054. if ( bbp_is_user_home() ) {
  2055. $title = __( 'Your Profile', 'bbpress' );
  2056. // Other users profile
  2057. } else {
  2058. $userdata = get_userdata( bbp_get_user_id() );
  2059. $title = sprintf( __( '%s\'s Profile', 'bbpress' ), $userdata->display_name );
  2060. }
  2061. // Profile edit page
  2062. } elseif ( bbp_is_single_user_edit() ) {
  2063. // Current users profile
  2064. if ( bbp_is_user_home_edit() ) {
  2065. $title = __( 'Edit Your Profile', 'bbpress' );
  2066. // Other users profile
  2067. } else {
  2068. $userdata = get_userdata( bbp_get_user_id() );
  2069. $title = sprintf( __( 'Edit %s\'s Profile', 'bbpress' ), $userdata->display_name );
  2070. }
  2071. /** Views *****************************************************************/
  2072. // Views
  2073. } elseif ( bbp_is_single_view() ) {
  2074. $title = sprintf( __( 'View: %s', 'bbpress' ), bbp_get_view_title() );
  2075. /** Search ****************************************************************/
  2076. // Search
  2077. } elseif ( bbp_is_search() ) {
  2078. $title = bbp_get_search_title();
  2079. }
  2080. // Filter the raw title
  2081. $title = apply_filters( 'bbp_raw_title', $title, $sep, $seplocation );
  2082. // Compare new title with original title
  2083. if ( $title == $_title )
  2084. return $title;
  2085. // Temporary separator, for accurate flipping, if necessary
  2086. $t_sep = '%WP_TITILE_SEP%';
  2087. $prefix = '';
  2088. if ( !empty( $title ) )
  2089. $prefix = " $sep ";
  2090. // sep on right, so reverse the order
  2091. if ( 'right' == $seplocation ) {
  2092. $title_array = array_reverse( explode( $t_sep, $title ) );
  2093. $title = implode( " $sep ", $title_array ) . $prefix;
  2094. // sep on left, do not reverse
  2095. } else {
  2096. $title_array = explode( $t_sep, $title );
  2097. $title = $prefix . implode( " $sep ", $title_array );
  2098. }
  2099. // Filter and return
  2100. return apply_filters( 'bbp_title', $title, $sep, $seplocation );
  2101. }