/includes/common/template.php

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