PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/bfay/maniacal-kitten
PHP | 2581 lines | 981 code | 480 blank | 1120 comment | 244 complexity | d845eb1757e3406416cef352542ad724 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * bbPress Common Template Tags
  4. *
  5. * Common template tags are ones that are used by more than one component, like
  6. * forums, topics, replies, users, topic tags, etc...
  7. *
  8. * @package bbPress
  9. * @subpackage TemplateTags
  10. */
  11. // Exit if accessed directly
  12. if ( !defined( 'ABSPATH' ) ) exit;
  13. /** URLs **********************************************************************/
  14. /**
  15. * Ouput the forum URL
  16. *
  17. * @since bbPress (r3979)
  18. *
  19. * @uses bbp_get_forums_url() To get the forums URL
  20. * @param string $path Additional path with leading slash
  21. */
  22. function bbp_forums_url( $path = '/' ) {
  23. echo bbp_get_forums_url( $path );
  24. }
  25. /**
  26. * Return the forum URL
  27. *
  28. * @since bbPress (r3979)
  29. *
  30. * @uses home_url() To get the home URL
  31. * @uses bbp_get_root_slug() To get the forum root location
  32. * @param string $path Additional path with leading slash
  33. */
  34. function bbp_get_forums_url( $path = '/' ) {
  35. return home_url( bbp_get_root_slug() . $path );
  36. }
  37. /**
  38. * Ouput the forum URL
  39. *
  40. * @since bbPress (r3979)
  41. *
  42. * @uses bbp_get_topics_url() To get the topics URL
  43. * @param string $path Additional path with leading slash
  44. */
  45. function bbp_topics_url( $path = '/' ) {
  46. echo bbp_get_topics_url( $path );
  47. }
  48. /**
  49. * Return the forum URL
  50. *
  51. * @since bbPress (r3979)
  52. *
  53. * @uses home_url() To get the home URL
  54. * @uses bbp_get_topic_archive_slug() To get the topics archive location
  55. * @param string $path Additional path with leading slash
  56. * @return The URL to the topics archive
  57. */
  58. function bbp_get_topics_url( $path = '/' ) {
  59. return home_url( bbp_get_topic_archive_slug() . $path );
  60. }
  61. /** Add-on Actions ************************************************************/
  62. /**
  63. * Add our custom head action to wp_head
  64. *
  65. * @since bbPress (r2464)
  66. *
  67. * @uses do_action() Calls 'bbp_head'
  68. */
  69. function bbp_head() {
  70. do_action( 'bbp_head' );
  71. }
  72. /**
  73. * Add our custom head action to wp_head
  74. *
  75. * @since bbPress (r2464)
  76. *
  77. * @uses do_action() Calls 'bbp_footer'
  78. */
  79. function bbp_footer() {
  80. do_action( 'bbp_footer' );
  81. }
  82. /** is_ ***********************************************************************/
  83. /**
  84. * Check if current site is public
  85. *
  86. * @since bbPress (r3398)
  87. *
  88. * @param int $site_id
  89. * @uses get_current_blog_id()
  90. * @uses get_blog_option()
  91. * @uses apply_filters()
  92. * @return bool True if site is public, false if private
  93. */
  94. function bbp_is_site_public( $site_id = 0 ) {
  95. // Get the current site ID
  96. if ( empty( $site_id ) )
  97. $site_id = get_current_blog_id();
  98. // Get the site visibility setting
  99. $public = get_blog_option( $site_id, 'blog_public', 1 );
  100. return (bool) apply_filters( 'bbp_is_site_public', $public, $site_id );
  101. }
  102. /**
  103. * Check if current page is a bbPress forum
  104. *
  105. * @since bbPress (r2549)
  106. *
  107. * @param int $post_id Possible post_id to check
  108. * @uses bbp_get_forum_post_type() To get the forum post type
  109. * @return bool True if it's a forum page, false if not
  110. */
  111. function bbp_is_forum( $post_id = 0 ) {
  112. // Assume false
  113. $retval = false;
  114. // Supplied ID is a forum
  115. if ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_type( $post_id ) ))
  116. $retval = true;
  117. return (bool) apply_filters( 'bbp_is_forum', $retval, $post_id );
  118. }
  119. /**
  120. * Check if we are viewing a forum archive.
  121. *
  122. * @since bbPress (r3251)
  123. *
  124. * @uses is_post_type_archive() To check if we are looking at the forum archive
  125. * @uses bbp_get_forum_post_type() To get the forum post type ID
  126. *
  127. * @return bool
  128. */
  129. function bbp_is_forum_archive() {
  130. // Default to false
  131. $retval = false;
  132. // In forum archive
  133. if ( is_post_type_archive( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_forum_archive' ) )
  134. $retval = true;
  135. return (bool) apply_filters( 'bbp_is_forum_archive', $retval );
  136. }
  137. /**
  138. * Viewing a single forum
  139. *
  140. * @since bbPress (r3338)
  141. *
  142. * @uses is_single()
  143. * @uses bbp_get_forum_post_type()
  144. * @uses get_post_type()
  145. * @uses apply_filters()
  146. *
  147. * @return bool
  148. */
  149. function bbp_is_single_forum() {
  150. // Assume false
  151. $retval = false;
  152. // Edit is not a single forum
  153. if ( bbp_is_forum_edit() )
  154. return false;
  155. // Single and a match
  156. if ( is_singular( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_single_forum' ) )
  157. $retval = true;
  158. return (bool) apply_filters( 'bbp_is_single_forum', $retval );
  159. }
  160. /**
  161. * Check if current page is a forum edit page
  162. *
  163. * @since bbPress (r3553)
  164. *
  165. * @uses WP_Query Checks if WP_Query::bbp_is_forum_edit is true
  166. * @return bool True if it's the forum edit page, false if not
  167. */
  168. function bbp_is_forum_edit() {
  169. global $wp_query, $pagenow;
  170. // Assume false
  171. $retval = false;
  172. // Check query
  173. if ( !empty( $wp_query->bbp_is_forum_edit ) && ( $wp_query->bbp_is_forum_edit == true ) )
  174. $retval = true;
  175. // Editing in admin
  176. elseif ( is_admin() && ( 'post.php' == $pagenow ) && ( get_post_type() == bbp_get_forum_post_type() ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  177. $retval = true;
  178. return (bool) apply_filters( 'bbp_is_forum_edit', $retval );
  179. }
  180. /**
  181. * Check if current page is a bbPress topic
  182. *
  183. * @since bbPress (r2549)
  184. *
  185. * @param int $post_id Possible post_id to check
  186. * @uses bbp_get_topic_post_type() To get the topic post type
  187. * @uses get_post_type() To get the post type of the post id
  188. * @return bool True if it's a topic page, false if not
  189. */
  190. function bbp_is_topic( $post_id = 0 ) {
  191. // Assume false
  192. $retval = false;
  193. // Supplied ID is a topic
  194. if ( !empty( $post_id ) && ( bbp_get_topic_post_type() == get_post_type( $post_id ) ) )
  195. $retval = true;
  196. return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id );
  197. }
  198. /**
  199. * Viewing a single topic
  200. *
  201. * @since bbPress (r3338)
  202. *
  203. * @uses is_single()
  204. * @uses bbp_get_topic_post_type()
  205. * @uses get_post_type()
  206. * @uses apply_filters()
  207. *
  208. * @return bool
  209. */
  210. function bbp_is_single_topic() {
  211. // Assume false
  212. $retval = false;
  213. // Edit is not a single topic
  214. if ( bbp_is_topic_edit() )
  215. return false;
  216. // Single and a match
  217. if ( is_singular( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_single_topic' ) )
  218. $retval = true;
  219. return (bool) apply_filters( 'bbp_is_single_topic', $retval );
  220. }
  221. /**
  222. * Check if we are viewing a topic archive.
  223. *
  224. * @since bbPress (r3251)
  225. *
  226. * @uses is_post_type_archive() To check if we are looking at the topic archive
  227. * @uses bbp_get_topic_post_type() To get the topic post type ID
  228. *
  229. * @return bool
  230. */
  231. function bbp_is_topic_archive() {
  232. // Default to false
  233. $retval = false;
  234. // In topic archive
  235. if ( is_post_type_archive( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_topic_archive' ) )
  236. $retval = true;
  237. return (bool) apply_filters( 'bbp_is_topic_archive', $retval );
  238. }
  239. /**
  240. * Check if current page is a topic edit page
  241. *
  242. * @since bbPress (r2753)
  243. *
  244. * @uses WP_Query Checks if WP_Query::bbp_is_topic_edit is true
  245. * @return bool True if it's the topic edit page, false if not
  246. */
  247. function bbp_is_topic_edit() {
  248. global $wp_query, $pagenow;
  249. // Assume false
  250. $retval = false;
  251. // Check query
  252. if ( !empty( $wp_query->bbp_is_topic_edit ) && ( $wp_query->bbp_is_topic_edit == true ) )
  253. $retval = true;
  254. // Editing in admin
  255. elseif ( is_admin() && ( 'post.php' == $pagenow ) && ( get_post_type() == bbp_get_topic_post_type() ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  256. $retval = true;
  257. return (bool) apply_filters( 'bbp_is_topic_edit', $retval );
  258. }
  259. /**
  260. * Check if current page is a topic merge page
  261. *
  262. * @since bbPress (r2756)
  263. *
  264. * @uses bbp_is_topic_edit() To check if it's a topic edit page
  265. * @return bool True if it's the topic merge page, false if not
  266. */
  267. function bbp_is_topic_merge() {
  268. // Assume false
  269. $retval = false;
  270. // Check topic edit and GET params
  271. if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) )
  272. return true;
  273. return (bool) apply_filters( 'bbp_is_topic_merge', $retval );
  274. }
  275. /**
  276. * Check if current page is a topic split page
  277. *
  278. * @since bbPress (r2756)
  279. *
  280. * @uses bbp_is_topic_edit() To check if it's a topic edit page
  281. * @return bool True if it's the topic split page, false if not
  282. */
  283. function bbp_is_topic_split() {
  284. // Assume false
  285. $retval = false;
  286. // Check topic edit and GET params
  287. if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) )
  288. $retval = true;
  289. return (bool) apply_filters( 'bbp_is_topic_split', $retval );
  290. }
  291. /**
  292. * Check if the current page is a topic tag
  293. *
  294. * @since bbPress (r3311)
  295. *
  296. * @return bool True if it's a topic tag, false if not
  297. */
  298. function bbp_is_topic_tag() {
  299. // Bail if topic-tags are off
  300. if ( ! bbp_allow_topic_tags() )
  301. return false;
  302. // Return false if editing a topic tag
  303. if ( bbp_is_topic_tag_edit() )
  304. return false;
  305. // Assume false
  306. $retval = false;
  307. // Check tax and query vars
  308. if ( is_tax( bbp_get_topic_tag_tax_id() ) || !empty( bbpress()->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) )
  309. $retval = true;
  310. return (bool) apply_filters( 'bbp_is_topic_tag', $retval );
  311. }
  312. /**
  313. * Check if the current page is editing a topic tag
  314. *
  315. * @since bbPress (r3346)
  316. *
  317. * @uses WP_Query Checks if WP_Query::bbp_is_topic_tag_edit is true
  318. * @return bool True if editing a topic tag, false if not
  319. */
  320. function bbp_is_topic_tag_edit() {
  321. global $wp_query, $pagenow, $taxnow;
  322. // Bail if topic-tags are off
  323. if ( ! bbp_allow_topic_tags() )
  324. return false;
  325. // Assume false
  326. $retval = false;
  327. // Check query
  328. if ( !empty( $wp_query->bbp_is_topic_tag_edit ) && ( true == $wp_query->bbp_is_topic_tag_edit ) )
  329. $retval = true;
  330. // Editing in admin
  331. elseif ( is_admin() && ( 'edit-tags.php' == $pagenow ) && ( bbp_get_topic_tag_tax_id() == $taxnow ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  332. $retval = true;
  333. return (bool) apply_filters( 'bbp_is_topic_tag_edit', $retval );
  334. }
  335. /**
  336. * Check if the current post type is one of bbPress's
  337. *
  338. * @since bbPress (r3311)
  339. *
  340. * @param mixed $the_post Optional. Post object or post ID.
  341. * @uses get_post_type()
  342. * @uses bbp_get_forum_post_type()
  343. * @uses bbp_get_topic_post_type()
  344. * @uses bbp_get_reply_post_type()
  345. *
  346. * @return bool
  347. */
  348. function bbp_is_custom_post_type( $the_post = false ) {
  349. // Assume false
  350. $retval = false;
  351. // Viewing one of the bbPress post types
  352. if ( in_array( get_post_type( $the_post ), array(
  353. bbp_get_forum_post_type(),
  354. bbp_get_topic_post_type(),
  355. bbp_get_reply_post_type()
  356. ) ) )
  357. $retval = true;
  358. return (bool) apply_filters( 'bbp_is_custom_post_type', $retval, $the_post );
  359. }
  360. /**
  361. * Check if current page is a bbPress reply
  362. *
  363. * @since bbPress (r2549)
  364. *
  365. * @param int $post_id Possible post_id to check
  366. * @uses bbp_get_reply_post_type() To get the reply post type
  367. * @uses get_post_type() To get the post type of the post id
  368. * @return bool True if it's a reply page, false if not
  369. */
  370. function bbp_is_reply( $post_id = 0 ) {
  371. // Assume false
  372. $retval = false;
  373. // Supplied ID is a reply
  374. if ( !empty( $post_id ) && ( bbp_get_reply_post_type() == get_post_type( $post_id ) ) )
  375. $retval = true;
  376. return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id );
  377. }
  378. /**
  379. * Check if current page is a reply edit page
  380. *
  381. * @since bbPress (r2753)
  382. *
  383. * @uses WP_Query Checks if WP_Query::bbp_is_reply_edit is true
  384. * @return bool True if it's the reply edit page, false if not
  385. */
  386. function bbp_is_reply_edit() {
  387. global $wp_query, $pagenow;
  388. // Assume false
  389. $retval = false;
  390. // Check query
  391. if ( !empty( $wp_query->bbp_is_reply_edit ) && ( true == $wp_query->bbp_is_reply_edit ) )
  392. $retval = true;
  393. // Editing in admin
  394. elseif ( is_admin() && ( 'post.php' == $pagenow ) && ( get_post_type() == bbp_get_reply_post_type() ) && ( !empty( $_GET['action'] ) && ( 'edit' == $_GET['action'] ) ) )
  395. $retval = true;
  396. return (bool) apply_filters( 'bbp_is_reply_edit', $retval );
  397. }
  398. /**
  399. * Check if current page is a reply move page
  400. *
  401. * @uses bbp_is_reply_move() To check if it's a reply move page
  402. * @return bool True if it's the reply move page, false if not
  403. */
  404. function bbp_is_reply_move() {
  405. // Assume false
  406. $retval = false;
  407. // Check reply edit and GET params
  408. if ( bbp_is_reply_edit() && !empty( $_GET['action'] ) && ( 'move' == $_GET['action'] ) )
  409. $retval = true;
  410. return (bool) apply_filters( 'bbp_is_reply_move', $retval );
  411. }
  412. /**
  413. * Viewing a single reply
  414. *
  415. * @since bbPress (r3344)
  416. *
  417. * @uses is_single()
  418. * @uses bbp_get_reply_post_type()
  419. * @uses get_post_type()
  420. * @uses apply_filters()
  421. *
  422. * @return bool
  423. */
  424. function bbp_is_single_reply() {
  425. // Assume false
  426. $retval = false;
  427. // Edit is not a single reply
  428. if ( bbp_is_reply_edit() )
  429. return false;
  430. // Single and a match
  431. if ( is_singular( bbp_get_reply_post_type() ) || ( bbp_is_query_name( 'bbp_single_reply' ) ) )
  432. $retval = true;
  433. return (bool) apply_filters( 'bbp_is_single_reply', $retval );
  434. }
  435. /**
  436. * Check if current page is a bbPress user's favorites page (profile page)
  437. *
  438. * @since bbPress (r2652)
  439. *
  440. * @return bool True if it's the favorites page, false if not
  441. */
  442. function bbp_is_favorites() {
  443. global $wp_query;
  444. // Assume false
  445. $retval = false;
  446. // Check query
  447. if ( !empty( $wp_query->bbp_is_single_user_favs ) && ( true == $wp_query->bbp_is_single_user_favs ) )
  448. $retval = true;
  449. return (bool) apply_filters( 'bbp_is_favorites', $retval );
  450. }
  451. /**
  452. * Check if current page is a bbPress user's subscriptions page (profile page)
  453. *
  454. * @since bbPress (r2652)
  455. *
  456. * @return bool True if it's the subscriptions page, false if not
  457. */
  458. function bbp_is_subscriptions() {
  459. global $wp_query;
  460. // Assume false
  461. $retval = false;
  462. // Check query
  463. if ( !empty( $wp_query->bbp_is_single_user_subs ) && ( true == $wp_query->bbp_is_single_user_subs ) )
  464. $retval = true;
  465. return (bool) apply_filters( 'bbp_is_subscriptions', $retval );
  466. }
  467. /**
  468. * Check if current page shows the topics created by a bbPress user (profile
  469. * page)
  470. *
  471. * @since bbPress (r2688)
  472. *
  473. * @return bool True if it's the topics created page, false if not
  474. */
  475. function bbp_is_topics_created() {
  476. global $wp_query;
  477. // Assume false
  478. $retval = false;
  479. // Check query
  480. if ( !empty( $wp_query->bbp_is_single_user_topics ) && ( true == $wp_query->bbp_is_single_user_topics ) )
  481. $retval = true;
  482. return (bool) apply_filters( 'bbp_is_topics_created', $retval );
  483. }
  484. /**
  485. * Check if current page shows the topics created by a bbPress user (profile
  486. * page)
  487. *
  488. * @since bbPress (r4225)
  489. *
  490. * @return bool True if it's the topics created page, false if not
  491. */
  492. function bbp_is_replies_created() {
  493. global $wp_query;
  494. // Assume false
  495. $retval = false;
  496. // Check query
  497. if ( !empty( $wp_query->bbp_is_single_user_replies ) && ( true == $wp_query->bbp_is_single_user_replies ) )
  498. $retval = true;
  499. return (bool) apply_filters( 'bbp_is_replies_created', $retval );
  500. }
  501. /**
  502. * Check if current page is the currently logged in users author page
  503. *
  504. * @since bbPress (r2688)
  505. * @uses bbp_is_single_user() Check query variable
  506. * @uses is_user_logged_in() Must be logged in to be home
  507. * @uses bbp_get_displayed_user_id()
  508. * @uses bbp_get_current_user_id()
  509. * @return bool True if it's the user's home, false if not
  510. */
  511. function bbp_is_user_home() {
  512. global $wp_query;
  513. // Assume false
  514. $retval = false;
  515. // Check query
  516. if ( !empty( $wp_query->bbp_is_single_user_home ) && ( true == $wp_query->bbp_is_single_user_home ) )
  517. $retval = true;
  518. return (bool) apply_filters( 'bbp_is_user_home', $retval );
  519. }
  520. /**
  521. * Check if current page is the currently logged in users author edit page
  522. *
  523. * @since bbPress (r3918)
  524. * @uses bbp_is_single_user_edit() Check query variable
  525. * @uses is_user_logged_in() Must be logged in to be home
  526. * @uses bbp_get_displayed_user_id()
  527. * @uses bbp_get_current_user_id()
  528. * @return bool True if it's the user's home, false if not
  529. */
  530. function bbp_is_user_home_edit() {
  531. // Assume false
  532. $retval = false;
  533. if ( bbp_is_user_home() && bbp_is_single_user_edit() )
  534. $retval = true;
  535. return (bool) apply_filters( 'bbp_is_user_home_edit', $retval );
  536. }
  537. /**
  538. * Check if current page is a user profile page
  539. *
  540. * @since bbPress (r2688)
  541. *
  542. * @uses WP_Query Checks if WP_Query::bbp_is_single_user is set to true
  543. * @return bool True if it's a user's profile page, false if not
  544. */
  545. function bbp_is_single_user() {
  546. global $wp_query;
  547. // Assume false
  548. $retval = false;
  549. // Check query
  550. if ( !empty( $wp_query->bbp_is_single_user ) && ( true == $wp_query->bbp_is_single_user ) )
  551. $retval = true;
  552. return (bool) apply_filters( 'bbp_is_single_user', $retval );
  553. }
  554. /**
  555. * Check if current page is a user profile edit page
  556. *
  557. * @since bbPress (r2688)
  558. *
  559. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_edit is set to true
  560. * @return bool True if it's a user's profile edit page, false if not
  561. */
  562. function bbp_is_single_user_edit() {
  563. global $wp_query;
  564. // Assume false
  565. $retval = false;
  566. // Check query
  567. if ( !empty( $wp_query->bbp_is_single_user_edit ) && ( true == $wp_query->bbp_is_single_user_edit ) )
  568. $retval = true;
  569. return (bool) apply_filters( 'bbp_is_single_user_edit', $retval );
  570. }
  571. /**
  572. * Check if current page is a user profile page
  573. *
  574. * @since bbPress (r4225)
  575. *
  576. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_profile is set to true
  577. * @return bool True if it's a user's profile page, false if not
  578. */
  579. function bbp_is_single_user_profile() {
  580. global $wp_query;
  581. // Assume false
  582. $retval = false;
  583. // Check query
  584. if ( !empty( $wp_query->bbp_is_single_user_profile ) && ( true == $wp_query->bbp_is_single_user_profile ) )
  585. $retval = true;
  586. return (bool) apply_filters( 'bbp_is_single_user_profile', $retval );
  587. }
  588. /**
  589. * Check if current page is a user topics created page
  590. *
  591. * @since bbPress (r4225)
  592. *
  593. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_topics is set to true
  594. * @return bool True if it's a user's topics page, false if not
  595. */
  596. function bbp_is_single_user_topics() {
  597. global $wp_query;
  598. // Assume false
  599. $retval = false;
  600. // Check query
  601. if ( !empty( $wp_query->bbp_is_single_user_topics ) && ( true == $wp_query->bbp_is_single_user_topics ) )
  602. $retval = true;
  603. return (bool) apply_filters( 'bbp_is_single_user_topics', $retval );
  604. }
  605. /**
  606. * Check if current page is a user replies created page
  607. *
  608. * @since bbPress (r4225)
  609. *
  610. * @uses WP_Query Checks if WP_Query::bbp_is_single_user_replies is set to true
  611. * @return bool True if it's a user's replies page, false if not
  612. */
  613. function bbp_is_single_user_replies() {
  614. global $wp_query;
  615. // Assume false
  616. $retval = false;
  617. // Check query
  618. if ( !empty( $wp_query->bbp_is_single_user_replies ) && ( true == $wp_query->bbp_is_single_user_replies ) )
  619. $retval = true;
  620. return (bool) apply_filters( 'bbp_is_single_user_replies', $retval );
  621. }
  622. /**
  623. * Check if current page is a view page
  624. *
  625. * @since bbPress (r2789)
  626. *
  627. * @global WP_Query $wp_query To check if WP_Query::bbp_is_view is true
  628. * @uses bbp_is_query_name() To get the query name
  629. * @return bool Is it a view page?
  630. */
  631. function bbp_is_single_view() {
  632. global $wp_query;
  633. // Assume false
  634. $retval = false;
  635. // Check query
  636. if ( !empty( $wp_query->bbp_is_view ) && ( true == $wp_query->bbp_is_view ) )
  637. $retval = true;
  638. // Check query name
  639. if ( empty( $retval ) && bbp_is_query_name( 'bbp_single_view' ) )
  640. $retval = true;
  641. return (bool) apply_filters( 'bbp_is_single_view', $retval );
  642. }
  643. /**
  644. * Check if current page is a search page
  645. *
  646. * @since bbPress (r4579)
  647. *
  648. * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true
  649. * @uses bbp_is_query_name() To get the query name
  650. * @return bool Is it a search page?
  651. */
  652. function bbp_is_search() {
  653. global $wp_query;
  654. // Assume false
  655. $retval = false;
  656. // Check query
  657. if ( !empty( $wp_query->bbp_is_search ) && ( true == $wp_query->bbp_is_search ) )
  658. $retval = true;
  659. // Check query name
  660. if ( empty( $retval ) && bbp_is_query_name( 'bbp_search' ) )
  661. $retval = true;
  662. // Check $_GET
  663. if ( empty( $retval ) && isset( $_GET[bbp_get_search_rewrite_id()] ) )
  664. $retval = true;
  665. return (bool) apply_filters( 'bbp_is_search', $retval );
  666. }
  667. /**
  668. * Check if current page is an edit page
  669. *
  670. * @since bbPress (r3585)
  671. *
  672. * @uses WP_Query Checks if WP_Query::bbp_is_edit is true
  673. * @return bool True if it's the edit page, false if not
  674. */
  675. function bbp_is_edit() {
  676. global $wp_query;
  677. // Assume false
  678. $retval = false;
  679. // Check query
  680. if ( !empty( $wp_query->bbp_is_edit ) && ( $wp_query->bbp_is_edit == true ) )
  681. $retval = true;
  682. return (bool) apply_filters( 'bbp_is_edit', $retval );
  683. }
  684. /**
  685. * Use the above is_() functions to output a body class for each scenario
  686. *
  687. * @since bbPress (r2926)
  688. *
  689. * @param array $wp_classes
  690. * @param array $custom_classes
  691. * @uses bbp_is_single_forum()
  692. * @uses bbp_is_single_topic()
  693. * @uses bbp_is_topic_edit()
  694. * @uses bbp_is_topic_merge()
  695. * @uses bbp_is_topic_split()
  696. * @uses bbp_is_single_reply()
  697. * @uses bbp_is_reply_edit()
  698. * @uses bbp_is_reply_move()
  699. * @uses bbp_is_single_view()
  700. * @uses bbp_is_single_user_edit()
  701. * @uses bbp_is_single_user()
  702. * @uses bbp_is_user_home()
  703. * @uses bbp_is_subscriptions()
  704. * @uses bbp_is_favorites()
  705. * @uses bbp_is_topics_created()
  706. * @uses bbp_is_forum_archive()
  707. * @uses bbp_is_topic_archive()
  708. * @uses bbp_is_topic_tag()
  709. * @uses bbp_is_topic_tag_edit()
  710. * @uses bbp_get_topic_tag_tax_id()
  711. * @uses bbp_get_topic_tag_slug()
  712. * @uses bbp_get_topic_tag_id()
  713. * @return array Body Classes
  714. */
  715. function bbp_body_class( $wp_classes, $custom_classes = false ) {
  716. $bbp_classes = array();
  717. /** Archives **************************************************************/
  718. if ( bbp_is_forum_archive() ) {
  719. $bbp_classes[] = bbp_get_forum_post_type() . '-archive';
  720. } elseif ( bbp_is_topic_archive() ) {
  721. $bbp_classes[] = bbp_get_topic_post_type() . '-archive';
  722. /** Topic Tags ************************************************************/
  723. } elseif ( bbp_is_topic_tag() ) {
  724. $bbp_classes[] = bbp_get_topic_tag_tax_id();
  725. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug();
  726. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id();
  727. } elseif ( bbp_is_topic_tag_edit() ) {
  728. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit';
  729. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit';
  730. $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id() . '-edit';
  731. /** Components ************************************************************/
  732. } elseif ( bbp_is_single_forum() ) {
  733. $bbp_classes[] = bbp_get_forum_post_type();
  734. } elseif ( bbp_is_single_topic() ) {
  735. $bbp_classes[] = bbp_get_topic_post_type();
  736. } elseif ( bbp_is_single_reply() ) {
  737. $bbp_classes[] = bbp_get_reply_post_type();
  738. } elseif ( bbp_is_topic_edit() ) {
  739. $bbp_classes[] = bbp_get_topic_post_type() . '-edit';
  740. } elseif ( bbp_is_topic_merge() ) {
  741. $bbp_classes[] = bbp_get_topic_post_type() . '-merge';
  742. } elseif ( bbp_is_topic_split() ) {
  743. $bbp_classes[] = bbp_get_topic_post_type() . '-split';
  744. } elseif ( bbp_is_reply_edit() ) {
  745. $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
  746. } elseif ( bbp_is_reply_move() ) {
  747. $bbp_classes[] = bbp_get_reply_post_type() . '-move';
  748. } elseif ( bbp_is_single_view() ) {
  749. $bbp_classes[] = 'bbp-view';
  750. /** User ******************************************************************/
  751. } elseif ( bbp_is_single_user_edit() ) {
  752. $bbp_classes[] = 'bbp-user-edit';
  753. $bbp_classes[] = 'single';
  754. $bbp_classes[] = 'singular';
  755. } elseif ( bbp_is_single_user() ) {
  756. $bbp_classes[] = 'bbp-user-page';
  757. $bbp_classes[] = 'single';
  758. $bbp_classes[] = 'singular';
  759. } elseif ( bbp_is_user_home() ) {
  760. $bbp_classes[] = 'bbp-user-home';
  761. $bbp_classes[] = 'single';
  762. $bbp_classes[] = 'singular';
  763. } elseif ( bbp_is_user_home_edit() ) {
  764. $bbp_classes[] = 'bbp-user-home-edit';
  765. $bbp_classes[] = 'single';
  766. $bbp_classes[] = 'singular';
  767. } elseif ( bbp_is_topics_created() ) {
  768. $bbp_classes[] = 'bbp-topics-created';
  769. $bbp_classes[] = 'single';
  770. $bbp_classes[] = 'singular';
  771. } elseif ( bbp_is_favorites() ) {
  772. $bbp_classes[] = 'bbp-favorites';
  773. $bbp_classes[] = 'single';
  774. $bbp_classes[] = 'singular';
  775. } elseif ( bbp_is_subscriptions() ) {
  776. $bbp_classes[] = 'bbp-subscriptions';
  777. $bbp_classes[] = 'single';
  778. $bbp_classes[] = 'singular';
  779. /** Search ****************************************************************/
  780. } elseif ( bbp_is_search() ) {
  781. $bbp_classes[] = 'bbp-search';
  782. $bbp_classes[] = 'forum-search';
  783. }
  784. /** Clean up **************************************************************/
  785. // Add bbPress class if we are within a bbPress page
  786. if ( !empty( $bbp_classes ) ) {
  787. $bbp_classes[] = 'bbpress';
  788. }
  789. // Merge WP classes with bbPress classes and remove any duplicates
  790. $classes = array_unique( array_merge( (array) $bbp_classes, (array) $wp_classes ) );
  791. // Deprecated filter (do not use)
  792. $classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
  793. return apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
  794. }
  795. /**
  796. * Use the above is_() functions to return if in any bbPress page
  797. *
  798. * @since bbPress (r3344)
  799. *
  800. * @uses bbp_is_single_forum()
  801. * @uses bbp_is_single_topic()
  802. * @uses bbp_is_topic_edit()
  803. * @uses bbp_is_topic_merge()
  804. * @uses bbp_is_topic_split()
  805. * @uses bbp_is_single_reply()
  806. * @uses bbp_is_reply_edit()
  807. * @uses bbp_is_reply_move()
  808. * @uses bbp_is_single_view()
  809. * @uses bbp_is_single_user_edit()
  810. * @uses bbp_is_single_user()
  811. * @uses bbp_is_user_home()
  812. * @uses bbp_is_subscriptions()
  813. * @uses bbp_is_favorites()
  814. * @uses bbp_is_topics_created()
  815. * @return bool In a bbPress page
  816. */
  817. function is_bbpress() {
  818. // Defalt to false
  819. $retval = false;
  820. /** Archives **************************************************************/
  821. if ( bbp_is_forum_archive() ) {
  822. $retval = true;
  823. } elseif ( bbp_is_topic_archive() ) {
  824. $retval = true;
  825. /** Topic Tags ************************************************************/
  826. } elseif ( bbp_is_topic_tag() ) {
  827. $retval = true;
  828. } elseif ( bbp_is_topic_tag_edit() ) {
  829. $retval = true;
  830. /** Components ************************************************************/
  831. } elseif ( bbp_is_single_forum() ) {
  832. $retval = true;
  833. } elseif ( bbp_is_single_topic() ) {
  834. $retval = true;
  835. } elseif ( bbp_is_single_reply() ) {
  836. $retval = true;
  837. } elseif ( bbp_is_topic_edit() ) {
  838. $retval = true;
  839. } elseif ( bbp_is_topic_merge() ) {
  840. $retval = true;
  841. } elseif ( bbp_is_topic_split() ) {
  842. $retval = true;
  843. } elseif ( bbp_is_reply_edit() ) {
  844. $retval = true;
  845. } elseif ( bbp_is_reply_move() ) {
  846. $retval = true;
  847. } elseif ( bbp_is_single_view() ) {
  848. $retval = true;
  849. /** User ******************************************************************/
  850. } elseif ( bbp_is_single_user_edit() ) {
  851. $retval = true;
  852. } elseif ( bbp_is_single_user() ) {
  853. $retval = true;
  854. } elseif ( bbp_is_user_home() ) {
  855. $retval = true;
  856. } elseif ( bbp_is_user_home_edit() ) {
  857. $retval = true;
  858. } elseif ( bbp_is_topics_created() ) {
  859. $retval = true;
  860. } elseif ( bbp_is_favorites() ) {
  861. $retval = true;
  862. } elseif ( bbp_is_subscriptions() ) {
  863. $retval = true;
  864. /** Search ****************************************************************/
  865. } elseif ( bbp_is_search() ) {
  866. $retval = true;
  867. }
  868. /** Done ******************************************************************/
  869. return (bool) apply_filters( 'is_bbpress', $retval );
  870. }
  871. /** Forms *********************************************************************/
  872. /**
  873. * Output the login form action url
  874. *
  875. * @since bbPress (r2815)
  876. *
  877. * @param string $url Pass a URL to redirect to
  878. * @uses add_query_arg() To add a arg to the url
  879. * @uses site_url() Toget the site url
  880. * @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args
  881. */
  882. function bbp_wp_login_action( $args = '' ) {
  883. // Parse arguments against default values
  884. $r = bbp_parse_args( $args, array(
  885. 'action' => '',
  886. 'context' => ''
  887. ), 'login_action' );
  888. // Add action as query arg
  889. if ( !empty( $r['action'] ) ) {
  890. $login_url = add_query_arg( array( 'action' => $r['action'] ), 'wp-login.php' );
  891. // No query arg
  892. } else {
  893. $login_url = 'wp-login.php';
  894. }
  895. $login_url = site_url( $login_url, $r['context'] );
  896. echo apply_filters( 'bbp_wp_login_action', $login_url, $r );
  897. }
  898. /**
  899. * Output hidden request URI field for user forms.
  900. *
  901. * The referer link is the current Request URI from the server super global. To
  902. * check the field manually, use bbp_get_redirect_to().
  903. *
  904. * @since bbPress (r2815)
  905. *
  906. * @param string $redirect_to Pass a URL to redirect to
  907. *
  908. * @uses wp_get_referer() To get the referer
  909. * @uses esc_attr() To escape the url
  910. * @uses apply_filters() Calls 'bbp_redirect_to_field', passes field and to
  911. */
  912. function bbp_redirect_to_field( $redirect_to = '' ) {
  913. // Make sure we are directing somewhere
  914. if ( empty( $redirect_to ) ) {
  915. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  916. $redirect_to = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  917. } else {
  918. $redirect_to = wp_get_referer();
  919. }
  920. }
  921. // Remove loggedout query arg if it's there
  922. $redirect_to = (string) esc_attr( remove_query_arg( 'loggedout', $redirect_to ) );
  923. $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . $redirect_to . '" />';
  924. echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to );
  925. }
  926. /**
  927. * Echo sanitized $_REQUEST value.
  928. *
  929. * Use the $input_type parameter to properly process the value. This
  930. * ensures correct sanitization of the value for the receiving input.
  931. *
  932. * @since bbPress (r2815)
  933. *
  934. * @param string $request Name of $_REQUEST to look for
  935. * @param string $input_type Type of input. Default: text. Accepts:
  936. * textarea|password|select|radio|checkbox
  937. * @uses bbp_get_sanitize_val() To sanitize the value.
  938. */
  939. function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
  940. echo bbp_get_sanitize_val( $request, $input_type );
  941. }
  942. /**
  943. * Return sanitized $_REQUEST value.
  944. *
  945. * Use the $input_type parameter to properly process the value. This
  946. * ensures correct sanitization of the value for the receiving input.
  947. *
  948. * @since bbPress (r2815)
  949. *
  950. * @param string $request Name of $_REQUEST to look for
  951. * @param string $input_type Type of input. Default: text. Accepts:
  952. * textarea|password|select|radio|checkbox
  953. * @uses esc_attr() To escape the string
  954. * @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized
  955. * value, request and input type
  956. * @return string Sanitized value ready for screen display
  957. */
  958. function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
  959. // Check that requested
  960. if ( empty( $_REQUEST[$request] ) )
  961. return false;
  962. // Set request varaible
  963. $pre_ret_val = $_REQUEST[$request];
  964. // Treat different kinds of fields in different ways
  965. switch ( $input_type ) {
  966. case 'text' :
  967. case 'textarea' :
  968. $retval = esc_attr( stripslashes( $pre_ret_val ) );
  969. break;
  970. case 'password' :
  971. case 'select' :
  972. case 'radio' :
  973. case 'checkbox' :
  974. default :
  975. $retval = esc_attr( $pre_ret_val );
  976. break;
  977. }
  978. return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
  979. }
  980. /**
  981. * Output the current tab index of a given form
  982. *
  983. * Use this function to handle the tab indexing of user facing forms within a
  984. * template file. Calling this function will automatically increment the global
  985. * tab index by default.
  986. *
  987. * @since bbPress (r2810)
  988. *
  989. * @param int $auto_increment Optional. Default true. Set to false to prevent
  990. * increment
  991. */
  992. function bbp_tab_index( $auto_increment = true ) {
  993. echo bbp_get_tab_index( $auto_increment );
  994. }
  995. /**
  996. * Output the current tab index of a given form
  997. *
  998. * Use this function to handle the tab indexing of user facing forms
  999. * within a template file. Calling this function will automatically
  1000. * increment the global tab index by default.
  1001. *
  1002. * @since bbPress (r2810)
  1003. *
  1004. * @uses apply_filters Allows return value to be filtered
  1005. * @param int $auto_increment Optional. Default true. Set to false to
  1006. * prevent the increment
  1007. * @return int $bbp->tab_index The global tab index
  1008. */
  1009. function bbp_get_tab_index( $auto_increment = true ) {
  1010. $bbp = bbpress();
  1011. if ( true === $auto_increment )
  1012. ++$bbp->tab_index;
  1013. return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
  1014. }
  1015. /**
  1016. * Output a select box allowing to pick which forum/topic a new topic/reply
  1017. * belongs in.
  1018. *
  1019. * Can be used for any post type, but is mostly used for topics and forums.
  1020. *
  1021. * @since bbPress (r2746)
  1022. *
  1023. * @param mixed $args See {@link bbp_get_dropdown()} for arguments
  1024. */
  1025. function bbp_dropdown( $args = '' ) {
  1026. echo bbp_get_dropdown( $args );
  1027. }
  1028. /**
  1029. * Output a select box allowing to pick which forum/topic a new
  1030. * topic/reply belongs in.
  1031. *
  1032. * @since bbPress (r2746)
  1033. *
  1034. * @param mixed $args The function supports these args:
  1035. * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
  1036. * - selected: Selected ID, to not have any value as selected, pass
  1037. * anything smaller than 0 (due to the nature of select
  1038. * box, the first value would of course be selected -
  1039. * though you can have that as none (pass 'show_none' arg))
  1040. * - sort_column: Sort by? Defaults to 'menu_order, post_title'
  1041. * - post_parent: Post parent. Defaults to 0
  1042. * - post_status: Which all post_statuses to find in? Can be an array
  1043. * or CSV of publish, category, closed, private, spam,
  1044. * trash (based on post type) - if not set, these are
  1045. * automatically determined based on the post_type
  1046. * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
  1047. * all posts
  1048. * - walker: Which walker to use? Defaults to
  1049. * {@link BBP_Walker_Dropdown}
  1050. * - select_id: ID of the select box. Defaults to 'bbp_forum_id'
  1051. * - tab: Tabindex value. False or integer
  1052. * - options_only: Show only <options>? No <select>?
  1053. * - show_none: False or something like __( '(No Forum)', 'bbpress' ),
  1054. * will have value=""
  1055. * - none_found: False or something like
  1056. * __( 'No forums to post to!', 'bbpress' )
  1057. * - disable_categories: Disable forum categories and closed forums?
  1058. * Defaults to true. Only for forums and when
  1059. * the category option is displayed.
  1060. * @uses BBP_Walker_Dropdown() As the default walker to generate the
  1061. * dropdown
  1062. * @uses current_user_can() To check if the current user can read
  1063. * private forums
  1064. * @uses bbp_get_forum_post_type() To get the forum post type
  1065. * @uses bbp_get_topic_post_type() To get the topic post type
  1066. * @uses walk_page_dropdown_tree() To generate the dropdown using the
  1067. * walker
  1068. * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
  1069. * and args
  1070. * @return string The dropdown
  1071. */
  1072. function bbp_get_dropdown( $args = '' ) {
  1073. /** Arguments *********************************************************/
  1074. // Parse arguments against default values
  1075. $r = bbp_parse_args( $args, array(
  1076. 'post_type' => bbp_get_forum_post_type(),
  1077. 'selected' => 0,
  1078. 'sort_column' => 'menu_order',
  1079. 'exclude' => array(),
  1080. 'post_parent' => null,
  1081. 'numberposts' => -1,
  1082. 'orderby' => 'menu_order',
  1083. 'order' => 'ASC',
  1084. 'walker' => '',
  1085. // Output-related
  1086. 'select_id' => 'bbp_forum_id',
  1087. 'tab' => bbp_get_tab_index(),
  1088. 'options_only' => false,
  1089. 'show_none' => false,
  1090. 'none_found' => false,
  1091. 'disable_categories' => true,
  1092. 'disabled' => ''
  1093. ), 'get_dropdown' );
  1094. if ( empty( $r['walker'] ) ) {
  1095. $r['walker'] = new BBP_Walker_Dropdown();
  1096. $r['walker']->tree_type = $r['post_type'];
  1097. }
  1098. // Force 0
  1099. if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) {
  1100. $r['selected'] = 0;
  1101. }
  1102. // Force array
  1103. if ( !empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) {
  1104. $r['exclude'] = explode( ',', $r['exclude'] );
  1105. }
  1106. /** Post Status *******************************************************/
  1107. // Define local variable(s)
  1108. $post_stati = array();
  1109. // Public
  1110. $post_stati[] = bbp_get_public_status_id();
  1111. // Forums
  1112. if ( bbp_get_forum_post_type() == $r['post_type'] ) {
  1113. // Private forums
  1114. if ( current_user_can( 'read_private_forums' ) ) {
  1115. $post_stati[] = bbp_get_private_status_id();
  1116. }
  1117. // Hidden forums
  1118. if ( current_user_can( 'read_hidden_forums' ) ) {
  1119. $post_stati[] = bbp_get_hidden_status_id();
  1120. }
  1121. }
  1122. // Setup the post statuses
  1123. $r['post_status'] = implode( ',', $post_stati );
  1124. /** Setup variables ***************************************************/
  1125. $name = esc_attr( $r['select_id'] );
  1126. $select_id = $name;
  1127. $tab = (int) $r['tab'];
  1128. $retval = '';
  1129. $disabled = disabled( isset( bbpress()->options[$r['disabled']] ), true, false );
  1130. $post_arr = array(
  1131. 'post_type' => $r['post_type'],
  1132. 'post_status' => $r['post_status'],
  1133. 'sort_column' => $r['sort_column'],
  1134. 'exclude' => $r['exclude'],
  1135. 'post_parent' => $r['post_parent'],
  1136. 'numberposts' => $r['numberposts'],
  1137. 'orderby' => $r['orderby'],
  1138. 'order' => $r['order'],
  1139. 'walker' => $r['walker'],
  1140. 'disable_categories' => $r['disable_categories']
  1141. );
  1142. $posts = get_posts( $post_arr );
  1143. /** Drop Down *********************************************************/
  1144. // Items found
  1145. if ( !empty( $posts ) ) {
  1146. if ( empty( $r['options_only'] ) ) {
  1147. $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
  1148. $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . $disabled . '>' . "\n";
  1149. }
  1150. $retval .= !empty( $r['show_none'] ) ? "\t<option value=\"\" class=\"level-0\">" . $r['show_none'] . '</option>' : '';
  1151. $retval .= walk_page_dropdown_tree( $posts, 0, $r );
  1152. if ( empty( $r['options_only'] ) ) {
  1153. $retval .= '</select>';
  1154. }
  1155. // No items found - Display feedback if no custom message was passed
  1156. } elseif ( empty( $r['none_found'] ) ) {
  1157. // Switch the response based on post type
  1158. switch ( $r['post_type'] ) {
  1159. // Topics
  1160. case bbp_get_topic_post_type() :
  1161. $retval = __( 'No topics available', 'bbpress' );
  1162. break;
  1163. // Forums
  1164. case bbp_get_forum_post_type() :
  1165. $retval = __( 'No forums available', 'bbpress' );
  1166. break;
  1167. // Any other
  1168. default :
  1169. $retval = __( 'None available', 'bbpress' );
  1170. break;
  1171. }
  1172. }
  1173. return apply_filters( 'bbp_get_dropdown', $retval, $r );
  1174. }
  1175. /**
  1176. * Output the required hidden fields when creating/editing a forum
  1177. *
  1178. * @since bbPress (r3553)
  1179. *
  1180. * @uses bbp_is_forum_edit() To check if it's the forum edit page
  1181. * @uses wp_nonce_field() To generate hidden nonce fields
  1182. * @uses bbp_forum_id() To output the forum id
  1183. * @uses bbp_is_single_forum() To check if it's a forum page
  1184. * @uses bbp_forum_id() To output the forum id
  1185. */
  1186. function bbp_forum_form_fields() {
  1187. if ( bbp_is_forum_edit() ) : ?>
  1188. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-forum" />
  1189. <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
  1190. <?php
  1191. if ( current_user_can( 'unfiltered_html' ) )
  1192. wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false );
  1193. ?>
  1194. <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() );
  1195. else :
  1196. if ( bbp_is_single_forum() ) : ?>
  1197. <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" />
  1198. <?php endif; ?>
  1199. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" />
  1200. <?php
  1201. if ( current_user_can( 'unfiltered_html' ) )
  1202. wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false );
  1203. ?>
  1204. <?php wp_nonce_field( 'bbp-new-forum' );
  1205. endif;
  1206. }
  1207. /**
  1208. * Output the required hidden fields when creating/editing a topic
  1209. *
  1210. * @since bbPress (r2753)
  1211. *
  1212. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  1213. * @uses wp_nonce_field() To generate hidden nonce fields
  1214. * @uses bbp_topic_id() To output the topic id
  1215. * @uses bbp_is_single_forum() To check if it's a forum page
  1216. * @uses bbp_forum_id() To output the forum id
  1217. */
  1218. function bbp_topic_form_fields() {
  1219. if ( bbp_is_topic_edit() ) : ?>
  1220. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" />
  1221. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
  1222. <?php
  1223. if ( current_user_can( 'unfiltered_html' ) )
  1224. wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
  1225. ?>
  1226. <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
  1227. else :
  1228. if ( bbp_is_single_forum() ) : ?>
  1229. <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
  1230. <?php endif; ?>
  1231. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
  1232. <?php if ( current_user_can( 'unfiltered_html' ) )
  1233. wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false ); ?>
  1234. <?php wp_nonce_field( 'bbp-new-topic' );
  1235. endif;
  1236. }
  1237. /**
  1238. * Output the required hidden fields when creating/editing a reply
  1239. *
  1240. * @since bbPress (r2753)
  1241. *
  1242. * @uses bbp_is_reply_edit() To check if it's the reply edit page
  1243. * @uses wp_nonce_field() To generate hidden nonce fields
  1244. * @uses bbp_reply_id() To output the reply id
  1245. * @uses bbp_topic_id() To output the topic id
  1246. * @uses bbp_forum_id() To output the forum id
  1247. */
  1248. function bbp_reply_form_fields() {
  1249. if ( bbp_is_reply_edit() ) : ?>
  1250. <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php bbp_reply_title(); ?>" />
  1251. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" />
  1252. <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" />
  1253. <?php if ( current_user_can( 'unfiltered_html' ) )
  1254. wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false ); ?>
  1255. <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
  1256. else : ?>
  1257. <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" />
  1258. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
  1259. <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" />
  1260. <?php if ( current_user_can( 'unfiltered_html' ) )
  1261. wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false ); ?>
  1262. <?php wp_nonce_field( 'bbp-new-reply' );
  1263. // Show redirect field if not viewing a specific topic
  1264. if ( bbp_is_query_name( 'bbp_single_topic' ) ) :
  1265. bbp_redirect_to_field( get_permalink() );
  1266. endif;
  1267. endif;
  1268. }
  1269. /**
  1270. * Output the required hidden fields when editing a user
  1271. *
  1272. * @since bbPress (r2690)
  1273. *
  1274. * @uses bbp_displayed_user_id() To output the displayed user id
  1275. * @uses wp_nonce_field() To generate a hidden nonce field
  1276. * @uses wp_referer_field() To generate a hidden referer field
  1277. */
  1278. function bbp_edit_user_form_fields() {
  1279. ?>
  1280. <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" />
  1281. <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" />
  1282. <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
  1283. }
  1284. /**
  1285. * Merge topic form fields
  1286. *
  1287. * Output the required hidden fields when merging a topic
  1288. *
  1289. * @since bbPress (r2756)
  1290. *
  1291. * @uses wp_nonce_field() To generate a hidden nonce field
  1292. * @uses bbp_topic_id() To output the topic id
  1293. */
  1294. function bbp_merge_topic_form_fields() {
  1295. ?>
  1296. <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" />
  1297. <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
  1298. <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
  1299. }
  1300. /**
  1301. * Split topic form fields
  1302. *
  1303. * Output the required hidden fields when splitting a topic
  1304. *
  1305. * @since bbPress (r2756)
  1306. *
  1307. * @uses wp_nonce_field() To generate a hidden nonce field
  1308. */
  1309. function bbp_split_topic_form_fields() {
  1310. ?>
  1311. <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" />
  1312. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
  1313. <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
  1314. }
  1315. /**
  1316. * Move reply form fields
  1317. *
  1318. * Output the required hidden fields when moving a reply
  1319. *
  1320. * @uses wp_nonce_field() To generate a hidden nonce field
  1321. */
  1322. function bbp_move_reply_form_fields() {
  1323. ?>
  1324. <input type="hidden" name="action" id="bbp_post_action" value="bbp-move-reply" />
  1325. <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
  1326. <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() );
  1327. }
  1328. /**
  1329. * Output a textarea or TinyMCE if enabled
  1330. *
  1331. * @since bbPress (r3586)
  1332. *
  1333. * @param array $args
  1334. * @uses bbp_get_the_content() To return the content to output
  1335. */
  1336. function bbp_the_content( $args = array() ) {
  1337. echo bbp_get_the_content( $args );
  1338. }
  1339. /**
  1340. * Return a textarea or TinyMCE if enabled
  1341. *
  1342. * @since bbPress (r3586)
  1343. *
  1344. * @param array $args
  1345. *
  1346. * @uses apply_filter() To filter args and output
  1347. * @uses wp_parse_pargs() To compare args
  1348. * @uses bbp_use_wp_editor() To see if WP editor is in use
  1349. * @uses bbp_is_edit() To see if we are editing something
  1350. * @uses wp_editor() To output the WordPress editor
  1351. *
  1352. * @return string HTML from output buffer
  1353. */
  1354. function bbp_get_the_content( $args = array() ) {
  1355. // Parse arguments against default values
  1356. $r = bbp_parse_args( $args, array(
  1357. 'context' => 'topic',
  1358. 'before' => '<div class="bbp-the-content-wrapper">',
  1359. 'after' => '</div>',
  1360. 'wpautop' => true,
  1361. 'media_buttons' => false,
  1362. 'textarea_rows' => '12',
  1363. 'tabindex' => bbp_get_tab_index(),
  1364. 'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags',
  1365. 'editor_class' => 'bbp-the-content',
  1366. 'tinymce' => false,
  1367. 'teeny' => true,
  1368. 'quicktags' => true,
  1369. 'dfw' => false
  1370. ), 'get_the_content' );
  1371. // If using tinymce, remove our escaping and trust tinymce
  1372. if ( bbp_use_wp_editor() && ( true === $r['tinymce'] ) ) {
  1373. remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
  1374. remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
  1375. remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
  1376. }
  1377. // Assume we are not editing
  1378. $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' );
  1379. // Start an output buffor
  1380. ob_start();
  1381. // Output something before the editor
  1382. if ( !empty( $r['before'] ) ) {
  1383. echo $r['before'];
  1384. }
  1385. // Use TinyMCE if available
  1386. if ( bbp_use_wp_editor() ) :
  1387. // Enable additional TinyMCE plugins before outputting the editor
  1388. add_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1389. add_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1390. add_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
  1391. add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
  1392. // Output the editor
  1393. wp_editor( $post_content, 'bbp_' . $r['context'] . '_content', array(
  1394. 'wpautop' => $r['wpautop'],
  1395. 'media_buttons' => $r['media_buttons'],
  1396. 'textarea_rows' => $r['textarea_rows'],
  1397. 'tabindex' => $r['tabindex'],
  1398. 'tabfocus_elements' => $r['tabfocus_elements'],
  1399. 'editor_class' => $r['editor_class'],
  1400. 'tinymce' => $r['tinymce'],
  1401. 'teeny' => $r['teeny'],
  1402. 'quicktags' => $r['quicktags'],
  1403. 'dfw' => $r['dfw'],
  1404. ) );
  1405. // Remove additional TinyMCE plugins after outputting the editor
  1406. remove_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1407. remove_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
  1408. remove_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
  1409. remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
  1410. /**
  1411. * Fallback to normal textarea.
  1412. *
  1413. * Note that we do not use esc_textarea() here to prevent double
  1414. * escaping the editable output, mucking up existing content.
  1415. */
  1416. else : ?>
  1417. <textarea id="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" class="<?php echo esc_attr( $r['editor_class'] ); ?>" name="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" cols="60" rows="<?php echo esc_attr( $r['textarea_rows'] ); ?>" tabindex="<?php echo esc_attr( $r['tabindex'] ); ?>"><?php echo $post_content; ?></textarea>
  1418. <?php endif;
  1419. // Output something after the editor
  1420. if ( !empty( $r['after'] ) ) {
  1421. echo $r['after'];
  1422. }
  1423. // Put the output into a usable variable
  1424. $output = ob_get_contents();
  1425. // Flush the output buffer
  1426. ob_end_clean();
  1427. return apply_filters( 'bbp_get_the_content', $output, $args, $post_content );
  1428. }
  1429. /**
  1430. * Edit TinyMCE plugins to match core behaviour
  1431. *
  1432. * @since bbPress (r4574)
  1433. *
  1434. * @param array $plugins
  1435. * @see tiny_mce_plugins, teeny_mce_plugins
  1436. * @return array
  1437. */
  1438. function bbp_get_tiny_mce_plugins( $plugins = array() ) {
  1439. // Unset fullscreen
  1440. foreach ( $plugins as $key => $value ) {
  1441. if ( 'fullscreen' == $value ) {
  1442. unset( $plugins[$key] );
  1443. break;
  1444. }
  1445. }
  1446. // Add the tabfocus plugin
  1447. $plugins[] = 'tabfocus';
  1448. return

Large files files are truncated, but you can click here to view the full file