/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 $url 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.  
  1100. // Parse arguments against default values 
  1101. $r = bbp_parse_args( $args, array( 
  1102. 'action' => '',  
  1103. 'context' => '' 
  1104. ), 'login_action' ); 
  1105.  
  1106. // Add action as query arg 
  1107. if ( !empty( $r['action'] ) ) { 
  1108. $login_url = add_query_arg( array( 'action' => $r['action'] ), 'wp-login.php' ); 
  1109.  
  1110. // No query arg 
  1111. } else { 
  1112. $login_url = 'wp-login.php'; 
  1113.  
  1114. $login_url = site_url( $login_url, $r['context'] ); 
  1115.  
  1116. echo apply_filters( 'bbp_wp_login_action', $login_url, $r ); 
  1117.  
  1118. /** 
  1119. * Output hidden request URI field for user forms. 
  1120. * 
  1121. * The referer link is the current Request URI from the server super global. To 
  1122. * check the field manually, use bbp_get_redirect_to(). 
  1123. * 
  1124. * @since bbPress (r2815) 
  1125. * 
  1126. * @param string $redirect_to Pass a URL to redirect to 
  1127. * 
  1128. * @uses wp_get_referer() To get the referer 
  1129. * @uses esc_attr() To escape the url 
  1130. * @uses apply_filters() Calls 'bbp_redirect_to_field', passes field and to 
  1131. */ 
  1132. function bbp_redirect_to_field( $redirect_to = '' ) { 
  1133.  
  1134. // Make sure we are directing somewhere 
  1135. if ( empty( $redirect_to ) ) { 
  1136. if ( isset( $_SERVER['REQUEST_URI'] ) ) { 
  1137. $redirect_to = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
  1138. } else { 
  1139. $redirect_to = wp_get_referer(); 
  1140.  
  1141. // Remove loggedout query arg if it's there 
  1142. $redirect_to = (string) esc_attr( remove_query_arg( 'loggedout', $redirect_to ) ); 
  1143. $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . $redirect_to . '" />'; 
  1144.  
  1145. echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to ); 
  1146.  
  1147. /** 
  1148. * Echo sanitized $_REQUEST value. 
  1149. * 
  1150. * Use the $input_type parameter to properly process the value. This 
  1151. * ensures correct sanitization of the value for the receiving input. 
  1152. * 
  1153. * @since bbPress (r2815) 
  1154. * 
  1155. * @param string $request Name of $_REQUEST to look for 
  1156. * @param string $input_type Type of input. Default: text. Accepts: 
  1157. * textarea|password|select|radio|checkbox 
  1158. * @uses bbp_get_sanitize_val() To sanitize the value. 
  1159. */ 
  1160. function bbp_sanitize_val( $request = '', $input_type = 'text' ) { 
  1161. echo bbp_get_sanitize_val( $request, $input_type ); 
  1162. /** 
  1163. * Return 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 esc_attr() To escape the string 
  1174. * @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized 
  1175. * value, request and input type 
  1176. * @return string Sanitized value ready for screen display 
  1177. */ 
  1178. function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) { 
  1179.  
  1180. // Check that requested 
  1181. if ( empty( $_REQUEST[$request] ) ) 
  1182. return false; 
  1183.  
  1184. // Set request varaible 
  1185. $pre_ret_val = $_REQUEST[$request]; 
  1186.  
  1187. // Treat different kinds of fields in different ways 
  1188. switch ( $input_type ) { 
  1189. case 'text' : 
  1190. case 'textarea' : 
  1191. $retval = esc_attr( stripslashes( $pre_ret_val ) ); 
  1192. break; 
  1193.  
  1194. case 'password' : 
  1195. case 'select' : 
  1196. case 'radio' : 
  1197. case 'checkbox' : 
  1198. default : 
  1199. $retval = esc_attr( $pre_ret_val ); 
  1200. break; 
  1201.  
  1202. return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type ); 
  1203.  
  1204. /** 
  1205. * Output the current tab index of a given form 
  1206. * 
  1207. * Use this function to handle the tab indexing of user facing forms within a 
  1208. * template file. Calling this function will automatically increment the global 
  1209. * tab index by default. 
  1210. * 
  1211. * @since bbPress (r2810) 
  1212. * 
  1213. * @param int $auto_increment Optional. Default true. Set to false to prevent 
  1214. * increment 
  1215. */ 
  1216. function bbp_tab_index( $auto_increment = true ) { 
  1217. echo bbp_get_tab_index( $auto_increment ); 
  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 
  1223. * within a template file. Calling this function will automatically 
  1224. * increment the global tab index by default. 
  1225. * 
  1226. * @since bbPress (r2810) 
  1227. * 
  1228. * @uses apply_filters Allows return value to be filtered 
  1229. * @param int $auto_increment Optional. Default true. Set to false to 
  1230. * prevent the increment 
  1231. * @return int $bbp->tab_index The global tab index 
  1232. */ 
  1233. function bbp_get_tab_index( $auto_increment = true ) { 
  1234. $bbp = bbpress(); 
  1235.  
  1236. if ( true === $auto_increment ) 
  1237. ++$bbp->tab_index; 
  1238.  
  1239. return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index ); 
  1240.  
  1241. /** 
  1242. * Output a select box allowing to pick which forum/topic a new topic/reply 
  1243. * belongs in. 
  1244. * 
  1245. * Can be used for any post type, but is mostly used for topics and forums. 
  1246. * 
  1247. * @since bbPress (r2746) 
  1248. * 
  1249. * @param mixed $args See {@link bbp_get_dropdown()} for arguments 
  1250. */ 
  1251. function bbp_dropdown( $args = '' ) { 
  1252. echo bbp_get_dropdown( $args ); 
  1253. /** 
  1254. * Output a select box allowing to pick which forum/topic a new 
  1255. * topic/reply belongs in. 
  1256. * 
  1257. * @since bbPress (r2746) 
  1258. * 
  1259. * @param mixed $args The function supports these args: 
  1260. * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum) 
  1261. * - selected: Selected ID, to not have any value as selected, pass 
  1262. * anything smaller than 0 (due to the nature of select 
  1263. * box, the first value would of course be selected - 
  1264. * though you can have that as none (pass 'show_none' arg)) 
  1265. * - orderby: Defaults to 'menu_order title' 
  1266. * - post_parent: Post parent. Defaults to 0 
  1267. * - post_status: Which all post_statuses to find in? Can be an array 
  1268. * or CSV of publish, category, closed, private, spam,  
  1269. * trash (based on post type) - if not set, these are 
  1270. * automatically determined based on the post_type 
  1271. * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get 
  1272. * all posts 
  1273. * - walker: Which walker to use? Defaults to 
  1274. * {@link BBP_Walker_Dropdown} 
  1275. * - select_id: ID of the select box. Defaults to 'bbp_forum_id' 
  1276. * - tab: Tabindex value. False or integer 
  1277. * - options_only: Show only <options>? No <select>? 
  1278. * - show_none: Boolean or String __( '(No Forum)', 'bbpress' ) 
  1279. * - disable_categories: Disable forum categories and closed forums? 
  1280. * Defaults to true. Only for forums and when 
  1281. * the category option is displayed. 
  1282. * @uses BBP_Walker_Dropdown() As the default walker to generate the 
  1283. * dropdown 
  1284. * @uses current_user_can() To check if the current user can read 
  1285. * private forums 
  1286. * @uses bbp_get_forum_post_type() To get the forum post type 
  1287. * @uses bbp_get_topic_post_type() To get the topic post type 
  1288. * @uses walk_page_dropdown_tree() To generate the dropdown using the 
  1289. * walker 
  1290. * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown 
  1291. * and args 
  1292. * @return string The dropdown 
  1293. */ 
  1294. function bbp_get_dropdown( $args = '' ) { 
  1295.  
  1296. /** Arguments *********************************************************/ 
  1297.  
  1298. // Parse arguments against default values 
  1299. $r = bbp_parse_args( $args, array( 
  1300. 'post_type' => bbp_get_forum_post_type(),  
  1301. 'post_parent' => null,  
  1302. 'post_status' => null,  
  1303. 'selected' => 0,  
  1304. 'exclude' => array(),  
  1305. 'numberposts' => -1,  
  1306. 'orderby' => 'menu_order title',  
  1307. 'order' => 'ASC',  
  1308. 'walker' => '',  
  1309.  
  1310. // Output-related 
  1311. 'select_id' => 'bbp_forum_id',  
  1312. 'tab' => bbp_get_tab_index(),  
  1313. 'options_only' => false,  
  1314. 'show_none' => false,  
  1315. 'disable_categories' => true,  
  1316. 'disabled' => '' 
  1317. ), 'get_dropdown' ); 
  1318.  
  1319. if ( empty( $r['walker'] ) ) { 
  1320. $r['walker'] = new BBP_Walker_Dropdown(); 
  1321. $r['walker']->tree_type = $r['post_type']; 
  1322.  
  1323. // Force 0 
  1324. if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) { 
  1325. $r['selected'] = 0; 
  1326.  
  1327. // Force array 
  1328. if ( !empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) { 
  1329. $r['exclude'] = explode( ', ', $r['exclude'] ); 
  1330.  
  1331. /** Setup variables ***************************************************/ 
  1332.  
  1333. $retval = ''; 
  1334. $posts = get_posts( array( 
  1335. 'post_type' => $r['post_type'],  
  1336. 'post_status' => $r['post_status'],  
  1337. 'exclude' => $r['exclude'],  
  1338. 'post_parent' => $r['post_parent'],  
  1339. 'numberposts' => $r['numberposts'],  
  1340. 'orderby' => $r['orderby'],  
  1341. 'order' => $r['order'],  
  1342. 'walker' => $r['walker'],  
  1343. 'disable_categories' => $r['disable_categories'] 
  1344. ) ); 
  1345.  
  1346. /** Drop Down *********************************************************/ 
  1347.  
  1348. // Build the opening tag for the select element 
  1349. if ( empty( $r['options_only'] ) ) { 
  1350.  
  1351. // Should this select appear disabled? 
  1352. $disabled = disabled( isset( bbpress()->options[ $r['disabled'] ] ), true, false ); 
  1353.  
  1354. // Setup the tab index attribute 
  1355. $tab = !empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : ''; 
  1356.  
  1357. // Open the select tag 
  1358. $retval .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '"' . $disabled . $tab . '>' . "\n"; 
  1359.  
  1360. // Display a leading 'no-value' option, with or without custom text 
  1361. if ( !empty( $r['show_none'] ) || !empty( $r['none_found'] ) ) { 
  1362.  
  1363. // Open the 'no-value' option tag 
  1364. $retval .= "\t<option value=\"\" class=\"level-0\">"; 
  1365.  
  1366. // Use deprecated 'none_found' first for backpat 
  1367. if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) { 
  1368. $retval .= esc_html( $r['none_found'] ); 
  1369.  
  1370. // Use 'show_none' second 
  1371. } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) { 
  1372. $retval .= esc_html( $r['show_none'] ); 
  1373.  
  1374. // Otherwise, make some educated guesses 
  1375. } else { 
  1376.  
  1377. // Switch the response based on post type 
  1378. switch ( $r['post_type'] ) { 
  1379.  
  1380. // Topics 
  1381. case bbp_get_topic_post_type() : 
  1382. $retval .= esc_html__( 'No topics available', 'bbpress' ); 
  1383. break; 
  1384.  
  1385. // Forums 
  1386. case bbp_get_forum_post_type() : 
  1387. $retval .= esc_html__( 'No forums available', 'bbpress' ); 
  1388. break; 
  1389.  
  1390. // Any other 
  1391. default : 
  1392. $retval .= esc_html__( 'None available', 'bbpress' ); 
  1393. break; 
  1394.  
  1395. // Close the 'no-value' option tag 
  1396. $retval .= '</option>'; 
  1397.  
  1398. // Items found so walk the tree 
  1399. if ( !empty( $posts ) ) { 
  1400. $retval .= walk_page_dropdown_tree( $posts, 0, $r ); 
  1401.  
  1402. // Close the selecet tag 
  1403. if ( empty( $r['options_only'] ) ) { 
  1404. $retval .= '</select>'; 
  1405.  
  1406. return apply_filters( 'bbp_get_dropdown', $retval, $r ); 
  1407.  
  1408. /** 
  1409. * Output the required hidden fields when creating/editing a forum 
  1410. * 
  1411. * @since bbPress (r3553) 
  1412. * 
  1413. * @uses bbp_is_forum_edit() To check if it's the forum edit page 
  1414. * @uses wp_nonce_field() To generate hidden nonce fields 
  1415. * @uses bbp_forum_id() To output the forum id 
  1416. * @uses bbp_is_single_forum() To check if it's a forum page 
  1417. * @uses bbp_forum_id() To output the forum id 
  1418. */ 
  1419. function bbp_forum_form_fields() { 
  1420.  
  1421. if ( bbp_is_forum_edit() ) : ?> 
  1422.  
  1423. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-forum" /> 
  1424. <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" /> 
  1425.  
  1426. <?php 
  1427.  
  1428. if ( current_user_can( 'unfiltered_html' ) ) 
  1429. wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false ); 
  1430.  
  1431. ?> 
  1432.  
  1433. <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() ); 
  1434.  
  1435. else : 
  1436.  
  1437. if ( bbp_is_single_forum() ) : ?> 
  1438.  
  1439. <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" /> 
  1440.  
  1441. <?php endif; ?> 
  1442.  
  1443. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" /> 
  1444.  
  1445. <?php 
  1446.  
  1447. if ( current_user_can( 'unfiltered_html' ) ) 
  1448. wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false ); 
  1449.  
  1450. ?> 
  1451.  
  1452. <?php wp_nonce_field( 'bbp-new-forum' ); 
  1453.  
  1454. endif; 
  1455.  
  1456. /** 
  1457. * Output the required hidden fields when creating/editing a topic 
  1458. * 
  1459. * @since bbPress (r2753) 
  1460. * 
  1461. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  1462. * @uses wp_nonce_field() To generate hidden nonce fields 
  1463. * @uses bbp_topic_id() To output the topic id 
  1464. * @uses bbp_is_single_forum() To check if it's a forum page 
  1465. * @uses bbp_forum_id() To output the forum id 
  1466. */ 
  1467. function bbp_topic_form_fields() { 
  1468.  
  1469. if ( bbp_is_topic_edit() ) : ?> 
  1470.  
  1471. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" /> 
  1472. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> 
  1473.  
  1474. <?php 
  1475.  
  1476. if ( current_user_can( 'unfiltered_html' ) ) 
  1477. wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false ); 
  1478.  
  1479. ?> 
  1480.  
  1481. <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() ); 
  1482.  
  1483. else : 
  1484.  
  1485. if ( bbp_is_single_forum() ) : ?> 
  1486.  
  1487. <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" /> 
  1488.  
  1489. <?php endif; ?> 
  1490.  
  1491. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" /> 
  1492.  
  1493. <?php if ( current_user_can( 'unfiltered_html' ) ) 
  1494. wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false ); ?> 
  1495.  
  1496. <?php wp_nonce_field( 'bbp-new-topic' ); 
  1497.  
  1498. endif; 
  1499.  
  1500. /** 
  1501. * Output the required hidden fields when creating/editing a reply 
  1502. * 
  1503. * @since bbPress (r2753) 
  1504. * 
  1505. * @uses bbp_is_reply_edit() To check if it's the reply edit page 
  1506. * @uses wp_nonce_field() To generate hidden nonce fields 
  1507. * @uses bbp_reply_id() To output the reply id 
  1508. * @uses bbp_topic_id() To output the topic id 
  1509. * @uses bbp_forum_id() To output the forum id 
  1510. */ 
  1511. function bbp_reply_form_fields() { 
  1512.  
  1513. if ( bbp_is_reply_edit() ) : ?> 
  1514.  
  1515. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" /> 
  1516. <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="<?php bbp_form_reply_to(); ?>" /> 
  1517. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" /> 
  1518.  
  1519. <?php if ( current_user_can( 'unfiltered_html' ) ) 
  1520. wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false ); ?> 
  1521.  
  1522. <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() ); 
  1523.  
  1524. else : ?> 
  1525.  
  1526. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> 
  1527. <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="<?php bbp_form_reply_to(); ?>" /> 
  1528. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" /> 
  1529.  
  1530. <?php if ( current_user_can( 'unfiltered_html' ) ) 
  1531. wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false ); ?> 
  1532.  
  1533. <?php wp_nonce_field( 'bbp-new-reply' ); 
  1534.  
  1535. // Show redirect field if not viewing a specific topic 
  1536. if ( bbp_is_query_name( 'bbp_single_topic' ) ) : 
  1537. bbp_redirect_to_field( get_permalink() ); 
  1538.  
  1539. endif; 
  1540. endif; 
  1541.  
  1542. /** 
  1543. * Output the required hidden fields when editing a user 
  1544. * 
  1545. * @since bbPress (r2690) 
  1546. * 
  1547. * @uses bbp_displayed_user_id() To output the displayed user id 
  1548. * @uses wp_nonce_field() To generate a hidden referer field 
  1549. */ 
  1550. function bbp_edit_user_form_fields() { 
  1551. ?> 
  1552.  
  1553. <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" /> 
  1554. <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" /> 
  1555.  
  1556. <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() ); 
  1557.  
  1558. /** 
  1559. * Merge topic form fields 
  1560. * 
  1561. * Output the required hidden fields when merging a topic 
  1562. * 
  1563. * @since bbPress (r2756) 
  1564. * 
  1565. * @uses wp_nonce_field() To generate a hidden nonce field 
  1566. * @uses bbp_topic_id() To output the topic id 
  1567. */ 
  1568. function bbp_merge_topic_form_fields() { 
  1569. ?> 
  1570.  
  1571. <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" /> 
  1572. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> 
  1573.  
  1574. <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() ); 
  1575.  
  1576. /** 
  1577. * Split topic form fields 
  1578. * 
  1579. * Output the required hidden fields when splitting a topic 
  1580. * 
  1581. * @since bbPress (r2756) 
  1582. * 
  1583. * @uses wp_nonce_field() To generate a hidden nonce field 
  1584. */ 
  1585. function bbp_split_topic_form_fields() { 
  1586. ?> 
  1587.  
  1588. <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" /> 
  1589. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" /> 
  1590.  
  1591. <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() ); 
  1592.  
  1593. /** 
  1594. * Move reply form fields 
  1595. * 
  1596. * Output the required hidden fields when moving a reply 
  1597. * 
  1598. * @uses wp_nonce_field() To generate a hidden nonce field 
  1599. */ 
  1600. function bbp_move_reply_form_fields() { 
  1601. ?> 
  1602.  
  1603. <input type="hidden" name="action" id="bbp_post_action" value="bbp-move-reply" /> 
  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-move-reply_' . bbp_get_reply_id() ); 
  1607.  
  1608. /** 
  1609. * Output a textarea or TinyMCE if enabled 
  1610. * 
  1611. * @since bbPress (r3586) 
  1612. * 
  1613. * @param array $args 
  1614. * @uses bbp_get_the_content() To return the content to output 
  1615. */ 
  1616. function bbp_the_content( $args = array() ) { 
  1617. echo bbp_get_the_content( $args ); 
  1618. /** 
  1619. * Return a textarea or TinyMCE if enabled 
  1620. * 
  1621. * @since bbPress (r3586) 
  1622. * 
  1623. * @param array $args 
  1624. * 
  1625. * @uses apply_filter() To filter args and output 
  1626. * @uses wp_parse_pargs() To compare args 
  1627. * @uses bbp_use_wp_editor() To see if WP editor is in use 
  1628. * @uses bbp_is_edit() To see if we are editing something 
  1629. * @uses wp_editor() To output the WordPress editor 
  1630. * 
  1631. * @return string HTML from output buffer 
  1632. */ 
  1633. function bbp_get_the_content( $args = array() ) { 
  1634.  
  1635. // Parse arguments against default values 
  1636. $r = bbp_parse_args( $args, array( 
  1637. 'context' => 'topic',  
  1638. 'before' => '<div class="bbp-the-content-wrapper">',  
  1639. 'after' => '</div>',  
  1640. 'wpautop' => true,  
  1641. 'media_buttons' => false,  
  1642. 'textarea_rows' => '12',  
  1643. 'tabindex' => bbp_get_tab_index(),  
  1644. 'tabfocus_elements' => 'bbp_topic_title, bbp_topic_tags',  
  1645. 'editor_class' => 'bbp-the-content',  
  1646. 'tinymce' => false,  
  1647. 'teeny' => true,  
  1648. 'quicktags' => true,  
  1649. 'dfw' => false 
  1650. ), 'get_the_content' ); 
  1651.  
  1652. // If using tinymce, remove our escaping and trust tinymce 
  1653. if ( bbp_use_wp_editor() && ( false !== $r['tinymce'] ) ) { 
  1654. remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' ); 
  1655. remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' ); 
  1656. remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' ); 
  1657.  
  1658. // Assume we are not editing 
  1659. $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' ); 
  1660.  
  1661. // Start an output buffor 
  1662. ob_start(); 
  1663.  
  1664. // Output something before the editor 
  1665. if ( !empty( $r['before'] ) ) { 
  1666. echo $r['before']; 
  1667.  
  1668. // Use TinyMCE if available 
  1669. if ( bbp_use_wp_editor() ) : 
  1670.  
  1671. // Enable additional TinyMCE plugins before outputting the editor 
  1672. add_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); 
  1673. add_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); 
  1674. add_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' ); 
  1675. add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' ); 
  1676.  
  1677. // Output the editor 
  1678. wp_editor( $post_content, 'bbp_' . $r['context'] . '_content', array( 
  1679. 'wpautop' => $r['wpautop'],  
  1680. 'media_buttons' => $r['media_buttons'],  
  1681. 'textarea_rows' => $r['textarea_rows'],  
  1682. 'tabindex' => $r['tabindex'],  
  1683. 'tabfocus_elements' => $r['tabfocus_elements'],  
  1684. 'editor_class' => $r['editor_class'],  
  1685. 'tinymce' => $r['tinymce'],  
  1686. 'teeny' => $r['teeny'],  
  1687. 'quicktags' => $r['quicktags'],  
  1688. 'dfw' => $r['dfw'],  
  1689. ) ); 
  1690.  
  1691. // Remove additional TinyMCE plugins after outputting the editor 
  1692. remove_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); 
  1693. remove_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); 
  1694. remove_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' ); 
  1695. remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' ); 
  1696.  
  1697. /** 
  1698. * Fallback to normal textarea. 
  1699. * 
  1700. * Note that we do not use esc_textarea() here to prevent double 
  1701. * escaping the editable output, mucking up existing content. 
  1702. */ 
  1703. else : ?> 
  1704.  
  1705. <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> 
  1706.  
  1707. <?php endif; 
  1708.  
  1709. // Output something after the editor 
  1710. if ( !empty( $r['after'] ) ) { 
  1711. echo $r['after']; 
  1712.  
  1713. // Put the output into a usable variable 
  1714. $output = ob_get_clean(); 
  1715.  
  1716. return apply_filters( 'bbp_get_the_content', $output, $args, $post_content ); 
  1717.  
  1718. /** 
  1719. * Edit TinyMCE plugins to match core behaviour 
  1720. * 
  1721. * @since bbPress (r4574) 
  1722. * 
  1723. * @param array $plugins 
  1724. * @see tiny_mce_plugins, teeny_mce_plugins 
  1725. * @return array 
  1726. */ 
  1727. function bbp_get_tiny_mce_plugins( $plugins = array() ) { 
  1728.  
  1729. // Unset fullscreen 
  1730. foreach ( $plugins as $key => $value ) { 
  1731. if ( 'fullscreen' === $value ) { 
  1732. unset( $plugins[$key] ); 
  1733. break; 
  1734.  
  1735. // Add the tabfocus plugin 
  1736. $plugins[] = 'tabfocus'; 
  1737.  
  1738. return apply_filters( 'bbp_get_tiny_mce_plugins', $plugins ); 
  1739.  
  1740. /** 
  1741. * Edit TeenyMCE buttons to match allowedtags 
  1742. * 
  1743. * @since bbPress (r4605) 
  1744. * 
  1745. * @param array $buttons 
  1746. * @see teeny_mce_buttons 
  1747. * @return array 
  1748. */ 
  1749. function bbp_get_teeny_mce_buttons( $buttons = array() ) { 
  1750.  
  1751. // Remove some buttons from TeenyMCE 
  1752. $buttons = array_diff( $buttons, array( 
  1753. 'underline',  
  1754. 'justifyleft',  
  1755. 'justifycenter',  
  1756. 'justifyright' 
  1757. ) ); 
  1758.  
  1759. // Images 
  1760. array_push( $buttons, 'image' ); 
  1761.  
  1762. return apply_filters( 'bbp_get_teeny_mce_buttons', $buttons ); 
  1763.  
  1764. /** 
  1765. * Edit TinyMCE quicktags buttons to match allowedtags 
  1766. * 
  1767. * @since bbPress (r4606) 
  1768. * 
  1769. * @param array $buttons 
  1770. * @see quicktags_settings 
  1771. * @return array Quicktags settings 
  1772. */ 
  1773. function bbp_get_quicktags_settings( $settings = array() ) { 
  1774.  
  1775. // Get buttons out of settings 
  1776. $buttons_array = explode( ', ', $settings['buttons'] ); 
  1777.  
  1778. // Diff the ones we don't want out 
  1779. $buttons = array_diff( $buttons_array, array( 
  1780. 'ins',  
  1781. 'more',  
  1782. 'spell' 
  1783. ) ); 
  1784.  
  1785. // Put them back into a string in the $settings array 
  1786. $settings['buttons'] = implode( ', ', $buttons ); 
  1787.  
  1788. return apply_filters( 'bbp_get_quicktags_settings', $settings ); 
  1789.  
  1790. /** Views *********************************************************************/ 
  1791.  
  1792. /** 
  1793. * Output the view id 
  1794. * 
  1795. * @since bbPress (r2789) 
  1796. * 
  1797. * @param string $view Optional. View id 
  1798. * @uses bbp_get_view_id() To get the view id 
  1799. */ 
  1800. function bbp_view_id( $view = '' ) { 
  1801. echo bbp_get_view_id( $view ); 
  1802.  
  1803. /** 
  1804. * Get the view id 
  1805. * 
  1806. * Use view id if supplied, otherwise bbp_get_view_rewrite_id() query var. 
  1807. * 
  1808. * @since bbPress (r2789) 
  1809. * 
  1810. * @param string $view Optional. View id. 
  1811. * @uses sanitize_title() To sanitize the view id 
  1812. * @uses get_query_var() To get the view id query variable 
  1813. * @uses bbp_get_view_rewrite_id() To get the view rewrite ID 
  1814. * @return bool|string ID on success, false on failure 
  1815. */ 
  1816. function bbp_get_view_id( $view = '' ) { 
  1817. $bbp = bbpress(); 
  1818.  
  1819. if ( !empty( $view ) ) { 
  1820. $view = sanitize_title( $view ); 
  1821. } elseif ( ! empty( $bbp->current_view_id ) ) { 
  1822. $view = $bbp->current_view_id; 
  1823. } else { 
  1824. $view = get_query_var( bbp_get_view_rewrite_id() ); 
  1825.  
  1826. if ( array_key_exists( $view, $bbp->views ) ) { 
  1827. return $view; 
  1828.  
  1829. return false; 
  1830.  
  1831. /** 
  1832. * Output the view name aka title 
  1833. * 
  1834. * @since bbPress (r2789) 
  1835. * 
  1836. * @param string $view Optional. View id 
  1837. * @uses bbp_get_view_title() To get the view title 
  1838. */ 
  1839. function bbp_view_title( $view = '' ) { 
  1840. echo bbp_get_view_title( $view ); 
  1841.  
  1842. /** 
  1843. * Get the view name aka title 
  1844. * 
  1845. * If a view id is supplied, that is used. Otherwise the bbp_view 
  1846. * query var is checked for. 
  1847. * 
  1848. * @since bbPress (r2789) 
  1849. * 
  1850. * @param string $view Optional. View id 
  1851. * @uses bbp_get_view_id() To get the view id 
  1852. * @return bool|string Title on success, false on failure 
  1853. */ 
  1854. function bbp_get_view_title( $view = '' ) { 
  1855. $bbp = bbpress(); 
  1856.  
  1857. $view = bbp_get_view_id( $view ); 
  1858. if ( empty( $view ) ) 
  1859. return false; 
  1860.  
  1861. return $bbp->views[$view]['title']; 
  1862.  
  1863. /** 
  1864. * Output the view url 
  1865. * 
  1866. * @since bbPress (r2789) 
  1867. * 
  1868. * @param string $view Optional. View id 
  1869. * @uses bbp_get_view_url() To get the view url 
  1870. */ 
  1871. function bbp_view_url( $view = false ) { 
  1872. echo esc_url( bbp_get_view_url( $view ) ); 
  1873. /** 
  1874. * Return the view url 
  1875. * 
  1876. * @since bbPress (r2789) 
  1877. * 
  1878. * @param string $view Optional. View id 
  1879. * @uses sanitize_title() To sanitize the view id 
  1880. * @uses home_url() To get blog home url 
  1881. * @uses add_query_arg() To add custom args to the url 
  1882. * @uses apply_filters() Calls 'bbp_get_view_url' with the view url,  
  1883. * used view id 
  1884. * @return string View url (or home url if the view was not found) 
  1885. */ 
  1886. function bbp_get_view_url( $view = false ) { 
  1887. global $wp_rewrite; 
  1888.  
  1889. $view = bbp_get_view_id( $view ); 
  1890. if ( empty( $view ) ) 
  1891. return home_url(); 
  1892.  
  1893. // Pretty permalinks 
  1894. if ( $wp_rewrite->using_permalinks() ) { 
  1895. $url = $wp_rewrite->root . bbp_get_view_slug() . '/' . $view; 
  1896. $url = home_url( user_trailingslashit( $url ) ); 
  1897.  
  1898. // Unpretty permalinks 
  1899. } else { 
  1900. $url = add_query_arg( array( bbp_get_view_rewrite_id() => $view ), home_url( '/' ) ); 
  1901.  
  1902. return apply_filters( 'bbp_get_view_link', $url, $view ); 
  1903.  
  1904. /** Query *********************************************************************/ 
  1905.  
  1906. /** 
  1907. * Check the passed parameter against the current _bbp_query_name 
  1908. * 
  1909. * @since bbPress (r2980) 
  1910. * 
  1911. * @uses bbp_get_query_name() Get the query var '_bbp_query_name' 
  1912. * @return bool True if match, false if not 
  1913. */ 
  1914. function bbp_is_query_name( $name = '' ) { 
  1915. return (bool) ( bbp_get_query_name() === $name ); 
  1916.  
  1917. /** 
  1918. * Get the '_bbp_query_name' setting 
  1919. * 
  1920. * @since bbPress (r2695) 
  1921. * 
  1922. * @uses get_query_var() To get the query var '_bbp_query_name' 
  1923. * @return string To return the query var value 
  1924. */ 
  1925. function bbp_get_query_name() { 
  1926. return get_query_var( '_bbp_query_name' ); 
  1927.  
  1928. /** 
  1929. * Set the '_bbp_query_name' setting to $name 
  1930. * 
  1931. * @since bbPress (r2692) 
  1932. * 
  1933. * @param string $name What to set the query var to 
  1934. * @uses set_query_var() To set the query var '_bbp_query_name' 
  1935. */ 
  1936. function bbp_set_query_name( $name = '' ) { 
  1937. set_query_var( '_bbp_query_name', $name ); 
  1938.  
  1939. /** 
  1940. * Used to clear the '_bbp_query_name' setting 
  1941. * 
  1942. * @since bbPress (r2692) 
  1943. * 
  1944. * @uses bbp_set_query_name() To set the query var '_bbp_query_name' value to '' 
  1945. */ 
  1946. function bbp_reset_query_name() { 
  1947. bbp_set_query_name(); 
  1948.  
  1949. /** Breadcrumbs ***************************************************************/ 
  1950.  
  1951. /** 
  1952. * Output the page title as a breadcrumb 
  1953. * 
  1954. * @since bbPress (r2589) 
  1955. * 
  1956. * @param string $sep Separator. Defaults to '←' 
  1957. * @param bool $current_page Include the current item 
  1958. * @param bool $root Include the root page if one exists 
  1959. * @uses bbp_get_breadcrumb() To get the breadcrumb 
  1960. */ 
  1961. function bbp_title_breadcrumb( $args = array() ) { 
  1962. echo bbp_get_breadcrumb( $args ); 
  1963.  
  1964. /** 
  1965. * Output a breadcrumb 
  1966. * 
  1967. * @since bbPress (r2589) 
  1968. * 
  1969. * @param string $sep Separator. Defaults to '←' 
  1970. * @param bool $current_page Include the current item 
  1971. * @param bool $root Include the root page if one exists 
  1972. * @uses bbp_get_breadcrumb() To get the breadcrumb 
  1973. */ 
  1974. function bbp_breadcrumb( $args = array() ) { 
  1975. echo bbp_get_breadcrumb( $args ); 
  1976. /** 
  1977. * Return a breadcrumb ( forum -> topic -> reply ) 
  1978. * 
  1979. * @since bbPress (r2589) 
  1980. * 
  1981. * @param string $sep Separator. Defaults to '←' 
  1982. * @param bool $current_page Include the current item 
  1983. * @param bool $root Include the root page if one exists 
  1984. * 
  1985. * @uses get_post() To get the post 
  1986. * @uses bbp_get_forum_permalink() To get the forum link 
  1987. * @uses bbp_get_topic_permalink() To get the topic link 
  1988. * @uses bbp_get_reply_permalink() To get the reply link 
  1989. * @uses get_permalink() To get the permalink 
  1990. * @uses bbp_get_forum_post_type() To get the forum post type 
  1991. * @uses bbp_get_topic_post_type() To get the topic post type 
  1992. * @uses bbp_get_reply_post_type() To get the reply post type 
  1993. * @uses bbp_get_forum_title() To get the forum title 
  1994. * @uses bbp_get_topic_title() To get the topic title 
  1995. * @uses bbp_get_reply_title() To get the reply title 
  1996. * @uses get_the_title() To get the title 
  1997. * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs 
  1998. * @return string Breadcrumbs 
  1999. */ 
  2000. function bbp_get_breadcrumb( $args = array() ) { 
  2001.  
  2002. // Turn off breadcrumbs 
  2003. if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) ) 
  2004. return; 
  2005.  
  2006. // Define variables 
  2007. $front_id = $root_id = 0; 
  2008. $ancestors = $crumbs = $tag_data = array(); 
  2009. $pre_root_text = $pre_front_text = $pre_current_text = ''; 
  2010. $pre_include_root = $pre_include_home = $pre_include_current = true; 
  2011.  
  2012. /** Home Text *********************************************************/ 
  2013.  
  2014. // No custom home text 
  2015. if ( empty( $args['home_text'] ) ) { 
  2016.  
  2017. $front_id = get_option( 'page_on_front' ); 
  2018.  
  2019. // Set home text to page title 
  2020. if ( !empty( $front_id ) ) { 
  2021. $pre_front_text = get_the_title( $front_id ); 
  2022.  
  2023. // Default to 'Home' 
  2024. } else { 
  2025. $pre_front_text = __( 'Home', 'bbpress' ); 
  2026.  
  2027. /** Root Text *********************************************************/ 
  2028.  
  2029. // No custom root text 
  2030. if ( empty( $args['root_text'] ) ) { 
  2031. $page = bbp_get_page_by_path( bbp_get_root_slug() ); 
  2032. if ( !empty( $page ) ) { 
  2033. $root_id = $page->ID; 
  2034. $pre_root_text = bbp_get_forum_archive_title(); 
  2035.  
  2036. /** Includes **********************************************************/ 
  2037.  
  2038. // Root slug is also the front page 
  2039. if ( !empty( $front_id ) && ( $front_id === $root_id ) ) { 
  2040. $pre_include_root = false; 
  2041.  
  2042. // Don't show root if viewing forum archive 
  2043. if ( bbp_is_forum_archive() ) { 
  2044. $pre_include_root = false; 
  2045.  
  2046. // Don't show root if viewing page in place of forum archive 
  2047. if ( !empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id === get_the_ID() ) ) ) { 
  2048. $pre_include_root = false; 
  2049.  
  2050. /** Current Text ******************************************************/ 
  2051.  
  2052. // Search page 
  2053. if ( bbp_is_search() ) { 
  2054. $pre_current_text = bbp_get_search_title(); 
  2055.  
  2056. // Forum archive 
  2057. } elseif ( bbp_is_forum_archive() ) { 
  2058. $pre_current_text = bbp_get_forum_archive_title(); 
  2059.  
  2060. // Topic archive 
  2061. } elseif ( bbp_is_topic_archive() ) { 
  2062. $pre_current_text = bbp_get_topic_archive_title(); 
  2063.  
  2064. // View 
  2065. } elseif ( bbp_is_single_view() ) { 
  2066. $pre_current_text = bbp_get_view_title(); 
  2067.  
  2068. // Single Forum 
  2069. } elseif ( bbp_is_single_forum() ) { 
  2070. $pre_current_text = bbp_get_forum_title(); 
  2071.  
  2072. // Single Topic 
  2073. } elseif ( bbp_is_single_topic() ) { 
  2074. $pre_current_text = bbp_get_topic_title(); 
  2075.  
  2076. // Single Topic 
  2077. } elseif ( bbp_is_single_reply() ) { 
  2078. $pre_current_text = bbp_get_reply_title(); 
  2079.  
  2080. // Topic Tag (or theme compat topic tag) 
  2081. } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && !bbp_is_topic_tag_edit() ) ) { 
  2082.  
  2083. // Always include the tag name 
  2084. $tag_data[] = bbp_get_topic_tag_name(); 
  2085.  
  2086. // If capable, include a link to edit the tag 
  2087. if ( current_user_can( 'manage_topic_tags' ) ) { 
  2088. $tag_data[] = '<a href="' . esc_url( bbp_get_topic_tag_edit_link() ) . '" class="bbp-edit-topic-tag-link">' . esc_html__( '(Edit)', 'bbpress' ) . '</a>'; 
  2089.  
  2090. // Implode the results of the tag data 
  2091. $pre_current_text = sprintf( __( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) ); 
  2092.  
  2093. // Edit Topic Tag 
  2094. } elseif ( bbp_is_topic_tag_edit() ) { 
  2095. $pre_current_text = __( 'Edit', 'bbpress' ); 
  2096.  
  2097. // Single 
  2098. } else { 
  2099. $pre_current_text = get_the_title(); 
  2100.  
  2101. /** Parse Args ********************************************************/ 
  2102.  
  2103. // Parse args 
  2104. $r = bbp_parse_args( $args, array( 
  2105.  
  2106. // HTML 
  2107. 'before' => '<div class="bbp-breadcrumb"><p>',  
  2108. 'after' => '</p></div>',  
  2109.  
  2110. // Separator 
  2111. 'sep' => is_rtl() ? __( '‹', 'bbpress' ) : __( '›', 'bbpress' ),  
  2112. 'pad_sep' => 1,  
  2113. 'sep_before' => '<span class="bbp-breadcrumb-sep">',  
  2114. 'sep_after' => '</span>',  
  2115.  
  2116. // Crumbs 
  2117. 'crumb_before' => '',  
  2118. 'crumb_after' => '',  
  2119.  
  2120. // Home 
  2121. 'include_home' => $pre_include_home,  
  2122. 'home_text' => $pre_front_text,  
  2123.  
  2124. // Forum root 
  2125. 'include_root' => $pre_include_root,  
  2126. 'root_text' => $pre_root_text,  
  2127.  
  2128. // Current 
  2129. 'include_current' => $pre_include_current,  
  2130. 'current_text' => $pre_current_text,  
  2131. 'current_before' => '<span class="bbp-breadcrumb-current">',  
  2132. 'current_after' => '</span>',  
  2133. ), 'get_breadcrumb' ); 
  2134.  
  2135. /** Ancestors *********************************************************/ 
  2136.  
  2137. // Get post ancestors 
  2138. if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) { 
  2139. $ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) ); 
  2140.  
  2141. // Do we want to include a link to home? 
  2142. if ( !empty( $r['include_home'] ) || empty( $r['home_text'] ) ) { 
  2143. $crumbs[] = '<a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>'; 
  2144.  
  2145. // Do we want to include a link to the forum root? 
  2146. if ( !empty( $r['include_root'] ) || empty( $r['root_text'] ) ) { 
  2147.  
  2148. // Page exists at root slug path, so use its permalink 
  2149. $page = bbp_get_page_by_path( bbp_get_root_slug() ); 
  2150. if ( !empty( $page ) ) { 
  2151. $root_url = get_permalink( $page->ID ); 
  2152.  
  2153. // Use the root slug 
  2154. } else { 
  2155. $root_url = get_post_type_archive_link( bbp_get_forum_post_type() ); 
  2156.  
  2157. // Add the breadcrumb 
  2158. $crumbs[] = '<a href="' . esc_url( $root_url ) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>'; 
  2159.  
  2160. // Ancestors exist 
  2161. if ( !empty( $ancestors ) ) { 
  2162.  
  2163. // Loop through parents 
  2164. foreach ( (array) $ancestors as $parent_id ) { 
  2165.  
  2166. // Parents 
  2167. $parent = get_post( $parent_id ); 
  2168.  
  2169. // Skip parent if empty or error 
  2170. if ( empty( $parent ) || is_wp_error( $parent ) ) 
  2171. continue; 
  2172.  
  2173. // Switch through post_type to ensure correct filters are applied 
  2174. switch ( $parent->post_type ) { 
  2175.  
  2176. // Forum 
  2177. case bbp_get_forum_post_type() : 
  2178. $crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>'; 
  2179. break; 
  2180.  
  2181. // Topic 
  2182. case bbp_get_topic_post_type() : 
  2183. $crumbs[] = '<a href="' . esc_url( bbp_get_topic_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>'; 
  2184. break; 
  2185.  
  2186. // Reply (Note: not in most themes) 
  2187. case bbp_get_reply_post_type() : 
  2188. $crumbs[] = '<a href="' . esc_url( bbp_get_reply_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>'; 
  2189. break; 
  2190.  
  2191. // WordPress Post/Page/Other 
  2192. default : 
  2193. $crumbs[] = '<a href="' . esc_url( get_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>'; 
  2194. break; 
  2195.  
  2196. // Edit topic tag 
  2197. } elseif ( bbp_is_topic_tag_edit() ) { 
  2198. $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>'; 
  2199.  
  2200. // Search 
  2201. } elseif ( bbp_is_search() && bbp_get_search_terms() ) { 
  2202. $crumbs[] = '<a href="' . esc_url( bbp_get_search_url() ) . '" class="bbp-breadcrumb-search">' . esc_html__( 'Search', 'bbpress' ) . '</a>'; 
  2203.  
  2204. /** Current ***********************************************************/ 
  2205.  
  2206. // Add current page to breadcrumb 
  2207. if ( !empty( $r['include_current'] ) || empty( $r['current_text'] ) ) { 
  2208. $crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after']; 
  2209.  
  2210. /** Separator *********************************************************/ 
  2211.  
  2212. // Wrap the separator in before/after before padding and filter 
  2213. if ( ! empty( $r['sep'] ) ) { 
  2214. $sep = $r['sep_before'] . $r['sep'] . $r['sep_after']; 
  2215.  
  2216. // Pad the separator 
  2217. if ( !empty( $r['pad_sep'] ) ) { 
  2218. if ( function_exists( 'mb_strlen' ) ) { 
  2219. $sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH ); 
  2220. } else { 
  2221. $sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH ); 
  2222.  
  2223. /** Finish Up *********************************************************/ 
  2224.  
  2225. // Filter the separator and breadcrumb 
  2226. $sep = apply_filters( 'bbp_breadcrumb_separator', $sep ); 
  2227. $crumbs = apply_filters( 'bbp_breadcrumbs', $crumbs ); 
  2228.  
  2229. // Build the trail 
  2230. $trail = !empty( $crumbs ) ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'] , $crumbs ) . $r['crumb_after'] . $r['after'] ) : ''; 
  2231.  
  2232. return apply_filters( 'bbp_get_breadcrumb', $trail, $crumbs, $r ); 
  2233.  
  2234. /** Topic Tags ***************************************************************/ 
  2235.  
  2236. /** 
  2237. * Output all of the allowed tags in HTML format with attributes. 
  2238. * 
  2239. * This is useful for displaying in the post area, which elements and 
  2240. * attributes are supported. As well as any plugins which want to display it. 
  2241. * 
  2242. * @since bbPress (r2780) 
  2243. * 
  2244. * @uses bbp_get_allowed_tags() 
  2245. */ 
  2246. function bbp_allowed_tags() { 
  2247. echo bbp_get_allowed_tags(); 
  2248. /** 
  2249. * Display all of the allowed tags in HTML format with attributes. 
  2250. * 
  2251. * This is useful for displaying in the post area, which elements and 
  2252. * attributes are supported. As well as any plugins which want to display it. 
  2253. * 
  2254. * @since bbPress (r2780) 
  2255. * 
  2256. * @uses bbp_kses_allowed_tags() To get the allowed tags 
  2257. * @uses apply_filters() Calls 'bbp_allowed_tags' with the tags 
  2258. * @return string HTML allowed tags entity encoded. 
  2259. */ 
  2260. function bbp_get_allowed_tags() { 
  2261.  
  2262. $allowed = ''; 
  2263.  
  2264. foreach ( (array) bbp_kses_allowed_tags() as $tag => $attributes ) { 
  2265. $allowed .= '<' . $tag; 
  2266. if ( 0 < count( $attributes ) ) { 
  2267. foreach ( array_keys( $attributes ) as $attribute ) { 
  2268. $allowed .= ' ' . $attribute . '=""'; 
  2269. $allowed .= '> '; 
  2270.  
  2271. return apply_filters( 'bbp_get_allowed_tags', htmlentities( $allowed ) ); 
  2272.  
  2273. /** Errors & Messages *********************************************************/ 
  2274.  
  2275. /** 
  2276. * Display possible errors & messages inside a template file 
  2277. * 
  2278. * @since bbPress (r2688) 
  2279. * 
  2280. * @uses WP_Error bbPress::errors::get_error_codes() To get the error codes 
  2281. * @uses WP_Error bbPress::errors::get_error_data() To get the error data 
  2282. * @uses WP_Error bbPress::errors::get_error_messages() To get the error 
  2283. * messages 
  2284. * @uses is_wp_error() To check if it's a {@link WP_Error} 
  2285. */ 
  2286. function bbp_template_notices() { 
  2287.  
  2288. // Bail if no notices or errors 
  2289. if ( !bbp_has_errors() ) 
  2290. return; 
  2291.  
  2292. // Define local variable(s) 
  2293. $errors = $messages = array(); 
  2294.  
  2295. // Get bbPress 
  2296. $bbp = bbpress(); 
  2297.  
  2298. // Loop through notices 
  2299. foreach ( $bbp->errors->get_error_codes() as $code ) { 
  2300.  
  2301. // Get notice severity 
  2302. $severity = $bbp->errors->get_error_data( $code ); 
  2303.  
  2304. // Loop through notices and separate errors from messages 
  2305. foreach ( $bbp->errors->get_error_messages( $code ) as $error ) { 
  2306. if ( 'message' === $severity ) { 
  2307. $messages[] = $error; 
  2308. } else { 
  2309. $errors[] = $error; 
  2310.  
  2311. // Display errors first... 
  2312. if ( !empty( $errors ) ) : ?> 
  2313.  
  2314. <div class="bbp-template-notice error"> 
  2315. <p> 
  2316. <?php echo implode( "</p>\n<p>", $errors ); ?> 
  2317. </p> 
  2318. </div> 
  2319.  
  2320. <?php endif; 
  2321.  
  2322. // ...and messages last 
  2323. if ( !empty( $messages ) ) : ?> 
  2324.  
  2325. <div class="bbp-template-notice"> 
  2326. <p> 
  2327. <?php echo implode( "</p>\n<p>", $messages ); ?> 
  2328. </p> 
  2329. </div> 
  2330.  
  2331. <?php endif; 
  2332.  
  2333. /** Login/logout/register/lost pass *******************************************/ 
  2334.  
  2335. /** 
  2336. * Output the logout link 
  2337. * 
  2338. * @since bbPress (r2827) 
  2339. * 
  2340. * @param string $redirect_to Redirect to url 
  2341. * @uses bbp_get_logout_link() To get the logout link 
  2342. */ 
  2343. function bbp_logout_link( $redirect_to = '' ) { 
  2344. echo bbp_get_logout_link( $redirect_to ); 
  2345. /** 
  2346. * Return the logout link 
  2347. * 
  2348. * @since bbPress (r2827) 
  2349. * 
  2350. * @param string $redirect_to Redirect to url 
  2351. * @uses wp_logout_url() To get the logout url 
  2352. * @uses apply_filters() Calls 'bbp_get_logout_link' with the logout link and 
  2353. * redirect to url 
  2354. * @return string The logout link 
  2355. */ 
  2356. function bbp_get_logout_link( $redirect_to = '' ) { 
  2357. 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 ); 
  2358.  
  2359. /** Title *********************************************************************/ 
  2360.  
  2361. /** 
  2362. * Custom page title for bbPress pages 
  2363. * 
  2364. * @since bbPress (r2788) 
  2365. * 
  2366. * @param string $title Optional. The title (not used). 
  2367. * @param string $sep Optional, default is '»'. How to separate the 
  2368. * various items within the page title. 
  2369. * @param string $seplocation Optional. Direction to display title, 'right'. 
  2370. * @uses bbp_is_single_user() To check if it's a user profile page 
  2371. * @uses bbp_is_single_user_edit() To check if it's a user profile edit page 
  2372. * @uses bbp_is_user_home() To check if the profile page is of the current user 
  2373. * @uses get_query_var() To get the user id 
  2374. * @uses get_userdata() To get the user data 
  2375. * @uses bbp_is_single_forum() To check if it's a forum 
  2376. * @uses bbp_get_forum_title() To get the forum title 
  2377. * @uses bbp_is_single_topic() To check if it's a topic 
  2378. * @uses bbp_get_topic_title() To get the topic title 
  2379. * @uses bbp_is_single_reply() To check if it's a reply 
  2380. * @uses bbp_get_reply_title() To get the reply title 
  2381. * @uses is_tax() To check if it's the tag page 
  2382. * @uses get_queried_object() To get the queried object 
  2383. * @uses bbp_is_single_view() To check if it's a view 
  2384. * @uses bbp_get_view_title() To get the view title 
  2385. * @uses apply_filters() Calls 'bbp_raw_title' with the title 
  2386. * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title,  
  2387. * separator and separator location 
  2388. * @return string The tite 
  2389. */ 
  2390. function bbp_title( $title = '', $sep = '»', $seplocation = '' ) { 
  2391.  
  2392. // Title array 
  2393. $new_title = array(); 
  2394.  
  2395. /** Archives **************************************************************/ 
  2396.  
  2397. // Forum Archive 
  2398. if ( bbp_is_forum_archive() ) { 
  2399. $new_title['text'] = bbp_get_forum_archive_title(); 
  2400.  
  2401. // Topic Archive 
  2402. } elseif ( bbp_is_topic_archive() ) { 
  2403. $new_title['text'] = bbp_get_topic_archive_title(); 
  2404.  
  2405. /** Edit ******************************************************************/ 
  2406.  
  2407. // Forum edit page 
  2408. } elseif ( bbp_is_forum_edit() ) { 
  2409. $new_title['text'] = bbp_get_forum_title(); 
  2410. $new_title['format'] = esc_attr__( 'Forum Edit: %s', 'bbpress' ); 
  2411.  
  2412. // Topic edit page 
  2413. } elseif ( bbp_is_topic_edit() ) { 
  2414. $new_title['text'] = bbp_get_topic_title(); 
  2415. $new_title['format'] = esc_attr__( 'Topic Edit: %s', 'bbpress' ); 
  2416.  
  2417. // Reply edit page 
  2418. } elseif ( bbp_is_reply_edit() ) { 
  2419. $new_title['text'] = bbp_get_reply_title(); 
  2420. $new_title['format'] = esc_attr__( 'Reply Edit: %s', 'bbpress' ); 
  2421.  
  2422. // Topic tag edit page 
  2423. } elseif ( bbp_is_topic_tag_edit() ) { 
  2424. $new_title['text'] = bbp_get_topic_tag_name(); 
  2425. $new_title['format'] = esc_attr__( 'Topic Tag Edit: %s', 'bbpress' ); 
  2426.  
  2427. /** Singles ***************************************************************/ 
  2428.  
  2429. // Forum page 
  2430. } elseif ( bbp_is_single_forum() ) { 
  2431. $new_title['text'] = bbp_get_forum_title(); 
  2432. $new_title['format'] = esc_attr__( 'Forum: %s', 'bbpress' ); 
  2433.  
  2434. // Topic page 
  2435. } elseif ( bbp_is_single_topic() ) { 
  2436. $new_title['text'] = bbp_get_topic_title(); 
  2437. $new_title['format'] = esc_attr__( 'Topic: %s', 'bbpress' ); 
  2438.  
  2439. // Replies 
  2440. } elseif ( bbp_is_single_reply() ) { 
  2441. $new_title['text'] = bbp_get_reply_title(); 
  2442.  
  2443. // Topic tag page 
  2444. } elseif ( bbp_is_topic_tag() || get_query_var( 'bbp_topic_tag' ) ) { 
  2445. $new_title['text'] = bbp_get_topic_tag_name(); 
  2446. $new_title['format'] = esc_attr__( 'Topic Tag: %s', 'bbpress' ); 
  2447.  
  2448. /** Users *****************************************************************/ 
  2449.  
  2450. // Profile page 
  2451. } elseif ( bbp_is_single_user() ) { 
  2452.  
  2453. // User is viewing their own profile 
  2454. if ( bbp_is_user_home() ) { 
  2455. $new_title['text'] = esc_attr_x( 'Your', 'User viewing his/her own profile', 'bbpress' ); 
  2456.  
  2457. // User is viewing someone else's profile (so use their display name) 
  2458. } else { 
  2459. $new_title['text'] = sprintf( esc_attr_x( "%s's", 'User viewing another users profile', 'bbpress' ), get_userdata( bbp_get_user_id() )->display_name ); 
  2460.  
  2461. // User topics created 
  2462. if ( bbp_is_single_user_topics() ) { 
  2463. $new_title['format'] = esc_attr__( "%s Topics", 'bbpress' ); 
  2464.  
  2465. // User rueplies created 
  2466. } elseif ( bbp_is_single_user_replies() ) { 
  2467. $new_title['format'] = esc_attr__( "%s Replies", 'bbpress' ); 
  2468.  
  2469. // User favorites 
  2470. } elseif ( bbp_is_favorites() ) { 
  2471. $new_title['format'] = esc_attr__( "%s Favorites", 'bbpress' ); 
  2472.  
  2473. // User subscriptions 
  2474. } elseif ( bbp_is_subscriptions() ) { 
  2475. $new_title['format'] = esc_attr__( "%s Subscriptions", 'bbpress' ); 
  2476.  
  2477. // User "home" 
  2478. } else { 
  2479. $new_title['format'] = esc_attr__( "%s Profile", 'bbpress' ); 
  2480.  
  2481. // Profile edit page 
  2482. } elseif ( bbp_is_single_user_edit() ) { 
  2483.  
  2484. // Current user 
  2485. if ( bbp_is_user_home_edit() ) { 
  2486. $new_title['text'] = esc_attr__( 'Edit Your Profile', 'bbpress' ); 
  2487.  
  2488. // Other user 
  2489. } else { 
  2490. $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; 
  2491. $new_title['format'] = esc_attr__( "Edit %s's Profile", 'bbpress' ); 
  2492.  
  2493. /** Views *****************************************************************/ 
  2494.  
  2495. // View
  2496. } elseif ( bbp_is_single_view() ) { 
  2497. $new_title['text'] = bbp_get_view_title(); 
  2498. $new_title['format'] = esc_attr__( 'View: %s', 'bbpress' ); 
  2499.  
  2500. /** Search ****************************************************************/ 
  2501.  
  2502. // Search 
  2503. } elseif ( bbp_is_search() ) { 
  2504. $new_title['text'] = bbp_get_search_title(); 
  2505.  
  2506. // This filter is deprecated. Use 'bbp_before_title_parse_args' instead. 
  2507. $new_title = apply_filters( 'bbp_raw_title_array', $new_title ); 
  2508.  
  2509. // Set title array defaults 
  2510. $new_title = bbp_parse_args( $new_title, array( 
  2511. 'text' => $title,  
  2512. 'format' => '%s' 
  2513. ), 'title' ); 
  2514.  
  2515. // Get the formatted raw title 
  2516. $new_title = sprintf( $new_title['format'], $new_title['text'] ); 
  2517.  
  2518. // Filter the raw title 
  2519. $new_title = apply_filters( 'bbp_raw_title', $new_title, $sep, $seplocation ); 
  2520.  
  2521. // Compare new title with original title 
  2522. if ( $new_title === $title ) 
  2523. return $title; 
  2524.  
  2525. // Temporary separator, for accurate flipping, if necessary 
  2526. $t_sep = '%WP_TITILE_SEP%'; 
  2527. $prefix = ''; 
  2528.  
  2529. if ( !empty( $new_title ) ) 
  2530. $prefix = " $sep "; 
  2531.  
  2532. // sep on right, so reverse the order 
  2533. if ( 'right' === $seplocation ) { 
  2534. $new_title_array = array_reverse( explode( $t_sep, $new_title ) ); 
  2535. $new_title = implode( " $sep ", $new_title_array ) . $prefix; 
  2536.  
  2537. // sep on left, do not reverse 
  2538. } else { 
  2539. $new_title_array = explode( $t_sep, $new_title ); 
  2540. $new_title = $prefix . implode( " $sep ", $new_title_array ); 
  2541.  
  2542. // Filter and return 
  2543. return apply_filters( 'bbp_title', $new_title, $sep, $seplocation ); 
.