PageRenderTime 31ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/bbpress/includes/forums/template.php

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 2672 lines | 951 code | 333 blank | 1388 comment | 150 complexity | 8368e3a7657f9af01d56a3c26a955af5 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. * bbPress Forum Template Tags
  4. *
  5. * @package bbPress
  6. * @subpackage TemplateTags
  7. */
  8. // Exit if accessed directly
  9. if ( !defined( 'ABSPATH' ) ) exit;
  10. /** Post Type *****************************************************************/
  11. /**
  12. * Output the unique id of the custom post type for forums
  13. *
  14. * @since bbPress (r2857)
  15. * @uses bbp_get_forum_post_type() To get the forum post type
  16. */
  17. function bbp_forum_post_type() {
  18. echo bbp_get_forum_post_type();
  19. }
  20. /**
  21. * Return the unique id of the custom post type for forums
  22. *
  23. * @since bbPress (r2857)
  24. *
  25. * @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum
  26. * post type id
  27. * @return string The unique forum post type id
  28. */
  29. function bbp_get_forum_post_type() {
  30. return apply_filters( 'bbp_get_forum_post_type', bbpress()->forum_post_type );
  31. }
  32. /**
  33. * Return array of labels used by the forum post type
  34. *
  35. * @since bbPress (r5129)
  36. *
  37. * @return array
  38. */
  39. function bbp_get_forum_post_type_labels() {
  40. return apply_filters( 'bbp_get_forum_post_type_labels', array(
  41. 'name' => __( 'Forums', 'bbpress' ),
  42. 'menu_name' => __( 'Forums', 'bbpress' ),
  43. 'singular_name' => __( 'Forum', 'bbpress' ),
  44. 'all_items' => __( 'All Forums', 'bbpress' ),
  45. 'add_new' => __( 'New Forum', 'bbpress' ),
  46. 'add_new_item' => __( 'Create New Forum', 'bbpress' ),
  47. 'edit' => __( 'Edit', 'bbpress' ),
  48. 'edit_item' => __( 'Edit Forum', 'bbpress' ),
  49. 'new_item' => __( 'New Forum', 'bbpress' ),
  50. 'view' => __( 'View Forum', 'bbpress' ),
  51. 'view_item' => __( 'View Forum', 'bbpress' ),
  52. 'search_items' => __( 'Search Forums', 'bbpress' ),
  53. 'not_found' => __( 'No forums found', 'bbpress' ),
  54. 'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ),
  55. 'parent_item_colon' => __( 'Parent Forum:', 'bbpress' )
  56. ) );
  57. }
  58. /**
  59. * Return array of forum post type rewrite settings
  60. *
  61. * @since bbPress (r5129)
  62. *
  63. * @return array
  64. */
  65. function bbp_get_forum_post_type_rewrite() {
  66. return apply_filters( 'bbp_get_forum_post_type_rewrite', array(
  67. 'slug' => bbp_get_forum_slug(),
  68. 'with_front' => false
  69. ) );
  70. }
  71. /**
  72. * Return array of features the forum post type supports
  73. *
  74. * @since bbPress (r5129)
  75. *
  76. * @return array
  77. */
  78. function bbp_get_forum_post_type_supports() {
  79. return apply_filters( 'bbp_get_forum_post_type_supports', array(
  80. 'title',
  81. 'editor',
  82. 'revisions'
  83. ) );
  84. }
  85. /** Forum Loop ****************************************************************/
  86. /**
  87. * The main forum loop.
  88. *
  89. * WordPress makes this easy for us.
  90. *
  91. * @since bbPress (r2464)
  92. *
  93. * @param mixed $args All the arguments supported by {@link WP_Query}
  94. * @uses WP_Query To make query and get the forums
  95. * @uses bbp_get_forum_post_type() To get the forum post type id
  96. * @uses bbp_get_forum_id() To get the forum id
  97. * @uses get_option() To get the forums per page option
  98. * @uses current_user_can() To check if the current user is capable of editing
  99. * others' forums
  100. * @uses apply_filters() Calls 'bbp_has_forums' with
  101. * bbPres::forum_query::have_posts()
  102. * and bbPres::forum_query
  103. * @return object Multidimensional array of forum information
  104. */
  105. function bbp_has_forums( $args = '' ) {
  106. // Forum archive only shows root
  107. if ( bbp_is_forum_archive() ) {
  108. $default_post_parent = 0;
  109. // User subscriptions shows any
  110. } elseif ( bbp_is_subscriptions() ) {
  111. $default_post_parent = 'any';
  112. // Could be anything, so look for possible parent ID
  113. } else {
  114. $default_post_parent = bbp_get_forum_id();
  115. }
  116. // Parse arguments with default forum query for most circumstances
  117. $bbp_f = bbp_parse_args( $args, array(
  118. 'post_type' => bbp_get_forum_post_type(),
  119. 'post_parent' => $default_post_parent,
  120. 'post_status' => bbp_get_public_status_id(),
  121. 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
  122. 'ignore_sticky_posts' => true,
  123. 'orderby' => 'menu_order title',
  124. 'order' => 'ASC'
  125. ), 'has_forums' );
  126. // Run the query
  127. $bbp = bbpress();
  128. $bbp->forum_query = new WP_Query( $bbp_f );
  129. return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
  130. }
  131. /**
  132. * Whether there are more forums available in the loop
  133. *
  134. * @since bbPress (r2464)
  135. *
  136. * @uses bbPress:forum_query::have_posts() To check if there are more forums
  137. * available
  138. * @return object Forum information
  139. */
  140. function bbp_forums() {
  141. // Put into variable to check against next
  142. $have_posts = bbpress()->forum_query->have_posts();
  143. // Reset the post data when finished
  144. if ( empty( $have_posts ) )
  145. wp_reset_postdata();
  146. return $have_posts;
  147. }
  148. /**
  149. * Loads up the current forum in the loop
  150. *
  151. * @since bbPress (r2464)
  152. *
  153. * @uses bbPress:forum_query::the_post() To get the current forum
  154. * @return object Forum information
  155. */
  156. function bbp_the_forum() {
  157. return bbpress()->forum_query->the_post();
  158. }
  159. /** Forum *********************************************************************/
  160. /**
  161. * Output forum id
  162. *
  163. * @since bbPress (r2464)
  164. *
  165. * @param $forum_id Optional. Used to check emptiness
  166. * @uses bbp_get_forum_id() To get the forum id
  167. */
  168. function bbp_forum_id( $forum_id = 0 ) {
  169. echo bbp_get_forum_id( $forum_id );
  170. }
  171. /**
  172. * Return the forum id
  173. *
  174. * @since bbPress (r2464)
  175. *
  176. * @param $forum_id Optional. Used to check emptiness
  177. * @uses bbPress::forum_query::in_the_loop To check if we're in the loop
  178. * @uses bbPress::forum_query::post::ID To get the forum id
  179. * @uses WP_Query::post::ID To get the forum id
  180. * @uses bbp_is_forum() To check if the search result is a forum
  181. * @uses bbp_is_single_forum() To check if it's a forum page
  182. * @uses bbp_is_single_topic() To check if it's a topic page
  183. * @uses bbp_get_topic_forum_id() To get the topic forum id
  184. * @uses get_post_field() To get the post's post type
  185. * @uses apply_filters() Calls 'bbp_get_forum_id' with the forum id and
  186. * supplied forum id
  187. * @return int The forum id
  188. */
  189. function bbp_get_forum_id( $forum_id = 0 ) {
  190. global $wp_query;
  191. $bbp = bbpress();
  192. // Easy empty checking
  193. if ( !empty( $forum_id ) && is_numeric( $forum_id ) ) {
  194. $bbp_forum_id = $forum_id;
  195. // Currently inside a forum loop
  196. } elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
  197. $bbp_forum_id = $bbp->forum_query->post->ID;
  198. // Currently inside a search loop
  199. } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
  200. $bbp_forum_id = $bbp->search_query->post->ID;
  201. // Currently viewing a forum
  202. } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && !empty( $bbp->current_forum_id ) ) {
  203. $bbp_forum_id = $bbp->current_forum_id;
  204. // Currently viewing a forum
  205. } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) {
  206. $bbp_forum_id = $wp_query->post->ID;
  207. // Currently viewing a topic
  208. } elseif ( bbp_is_single_topic() ) {
  209. $bbp_forum_id = bbp_get_topic_forum_id();
  210. // Fallback
  211. } else {
  212. $bbp_forum_id = 0;
  213. }
  214. return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
  215. }
  216. /**
  217. * Gets a forum
  218. *
  219. * @since bbPress (r2787)
  220. *
  221. * @param int|object $forum forum id or forum object
  222. * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
  223. * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
  224. * @uses get_post() To get the forum
  225. * @uses apply_filters() Calls 'bbp_get_forum' with the forum, output type and
  226. * sanitation filter
  227. * @return mixed Null if error or forum (in specified form) if success
  228. */
  229. function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
  230. // Use forum ID
  231. if ( empty( $forum ) || is_numeric( $forum ) )
  232. $forum = bbp_get_forum_id( $forum );
  233. // Attempt to load the forum
  234. $forum = get_post( $forum, OBJECT, $filter );
  235. if ( empty( $forum ) )
  236. return $forum;
  237. // Bail if post_type is not a forum
  238. if ( $forum->post_type !== bbp_get_forum_post_type() )
  239. return null;
  240. // Tweak the data type to return
  241. if ( $output === OBJECT ) {
  242. return $forum;
  243. } elseif ( $output === ARRAY_A ) {
  244. $_forum = get_object_vars( $forum );
  245. return $_forum;
  246. } elseif ( $output === ARRAY_N ) {
  247. $_forum = array_values( get_object_vars( $forum ) );
  248. return $_forum;
  249. }
  250. return apply_filters( 'bbp_get_forum', $forum, $output, $filter );
  251. }
  252. /**
  253. * Output the link to the forum
  254. *
  255. * @since bbPress (r2464)
  256. *
  257. * @param int $forum_id Optional. Forum id
  258. * @uses bbp_get_forum_permalink() To get the permalink
  259. */
  260. function bbp_forum_permalink( $forum_id = 0 ) {
  261. echo esc_url( bbp_get_forum_permalink( $forum_id ) );
  262. }
  263. /**
  264. * Return the link to the forum
  265. *
  266. * @since bbPress (r2464)
  267. *
  268. * @param int $forum_id Optional. Forum id
  269. * @param $string $redirect_to Optional. Pass a redirect value for use with
  270. * shortcodes and other fun things.
  271. * @uses bbp_get_forum_id() To get the forum id
  272. * @uses get_permalink() Get the permalink of the forum
  273. * @uses apply_filters() Calls 'bbp_get_forum_permalink' with the forum
  274. * link
  275. * @return string Permanent link to forum
  276. */
  277. function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
  278. $forum_id = bbp_get_forum_id( $forum_id );
  279. // Use the redirect address
  280. if ( !empty( $redirect_to ) ) {
  281. $forum_permalink = esc_url_raw( $redirect_to );
  282. // Use the topic permalink
  283. } else {
  284. $forum_permalink = get_permalink( $forum_id );
  285. }
  286. return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id );
  287. }
  288. /**
  289. * Output the title of the forum
  290. *
  291. * @since bbPress (r2464)
  292. *
  293. * @param int $forum_id Optional. Forum id
  294. * @uses bbp_get_forum_title() To get the forum title
  295. */
  296. function bbp_forum_title( $forum_id = 0 ) {
  297. echo bbp_get_forum_title( $forum_id );
  298. }
  299. /**
  300. * Return the title of the forum
  301. *
  302. * @since bbPress (r2464)
  303. *
  304. * @param int $forum_id Optional. Forum id
  305. * @uses bbp_get_forum_id() To get the forum id
  306. * @uses get_the_title() To get the forum title
  307. * @uses apply_filters() Calls 'bbp_get_forum_title' with the title
  308. * @return string Title of forum
  309. */
  310. function bbp_get_forum_title( $forum_id = 0 ) {
  311. $forum_id = bbp_get_forum_id( $forum_id );
  312. $title = get_the_title( $forum_id );
  313. return apply_filters( 'bbp_get_forum_title', $title, $forum_id );
  314. }
  315. /**
  316. * Output the forum archive title
  317. *
  318. * @since bbPress (r3249)
  319. *
  320. * @param string $title Default text to use as title
  321. */
  322. function bbp_forum_archive_title( $title = '' ) {
  323. echo bbp_get_forum_archive_title( $title );
  324. }
  325. /**
  326. * Return the forum archive title
  327. *
  328. * @since bbPress (r3249)
  329. *
  330. * @param string $title Default text to use as title
  331. *
  332. * @uses bbp_get_page_by_path() Check if page exists at root path
  333. * @uses get_the_title() Use the page title at the root path
  334. * @uses get_post_type_object() Load the post type object
  335. * @uses bbp_get_forum_post_type() Get the forum post type ID
  336. * @uses get_post_type_labels() Get labels for forum post type
  337. * @uses apply_filters() Allow output to be manipulated
  338. *
  339. * @return string The forum archive title
  340. */
  341. function bbp_get_forum_archive_title( $title = '' ) {
  342. // If no title was passed
  343. if ( empty( $title ) ) {
  344. // Set root text to page title
  345. $page = bbp_get_page_by_path( bbp_get_root_slug() );
  346. if ( !empty( $page ) ) {
  347. $title = get_the_title( $page->ID );
  348. // Default to forum post type name label
  349. } else {
  350. $fto = get_post_type_object( bbp_get_forum_post_type() );
  351. $title = $fto->labels->name;
  352. }
  353. }
  354. return apply_filters( 'bbp_get_forum_archive_title', $title );
  355. }
  356. /**
  357. * Output the content of the forum
  358. *
  359. * @since bbPress (r2780)
  360. *
  361. * @param int $forum_id Optional. Topic id
  362. * @uses bbp_get_forum_content() To get the forum content
  363. */
  364. function bbp_forum_content( $forum_id = 0 ) {
  365. echo bbp_get_forum_content( $forum_id );
  366. }
  367. /**
  368. * Return the content of the forum
  369. *
  370. * @since bbPress (r2780)
  371. *
  372. * @param int $forum_id Optional. Topic id
  373. * @uses bbp_get_forum_id() To get the forum id
  374. * @uses post_password_required() To check if the forum requires pass
  375. * @uses get_the_password_form() To get the password form
  376. * @uses get_post_field() To get the content post field
  377. * @uses apply_filters() Calls 'bbp_get_forum_content' with the content
  378. * and forum id
  379. * @return string Content of the forum
  380. */
  381. function bbp_get_forum_content( $forum_id = 0 ) {
  382. $forum_id = bbp_get_forum_id( $forum_id );
  383. // Check if password is required
  384. if ( post_password_required( $forum_id ) )
  385. return get_the_password_form();
  386. $content = get_post_field( 'post_content', $forum_id );
  387. return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
  388. }
  389. /**
  390. * Allow forum rows to have adminstrative actions
  391. *
  392. * @since bbPress (r3653)
  393. * @uses do_action()
  394. * @todo Links and filter
  395. */
  396. function bbp_forum_row_actions() {
  397. do_action( 'bbp_forum_row_actions' );
  398. }
  399. /**
  400. * Output the forums last active ID
  401. *
  402. * @since bbPress (r2860)
  403. *
  404. * @uses bbp_get_forum_last_active_id() To get the forum's last active id
  405. * @param int $forum_id Optional. Forum id
  406. */
  407. function bbp_forum_last_active_id( $forum_id = 0 ) {
  408. echo bbp_get_forum_last_active_id( $forum_id );
  409. }
  410. /**
  411. * Return the forums last active ID
  412. *
  413. * @since bbPress (r2860)
  414. *
  415. * @param int $forum_id Optional. Forum id
  416. * @uses bbp_get_forum_id() To get the forum id
  417. * @uses get_post_meta() To get the forum's last active id
  418. * @uses apply_filters() Calls 'bbp_get_forum_last_active_id' with
  419. * the last active id and forum id
  420. * @return int Forum's last active id
  421. */
  422. function bbp_get_forum_last_active_id( $forum_id = 0 ) {
  423. $forum_id = bbp_get_forum_id( $forum_id );
  424. $active_id = get_post_meta( $forum_id, '_bbp_last_active_id', true );
  425. return (int) apply_filters( 'bbp_get_forum_last_active_id', (int) $active_id, $forum_id );
  426. }
  427. /**
  428. * Output the forums last update date/time (aka freshness)
  429. *
  430. * @since bbPress (r2464)
  431. *
  432. * @uses bbp_get_forum_last_active_time() To get the forum freshness
  433. * @param int $forum_id Optional. Forum id
  434. */
  435. function bbp_forum_last_active_time( $forum_id = 0 ) {
  436. echo bbp_get_forum_last_active_time( $forum_id );
  437. }
  438. /**
  439. * Return the forums last update date/time (aka freshness)
  440. *
  441. * @since bbPress (r2464)
  442. *
  443. * @param int $forum_id Optional. Forum id
  444. * @uses bbp_get_forum_id() To get the forum id
  445. * @uses get_post_meta() To retrieve forum last active meta
  446. * @uses bbp_get_forum_last_reply_id() To get forum's last reply id
  447. * @uses get_post_field() To get the post date of the reply
  448. * @uses bbp_get_forum_last_topic_id() To get forum's last topic id
  449. * @uses bbp_get_topic_last_active_time() To get time when the topic was
  450. * last active
  451. * @uses bbp_convert_date() To convert the date
  452. * @uses bbp_get_time_since() To get time in since format
  453. * @uses apply_filters() Calls 'bbp_get_forum_last_active' with last
  454. * active time and forum id
  455. * @return string Forum last update date/time (freshness)
  456. */
  457. function bbp_get_forum_last_active_time( $forum_id = 0 ) {
  458. // Verify forum and get last active meta
  459. $forum_id = bbp_get_forum_id( $forum_id );
  460. $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
  461. if ( empty( $last_active ) ) {
  462. $reply_id = bbp_get_forum_last_reply_id( $forum_id );
  463. if ( !empty( $reply_id ) ) {
  464. $last_active = get_post_field( 'post_date', $reply_id );
  465. } else {
  466. $topic_id = bbp_get_forum_last_topic_id( $forum_id );
  467. if ( !empty( $topic_id ) ) {
  468. $last_active = bbp_get_topic_last_active_time( $topic_id );
  469. }
  470. }
  471. }
  472. $active_time = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
  473. return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id );
  474. }
  475. /**
  476. * Output link to the most recent activity inside a forum.
  477. *
  478. * Outputs a complete link with attributes and content.
  479. *
  480. * @since bbPress (r2625)
  481. *
  482. * @param int $forum_id Optional. Forum id
  483. * @uses bbp_get_forum_freshness_link() To get the forum freshness link
  484. */
  485. function bbp_forum_freshness_link( $forum_id = 0) {
  486. echo bbp_get_forum_freshness_link( $forum_id );
  487. }
  488. /**
  489. * Returns link to the most recent activity inside a forum.
  490. *
  491. * Returns a complete link with attributes and content.
  492. *
  493. * @since bbPress (r2625)
  494. *
  495. * @param int $forum_id Optional. Forum id
  496. * @uses bbp_get_forum_id() To get the forum id
  497. * @uses bbp_get_forum_last_active_id() To get the forum last active id
  498. * @uses bbp_get_forum_last_reply_id() To get the forum last reply id
  499. * @uses bbp_get_forum_last_topic_id() To get the forum last topic id
  500. * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
  501. * @uses bbp_get_forum_last_reply_title() To get the forum last reply
  502. * title
  503. * @uses bbp_get_forum_last_topic_permalink() To get the forum last
  504. * topic permalink
  505. * @uses bbp_get_forum_last_topic_title() To get the forum last topic
  506. * title
  507. * @uses bbp_get_forum_last_active_time() To get the time when the forum
  508. * was last active
  509. * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the
  510. * link and forum id
  511. */
  512. function bbp_get_forum_freshness_link( $forum_id = 0 ) {
  513. $forum_id = bbp_get_forum_id( $forum_id );
  514. $active_id = bbp_get_forum_last_active_id( $forum_id );
  515. $link_url = $title = '';
  516. if ( empty( $active_id ) )
  517. $active_id = bbp_get_forum_last_reply_id( $forum_id );
  518. if ( empty( $active_id ) )
  519. $active_id = bbp_get_forum_last_topic_id( $forum_id );
  520. if ( bbp_is_topic( $active_id ) ) {
  521. $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
  522. $title = bbp_get_forum_last_topic_title( $forum_id );
  523. } elseif ( bbp_is_reply( $active_id ) ) {
  524. $link_url = bbp_get_forum_last_reply_url( $forum_id );
  525. $title = bbp_get_forum_last_reply_title( $forum_id );
  526. }
  527. $time_since = bbp_get_forum_last_active_time( $forum_id );
  528. if ( !empty( $time_since ) && !empty( $link_url ) ) {
  529. $anchor = '<a class="lastMessageTitle" href="' . esc_url( $link_url ) . '">' . esc_attr( $title ) . '</a>';
  530. $anchor .= '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
  531. }
  532. else
  533. $anchor = esc_html__( 'No Topics', 'bbpress' );
  534. return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id );
  535. }
  536. /**
  537. * Output parent ID of a forum, if exists
  538. *
  539. * @since bbPress (r3675)
  540. *
  541. * @param int $forum_id Forum ID
  542. * @uses bbp_get_forum_parent_id() To get the forum's parent ID
  543. */
  544. function bbp_forum_parent_id( $forum_id = 0 ) {
  545. echo bbp_get_forum_parent_id( $forum_id );
  546. }
  547. /**
  548. * Return ID of forum parent, if exists
  549. *
  550. * @since bbPress (r3675)
  551. *
  552. * @param int $forum_id Optional. Forum id
  553. * @uses bbp_get_forum_id() To get the forum id
  554. * @uses get_post_field() To get the forum parent
  555. * @uses apply_filters() Calls 'bbp_get_forum_parent' with the parent & forum id
  556. * @return int Forum parent
  557. */
  558. function bbp_get_forum_parent_id( $forum_id = 0 ) {
  559. $forum_id = bbp_get_forum_id( $forum_id );
  560. $parent_id = get_post_field( 'post_parent', $forum_id );
  561. return (int) apply_filters( 'bbp_get_forum_parent_id', (int) $parent_id, $forum_id );
  562. }
  563. /**
  564. * Return array of parent forums
  565. *
  566. * @since bbPress (r2625)
  567. *
  568. * @param int $forum_id Optional. Forum id
  569. * @uses bbp_get_forum_id() To get the forum id
  570. * @uses bbp_get_forum() To get the forum
  571. * @uses apply_filters() Calls 'bbp_get_forum_ancestors' with the ancestors
  572. * and forum id
  573. * @return array Forum ancestors
  574. */
  575. function bbp_get_forum_ancestors( $forum_id = 0 ) {
  576. $forum_id = bbp_get_forum_id( $forum_id );
  577. $ancestors = array();
  578. $forum = bbp_get_forum( $forum_id );
  579. if ( !empty( $forum ) ) {
  580. while ( 0 !== (int) $forum->post_parent ) {
  581. $ancestors[] = $forum->post_parent;
  582. $forum = bbp_get_forum( $forum->post_parent );
  583. }
  584. }
  585. return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );
  586. }
  587. /**
  588. * Return subforums of given forum
  589. *
  590. * @since bbPress (r2747)
  591. *
  592. * @param mixed $args All the arguments supported by {@link WP_Query}
  593. * @uses bbp_get_forum_id() To get the forum id
  594. * @uses current_user_can() To check if the current user is capable of
  595. * reading private forums
  596. * @uses get_posts() To get the subforums
  597. * @uses apply_filters() Calls 'bbp_forum_get_subforums' with the subforums
  598. * and the args
  599. * @return mixed false if none, array of subs if yes
  600. */
  601. function bbp_forum_get_subforums( $args = '' ) {
  602. // Use passed integer as post_parent
  603. if ( is_numeric( $args ) )
  604. $args = array( 'post_parent' => $args );
  605. // Setup possible post__not_in array
  606. $post_stati[] = bbp_get_public_status_id();
  607. // Super admin get whitelisted post statuses
  608. if ( bbp_is_user_keymaster() ) {
  609. $post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() );
  610. // Not a keymaster, so check caps
  611. } else {
  612. // Check if user can read private forums
  613. if ( current_user_can( 'read_private_forums' ) ) {
  614. $post_stati[] = bbp_get_private_status_id();
  615. }
  616. // Check if user can read hidden forums
  617. if ( current_user_can( 'read_hidden_forums' ) ) {
  618. $post_stati[] = bbp_get_hidden_status_id();
  619. }
  620. }
  621. // Parse arguments against default values
  622. $r = bbp_parse_args( $args, array(
  623. 'post_parent' => 0,
  624. 'post_type' => bbp_get_forum_post_type(),
  625. 'post_status' => implode( ',', $post_stati ),
  626. 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
  627. 'orderby' => 'menu_order title',
  628. 'order' => 'ASC',
  629. 'ignore_sticky_posts' => true,
  630. 'no_found_rows' => true
  631. ), 'forum_get_subforums' );
  632. $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
  633. // Create a new query for the subforums
  634. $get_posts = new WP_Query();
  635. // No forum passed
  636. $sub_forums = !empty( $r['post_parent'] ) ? $get_posts->query( $r ) : array();
  637. return (array) apply_filters( 'bbp_forum_get_subforums', $sub_forums, $r );
  638. }
  639. /**
  640. * Output a list of forums (can be used to list subforums)
  641. *
  642. * @param mixed $args The function supports these args:
  643. * - before: To put before the output. Defaults to '<ul class="bbp-forums">'
  644. * - after: To put after the output. Defaults to '</ul>'
  645. * - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
  646. * - link_after: To put after every link. Defaults to '</li>'
  647. * - separator: Separator. Defaults to ', '
  648. * - forum_id: Forum id. Defaults to ''
  649. * - show_topic_count - To show forum topic count or not. Defaults to true
  650. * - show_reply_count - To show forum reply count or not. Defaults to true
  651. * @uses bbp_forum_get_subforums() To check if the forum has subforums or not
  652. * @uses bbp_get_forum_permalink() To get forum permalink
  653. * @uses bbp_get_forum_title() To get forum title
  654. * @uses bbp_is_forum_category() To check if a forum is a category
  655. * @uses bbp_get_forum_topic_count() To get forum topic count
  656. * @uses bbp_get_forum_reply_count() To get forum reply count
  657. */
  658. function bbp_list_forums( $args = '' ) {
  659. // Define used variables
  660. $output = $sub_forums = $topic_count = $reply_count = $counts = '';
  661. $i = 0;
  662. $count = array();
  663. // Parse arguments against default values
  664. $r = bbp_parse_args( $args, array(
  665. 'before' => '<ul class="bbp-forums-list">',
  666. 'after' => '</ul>',
  667. 'link_before' => '<li class="bbp-forum">',
  668. 'link_after' => '</li>',
  669. 'count_before' => ' (',
  670. 'count_after' => ')',
  671. 'count_sep' => ', ',
  672. 'separator' => ', ',
  673. 'forum_id' => '',
  674. 'show_topic_count' => true,
  675. 'show_reply_count' => true,
  676. ), 'list_forums' );
  677. // Loop through forums and create a list
  678. $sub_forums = bbp_forum_get_subforums( $r['forum_id'] );
  679. if ( !empty( $sub_forums ) ) {
  680. // Total count (for separator)
  681. $total_subs = count( $sub_forums );
  682. foreach ( $sub_forums as $sub_forum ) {
  683. $i++; // Separator count
  684. // Get forum details
  685. $count = array();
  686. $show_sep = $total_subs > $i ? $r['separator'] : '';
  687. $permalink = bbp_get_forum_permalink( $sub_forum->ID );
  688. $title = bbp_get_forum_title( $sub_forum->ID );
  689. // Show topic count
  690. if ( !empty( $r['show_topic_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  691. $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
  692. }
  693. // Show reply count
  694. if ( !empty( $r['show_reply_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  695. $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
  696. }
  697. // Counts to show
  698. if ( !empty( $count ) ) {
  699. $counts = 'Тем: ' . $count['topic'] . '&nbsp;&nbsp;&nbsp;Ответов: ' . $count['reply'];
  700. }
  701. // Build this sub forums link
  702. $output .= $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" class="bbp-forum-link">' . '<img src="/wp-content/themes/wow-guild/images/forumicon.png"> <div class="aboutforum">' . $title . '<p class="counters">' . $counts . '</p></div></a>' . $r['link_after'];
  703. }
  704. // Output the list
  705. echo apply_filters( 'bbp_list_forums', $r['before'] . $output . $r['after'], $r );
  706. }
  707. }
  708. /** Forum Subscriptions *******************************************************/
  709. /**
  710. * Output the forum subscription link
  711. *
  712. * @since bbPress (r5156)
  713. *
  714. * @uses bbp_get_forum_subscription_link()
  715. */
  716. function bbp_forum_subscription_link( $args = array() ) {
  717. echo bbp_get_forum_subscription_link( $args );
  718. }
  719. /**
  720. * Get the forum subscription link
  721. *
  722. * A custom wrapper for bbp_get_user_subscribe_link()
  723. *
  724. * @since bbPress (r5156)
  725. *
  726. * @uses bbp_parse_args()
  727. * @uses bbp_get_user_subscribe_link()
  728. * @uses apply_filters() Calls 'bbp_get_forum_subscribe_link'
  729. */
  730. function bbp_get_forum_subscription_link( $args = array() ) {
  731. // No link
  732. $retval = false;
  733. // Parse the arguments
  734. $r = bbp_parse_args( $args, array(
  735. 'forum_id' => 0,
  736. 'user_id' => 0,
  737. 'before' => '',
  738. 'after' => '',
  739. 'subscribe' => __( 'Subscribe', 'bbpress' ),
  740. 'unsubscribe' => __( 'Unsubscribe', 'bbpress' )
  741. ), 'get_forum_subscribe_link' );
  742. // No link for categories until we support subscription hierarchy
  743. // @see http://bbpress.trac.wordpress.org/ticket/2475
  744. if ( ! bbp_is_forum_category() ) {
  745. $retval = bbp_get_user_subscribe_link( $r );
  746. }
  747. return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r );
  748. }
  749. /** Forum Last Topic **********************************************************/
  750. /**
  751. * Output the forum's last topic id
  752. *
  753. * @since bbPress (r2464)
  754. *
  755. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  756. * @param int $forum_id Optional. Forum id
  757. */
  758. function bbp_forum_last_topic_id( $forum_id = 0 ) {
  759. echo bbp_get_forum_last_topic_id( $forum_id );
  760. }
  761. /**
  762. * Return the forum's last topic id
  763. *
  764. * @since bbPress (r2464)
  765. *
  766. * @param int $forum_id Optional. Forum id
  767. * @uses bbp_get_forum_id() To get the forum id
  768. * @uses get_post_meta() To get the forum's last topic id
  769. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_id' with the
  770. * forum and topic id
  771. * @return int Forum's last topic id
  772. */
  773. function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
  774. $forum_id = bbp_get_forum_id( $forum_id );
  775. $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true );
  776. return (int) apply_filters( 'bbp_get_forum_last_topic_id', (int) $topic_id, $forum_id );
  777. }
  778. /**
  779. * Output the title of the last topic inside a forum
  780. *
  781. * @since bbPress (r2625)
  782. *
  783. * @param int $forum_id Optional. Forum id
  784. * @uses bbp_get_forum_last_topic_title() To get the forum's last topic's title
  785. */
  786. function bbp_forum_last_topic_title( $forum_id = 0 ) {
  787. echo bbp_get_forum_last_topic_title( $forum_id );
  788. }
  789. /**
  790. * Return the title of the last topic inside a forum
  791. *
  792. * @since bbPress (r2625)
  793. *
  794. * @param int $forum_id Optional. Forum id
  795. * @uses bbp_get_forum_id() To get the forum id
  796. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  797. * @uses bbp_get_topic_title() To get the topic's title
  798. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_title' with the
  799. * topic title and forum id
  800. * @return string Forum's last topic's title
  801. */
  802. function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
  803. $forum_id = bbp_get_forum_id( $forum_id );
  804. $topic_id = bbp_get_forum_last_topic_id( $forum_id );
  805. $title = !empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : '';
  806. return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id );
  807. }
  808. /**
  809. * Output the link to the last topic in a forum
  810. *
  811. * @since bbPress (r2464)
  812. *
  813. * @param int $forum_id Optional. Forum id
  814. * @uses bbp_get_forum_last_topic_permalink() To get the forum's last topic's
  815. * permanent link
  816. */
  817. function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
  818. echo esc_url( bbp_get_forum_last_topic_permalink( $forum_id ) );
  819. }
  820. /**
  821. * Return the link to the last topic in a forum
  822. *
  823. * @since bbPress (r2464)
  824. *
  825. * @param int $forum_id Optional. Forum id
  826. * @uses bbp_get_forum_id() To get the forum id
  827. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  828. * @uses bbp_get_topic_permalink() To get the topic's permalink
  829. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with
  830. * the topic link and forum id
  831. * @return string Permanent link to topic
  832. */
  833. function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
  834. $forum_id = bbp_get_forum_id( $forum_id );
  835. return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
  836. }
  837. /**
  838. * Return the author ID of the last topic of a forum
  839. *
  840. * @since bbPress (r2625)
  841. *
  842. * @param int $forum_id Optional. Forum id
  843. * @uses bbp_get_forum_id() To get the forum id
  844. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  845. * @uses bbp_get_topic_author_id() To get the topic's author id
  846. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author' with the author
  847. * id and forum id
  848. * @return int Forum's last topic's author id
  849. */
  850. function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
  851. $forum_id = bbp_get_forum_id( $forum_id );
  852. $author_id = bbp_get_topic_author_id( bbp_get_forum_last_topic_id( $forum_id ) );
  853. return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id );
  854. }
  855. /**
  856. * Output link to author of last topic of forum
  857. *
  858. * @since bbPress (r2625)
  859. *
  860. * @param int $forum_id Optional. Forum id
  861. * @uses bbp_get_forum_last_topic_author_link() To get the forum's last topic's
  862. * author link
  863. */
  864. function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
  865. echo bbp_get_forum_last_topic_author_link( $forum_id );
  866. }
  867. /**
  868. * Return link to author of last topic of forum
  869. *
  870. * @since bbPress (r2625)
  871. *
  872. * @param int $forum_id Optional. Forum id
  873. * @uses bbp_get_forum_id() To get the forum id
  874. * @uses bbp_get_forum_last_topic_author_id() To get the forum's last
  875. * topic's author id
  876. * @uses bbp_get_user_profile_link() To get the author's profile link
  877. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author_link'
  878. * with the author link and forum id
  879. * @return string Forum's last topic's author link
  880. */
  881. function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
  882. $forum_id = bbp_get_forum_id( $forum_id );
  883. $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
  884. $author_link = bbp_get_user_profile_link( $author_id );
  885. return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
  886. }
  887. /** Forum Last Reply **********************************************************/
  888. /**
  889. * Output the forums last reply id
  890. *
  891. * @since bbPress (r2464)
  892. *
  893. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  894. * @param int $forum_id Optional. Forum id
  895. */
  896. function bbp_forum_last_reply_id( $forum_id = 0 ) {
  897. echo bbp_get_forum_last_reply_id( $forum_id );
  898. }
  899. /**
  900. * Return the forums last reply id
  901. *
  902. * @since bbPress (r2464)
  903. *
  904. * @param int $forum_id Optional. Forum id
  905. * @uses bbp_get_forum_id() To get the forum id
  906. * @uses get_post_meta() To get the forum's last reply id
  907. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  908. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_id' with
  909. * the last reply id and forum id
  910. * @return int Forum's last reply id
  911. */
  912. function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
  913. $forum_id = bbp_get_forum_id( $forum_id );
  914. $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true );
  915. if ( empty( $reply_id ) )
  916. $reply_id = bbp_get_forum_last_topic_id( $forum_id );
  917. return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
  918. }
  919. /**
  920. * Output the title of the last reply inside a forum
  921. *
  922. * @param int $forum_id Optional. Forum id
  923. * @uses bbp_get_forum_last_reply_title() To get the forum's last reply's title
  924. */
  925. function bbp_forum_last_reply_title( $forum_id = 0 ) {
  926. echo bbp_get_forum_last_reply_title( $forum_id );
  927. }
  928. /**
  929. * Return the title of the last reply inside a forum
  930. *
  931. * @param int $forum_id Optional. Forum id
  932. * @uses bbp_get_forum_id() To get the forum id
  933. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  934. * @uses bbp_get_reply_title() To get the reply title
  935. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_title' with the
  936. * reply title and forum id
  937. * @return string
  938. */
  939. function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
  940. $forum_id = bbp_get_forum_id( $forum_id );
  941. return apply_filters( 'bbp_get_forum_last_reply_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
  942. }
  943. /**
  944. * Output the link to the last reply in a forum
  945. *
  946. * @since bbPress (r2464)
  947. *
  948. * @param int $forum_id Optional. Forum id
  949. * @uses bbp_get_forum_last_reply_permalink() To get the forum last reply link
  950. */
  951. function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
  952. echo esc_url( bbp_get_forum_last_reply_permalink( $forum_id ) );
  953. }
  954. /**
  955. * Return the link to the last reply in a forum
  956. *
  957. * @since bbPress (r2464)
  958. *
  959. * @param int $forum_id Optional. Forum id
  960. * @uses bbp_get_forum_id() To get the forum id
  961. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  962. * @uses bbp_get_reply_permalink() To get the reply permalink
  963. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_permalink' with
  964. * the reply link and forum id
  965. * @return string Permanent link to the forum's last reply
  966. */
  967. function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
  968. $forum_id = bbp_get_forum_id( $forum_id );
  969. return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
  970. }
  971. /**
  972. * Output the url to the last reply in a forum
  973. *
  974. * @since bbPress (r2683)
  975. *
  976. * @param int $forum_id Optional. Forum id
  977. * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
  978. */
  979. function bbp_forum_last_reply_url( $forum_id = 0 ) {
  980. echo esc_url( bbp_get_forum_last_reply_url( $forum_id ) );
  981. }
  982. /**
  983. * Return the url to the last reply in a forum
  984. *
  985. * @since bbPress (r2683)
  986. *
  987. * @param int $forum_id Optional. Forum id
  988. * @uses bbp_get_forum_id() To get the forum id
  989. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  990. * @uses bbp_get_reply_url() To get the reply url
  991. * @uses bbp_get_forum_last_topic_permalink() To get the forum's last
  992. * topic's permalink
  993. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_url' with the
  994. * reply url and forum id
  995. * @return string Paginated URL to latest reply
  996. */
  997. function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
  998. $forum_id = bbp_get_forum_id( $forum_id );
  999. // If forum has replies, get the last reply and use its url
  1000. $reply_id = bbp_get_forum_last_reply_id( $forum_id );
  1001. if ( !empty( $reply_id ) ) {
  1002. $reply_url = bbp_get_reply_url( $reply_id );
  1003. // No replies, so look for topics and use last permalink
  1004. } else {
  1005. $reply_url = bbp_get_forum_last_topic_permalink( $forum_id );
  1006. // No topics either, so set $reply_url as empty string
  1007. if ( empty( $reply_url ) ) {
  1008. $reply_url = '';
  1009. }
  1010. }
  1011. // Filter and return
  1012. return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id );
  1013. }
  1014. /**
  1015. * Output author ID of last reply of forum
  1016. *
  1017. * @since bbPress (r2625)
  1018. *
  1019. * @param int $forum_id Optional. Forum id
  1020. * @uses bbp_get_forum_last_reply_author_id() To get the forum's last reply
  1021. * author id
  1022. */
  1023. function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
  1024. echo bbp_get_forum_last_reply_author_id( $forum_id );
  1025. }
  1026. /**
  1027. * Return author ID of last reply of forum
  1028. *
  1029. * @since bbPress (r2625)
  1030. *
  1031. * @param int $forum_id Optional. Forum id
  1032. * @uses bbp_get_forum_id() To get the forum id
  1033. * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
  1034. * reply's author id
  1035. * @uses bbp_get_reply_author_id() To get the reply's author id
  1036. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_id' with
  1037. * the author id and forum id
  1038. * @return int Forum's last reply author id
  1039. */
  1040. function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
  1041. $forum_id = bbp_get_forum_id( $forum_id );
  1042. $author_id = bbp_get_reply_author_id( bbp_get_forum_last_reply_id( $forum_id ) );
  1043. return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id );
  1044. }
  1045. /**
  1046. * Output link to author of last reply of forum
  1047. *
  1048. * @since bbPress (r2625)
  1049. *
  1050. * @param int $forum_id Optional. Forum id
  1051. * @uses bbp_get_forum_last_reply_author_link() To get the forum's last reply's
  1052. * author link
  1053. */
  1054. function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
  1055. echo bbp_get_forum_last_reply_author_link( $forum_id );
  1056. }
  1057. /**
  1058. * Return link to author of last reply of forum
  1059. *
  1060. * @since bbPress (r2625)
  1061. *
  1062. * @param int $forum_id Optional. Forum id
  1063. * @uses bbp_get_forum_id() To get the forum id
  1064. * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
  1065. * reply's author id
  1066. * @uses bbp_get_user_profile_link() To get the reply's author's profile
  1067. * link
  1068. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_link'
  1069. * with the author link and forum id
  1070. * @return string Link to author of last reply of forum
  1071. */
  1072. function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
  1073. $forum_id = bbp_get_forum_id( $forum_id );
  1074. $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
  1075. $author_link = bbp_get_user_profile_link( $author_id );
  1076. return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id );
  1077. }
  1078. /** Forum Counts **************************************************************/
  1079. /**
  1080. * Output the topics link of the forum
  1081. *
  1082. * @since bbPress (r2883)
  1083. *
  1084. * @param int $forum_id Optional. Topic id
  1085. * @uses bbp_get_forum_topics_link() To get the forum topics link
  1086. */
  1087. function bbp_forum_topics_link( $forum_id = 0 ) {
  1088. echo bbp_get_forum_topics_link( $forum_id );
  1089. }
  1090. /**
  1091. * Return the topics link of the forum
  1092. *
  1093. * @since bbPress (r2883)
  1094. *
  1095. * @param int $forum_id Optional. Topic id
  1096. * @uses bbp_get_forum_id() To get the forum id
  1097. * @uses bbp_get_forum() To get the forum
  1098. * @uses bbp_get_forum_topic_count() To get the forum topic count
  1099. * @uses bbp_get_forum_permalink() To get the forum permalink
  1100. * @uses remove_query_arg() To remove args from the url
  1101. * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden
  1102. * topic count
  1103. * @uses current_user_can() To check if the current user can edit others
  1104. * topics
  1105. * @uses add_query_arg() To add custom args to the url
  1106. * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the
  1107. * topics link and forum id
  1108. */
  1109. function bbp_get_forum_topics_link( $forum_id = 0 ) {
  1110. $forum = bbp_get_forum( $forum_id );
  1111. $forum_id = $forum->ID;
  1112. $topics = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, false ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id ) );
  1113. $retval = '';
  1114. // First link never has view=all
  1115. if ( bbp_get_view_all( 'edit_others_topics' ) )
  1116. $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_forum_permalink( $forum_id ) ) ) . "'>" . esc_html( $topics ) . "</a>";
  1117. else
  1118. $retval .= esc_html( $topics );
  1119. // Get deleted topics
  1120. $deleted = bbp_get_forum_topic_count_hidden( $forum_id );
  1121. // This forum has hidden topics
  1122. if ( !empty( $deleted ) && current_user_can( 'edit_others_topics' ) ) {
  1123. // Extra text
  1124. $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
  1125. // No link
  1126. if ( bbp_get_view_all() ) {
  1127. $retval .= " $extra";
  1128. // Link
  1129. } else {
  1130. $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_forum_permalink( $forum_id ), true ) ) . "'>" . esc_html( $extra ) . "</a>";
  1131. }
  1132. }
  1133. return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
  1134. }
  1135. /**
  1136. * Output total sub-forum count of a forum
  1137. *
  1138. * @since bbPress (r2464)
  1139. *
  1140. * @param int $forum_id Optional. Forum id to check
  1141. * @param boolean $integer Optional. Whether or not to format the result
  1142. * @uses bbp_get_forum_subforum_count() To get the forum's subforum count
  1143. */
  1144. function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) {
  1145. echo bbp_get_forum_subforum_count( $forum_id, $integer );
  1146. }
  1147. /**
  1148. * Return total subforum count of a forum
  1149. *
  1150. * @since bbPress (r2464)
  1151. *
  1152. * @param int $forum_id Optional. Forum id
  1153. * @param boolean $integer Optional. Whether or not to format the result
  1154. * @uses bbp_get_forum_id() To get the forum id
  1155. * @uses get_post_meta() To get the subforum count
  1156. * @uses apply_filters() Calls 'bbp_get_forum_subforum_count' with the
  1157. * subforum count and forum id
  1158. * @return int Forum's subforum count
  1159. */
  1160. function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
  1161. $forum_id = bbp_get_forum_id( $forum_id );
  1162. $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
  1163. $filter = ( true === $integer ) ? 'bbp_get_forum_subforum_count_int' : 'bbp_get_forum_subforum_count';
  1164. return apply_filters( $filter, $forum_count, $forum_id );
  1165. }
  1166. /**
  1167. * Output total topic count of a forum
  1168. *
  1169. * @since bbPress (r2464)
  1170. *
  1171. * @param int $forum_id Optional. Forum id
  1172. * @param bool $total_count Optional. To get the total count or normal count?
  1173. * @param boolean $integer Optional. Whether or not to format the result
  1174. * @uses bbp_get_forum_topic_count() To get the forum topic count
  1175. */
  1176. function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1177. echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer );
  1178. }
  1179. /**
  1180. * Return total topic count of a forum
  1181. *
  1182. * @since bbPress (r2464)
  1183. *
  1184. * @param int $forum_id Optional. Forum id
  1185. * @param bool $total_count Optional. To get the total count or normal
  1186. * count? Defaults to total.
  1187. * @param boolean $integer Optional. Whether or not to format the result
  1188. * @uses bbp_get_forum_id() To get the forum id
  1189. * @uses get_post_meta() To get the forum topic count
  1190. * @uses apply_filters() Calls 'bbp_get_forum_topic_count' with the
  1191. * topic count and forum id
  1192. * @return int Forum topic count
  1193. */
  1194. function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1195. $forum_id = bbp_get_forum_id( $forum_id );
  1196. $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count';
  1197. $topics = (int) get_post_meta( $forum_id, $meta_key, true );
  1198. $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_int' : 'bbp_get_forum_topic_count';
  1199. return apply_filters( $filter, $topics, $forum_id );
  1200. }
  1201. /**
  1202. * Output total reply count of a forum
  1203. *
  1204. * @since bbPress (r2464)
  1205. *
  1206. * @param int $forum_id Optional. Forum id
  1207. * @param bool $total_count Optional. To get the total count or normal count?
  1208. * @param boolean $integer Optional. Whether or not to format the result
  1209. * @uses bbp_get_forum_reply_count() To get the forum reply count
  1210. */
  1211. function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1212. echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer );
  1213. }
  1214. /**
  1215. * Return total post count of a forum
  1216. *
  1217. * @since bbPress (r2464)
  1218. *
  1219. * @param int $forum_id Optional. Forum id
  1220. * @param bool $total_count Optional. To get the total count or normal
  1221. * count?
  1222. * @param boolean $integer Optional. Whether or not to format the result
  1223. * @uses bbp_get_forum_id() To get the forum id
  1224. * @uses get_post_meta() To get the forum reply count
  1225. * @uses apply_filters() Calls 'bbp_get_forum_reply_count' with the
  1226. * reply count and forum id
  1227. * @return int Forum reply count
  1228. */
  1229. function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1230. $forum_id = bbp_get_forum_id( $forum_id );
  1231. $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
  1232. $replies = (int) get_post_meta( $forum_id, $meta_key, true );
  1233. $filter = ( true === $integer ) ? 'bbp_get_forum_reply_count_int' : 'bbp_get_forum_reply_count';
  1234. return apply_filters( $filter, $replies, $forum_id );
  1235. }
  1236. /**
  1237. * Output total post count of a forum
  1238. *
  1239. * @since bbPress (r2954)
  1240. *
  1241. * @param int $forum_id Optional. Forum id
  1242. * @param bool $total_count Optional. To get the total count or normal count?
  1243. * @param boolean $integer Optional. Whether or not to format the result
  1244. * @uses bbp_get_forum_post_count() To get the forum post count
  1245. */
  1246. function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1247. echo bbp_get_forum_post_count( $forum_id, $total_count, $integer );
  1248. }
  1249. /**
  1250. * Return total post count of a forum
  1251. *
  1252. * @since bbPress (r2954)
  1253. *
  1254. * @param int $forum_id Optional. Forum id
  1255. * @param bool $total_count Optional. To get the total count or normal
  1256. * count?
  1257. * @param boolean $integer Optional. Whether or not to format the result
  1258. * @uses bbp_get_forum_id() To get the forum id
  1259. * @uses get_post_meta() To get the forum post count
  1260. * @uses apply_filters() Calls 'bbp_get_forum_post_count' with the
  1261. * post count and forum id
  1262. * @return int Forum post count
  1263. */
  1264. function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1265. $forum_id = bbp_get_forum_id( $forum_id );
  1266. $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true );
  1267. $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
  1268. $replies = (int) get_post_meta( $forum_id, $meta_key, true );
  1269. $retval = $replies + $topics;
  1270. $filter = ( true === $integer ) ? 'bbp_get_forum_post_count_int' : 'bbp_get_forum_post_count';
  1271. return apply_filters( $filter, $retval, $forum_id );
  1272. }
  1273. /**
  1274. * Output total hidden topic count of a forum (hidden includes trashed and
  1275. * spammed topics)
  1276. *
  1277. * @since bbPress (r2883)
  1278. *
  1279. * @param int $forum_id Optional. Topic id
  1280. * @param boolean $integer Optional. Whether or not to format the result
  1281. * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count
  1282. */
  1283. function bbp_forum_topic_count_hidden( $forum_id = 0, $integer = false ) {
  1284. echo bbp_get_forum_topic_count_hidden( $forum_id, $integer );
  1285. }
  1286. /**
  1287. * Return total hidden topic count of a forum (hidden includes trashed
  1288. * and spammed topics)
  1289. *
  1290. * @since bbPress (r2883)
  1291. *
  1292. * @param int $forum_id Optional. Topic id
  1293. * @param boolean $integer Optional. Whether or not to format the result
  1294. * @uses bbp_get_forum_id() To get the forum id
  1295. * @uses get_post_meta() To get the hidden topic count
  1296. * @uses apply_filters() Calls 'bbp_get_forum_topic_count_hidden' with
  1297. * the hidden topic count and forum id
  1298. * @return int Topic hidden topic count
  1299. */
  1300. function bbp_get_forum_topic_count_hidden( $forum_id = 0, $integer = false ) {
  1301. $forum_id = bbp_get_forum_id( $forum_id );
  1302. $topics = (int) get_post_meta( $forum_id, '_bbp_topic_count_hidden', true );
  1303. $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_hidden_int' : 'bbp_get_forum_topic_count_hidden';
  1304. return apply_filters( $filter, $topics, $forum_id );
  1305. }
  1306. /**
  1307. * Output the status of the forum
  1308. *
  1309. * @since bbPress (r2667)
  1310. *
  1311. * @param int $forum_id Optional. Forum id
  1312. * @uses bbp_get_forum_status() To get the forum status
  1313. */
  1314. function bbp_forum_status( $forum_id = 0 ) {
  1315. echo bbp_get_forum_status( $forum_id );
  1316. }
  1317. /**
  1318. * Return the status of the forum
  1319. *
  1320. * @since bbPress (r2667)
  1321. *
  1322. * @param int $forum_id Optional. Forum id
  1323. * @uses bbp_get_forum_id() To get the forum id
  1324. * @uses get_post_status() To get the forum's status
  1325. * @uses apply_filters() Calls 'bbp_get_forum_status' with the status
  1326. * and forum id
  1327. * @return string Status of forum
  1328. */
  1329. function bbp_get_forum_status( $forum_id = 0 ) {
  1330. $forum_id = bbp_get_forum_id( $forum_id );
  1331. $status = get_post_meta( $forum_id, '_bbp_status', true );
  1332. if ( empty( $status ) )
  1333. $status = 'open';
  1334. return apply_filters( 'bbp_get_forum_status', $status, $forum_id );
  1335. }
  1336. /**
  1337. * Output the visibility of the forum
  1338. *
  1339. * @since bbPress (r2997)
  1340. *
  1341. * @param int $forum_id Optional. Forum id
  1342. * @uses bbp_get_forum_visibility() To get the forum visibility
  1343. */
  1344. function bbp_forum_visibility( $forum_id = 0 ) {
  1345. echo bbp_get_forum_visibility( $forum_id );
  1346. }
  1347. /**
  1348. * Return the visibility of the forum
  1349. *
  1350. * @since bbPress (r2997)
  1351. *
  1352. * @param int $forum_id Optional. Forum id
  1353. * @uses bbp_get_forum_id() To get the forum id
  1354. * @uses get_post_visibility() To get the forum's visibility
  1355. * @uses apply_filters() Calls 'bbp_get_forum_visibility' with the visibility
  1356. * and forum id
  1357. * @return string Status of forum
  1358. */
  1359. function bbp_get_forum_visibility( $forum_id = 0 ) {
  1360. $forum_id = bbp_get_forum_id( $forum_id );
  1361. return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id );
  1362. }
  1363. /**
  1364. * Output the type of the forum
  1365. *
  1366. * @since bbPress (r3563)
  1367. *
  1368. * @param int $forum_id Optional. Forum id
  1369. * @uses bbp_get_forum_type() To get the forum type
  1370. */
  1371. function bbp_forum_type( $forum_id = 0 ) {
  1372. echo bbp_get_forum_type( $forum_id );
  1373. }
  1374. /**
  1375. * Return the type of forum (category/forum/etc...)
  1376. *
  1377. * @since bbPress (r3563)
  1378. *
  1379. * @param int $forum_id Optional. Forum id
  1380. * @uses get_post_meta() To get the forum category meta
  1381. * @return bool Whether the forum is a category or not
  1382. */
  1383. function bbp_get_forum_type( $forum_id = 0 ) {
  1384. $forum_id = bbp_get_forum_id( $forum_id );
  1385. $retval = get_post_meta( $forum_id, '_bbp_forum_type', true );
  1386. if ( empty( $retval ) )
  1387. $retval = 'forum';
  1388. return apply_filters( 'bbp_get_forum_type', $retval, $forum_id );
  1389. }
  1390. /**
  1391. * Is the forum a category?
  1392. *
  1393. * @since bbPress (r2746)
  1394. *
  1395. * @param int $forum_id Optional. Forum id
  1396. * @uses bbp_get_forum_type() To get the forum type
  1397. * @return bool Whether the forum is a category or not
  1398. */
  1399. function bbp_is_forum_category( $forum_id = 0 ) {
  1400. $forum_id = bbp_get_forum_id( $forum_id );
  1401. $type = bbp_get_forum_type( $forum_id );
  1402. $retval = ( !empty( $type ) && 'category' === $type );
  1403. return (bool) apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
  1404. }
  1405. /**
  1406. * Is the forum open?
  1407. *
  1408. * @since bbPress (r2746)
  1409. * @param int $forum_id Optional. Forum id
  1410. *
  1411. * @param int $forum_id Optional. Forum id
  1412. * @uses bbp_is_forum_closed() To check if the forum is closed or not
  1413. * @return bool Whether the forum is open or not
  1414. */
  1415. function bbp_is_forum_open( $forum_id = 0 ) {
  1416. return !bbp_is_forum_closed( $forum_id );
  1417. }
  1418. /**
  1419. * Is the forum closed?
  1420. *
  1421. * @since bbPress (r2746)
  1422. *
  1423. * @param int $forum_id Optional. Forum id
  1424. * @param bool $check_ancestors Check if the ancestors are closed (only
  1425. * if they're a category)
  1426. * @uses bbp_get_forum_status() To get the forum status
  1427. * @uses bbp_get_forum_ancestors() To get the forum ancestors
  1428. * @uses bbp_is_forum_category() To check if the forum is a category
  1429. * @uses bbp_is_forum_closed() To check if the forum is closed
  1430. * @return bool True if closed, false if not
  1431. */
  1432. function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
  1433. $forum_id = bbp_get_forum_id( $forum_id );
  1434. $retval = ( bbp_get_closed_status_id() === bbp_get_forum_status( $forum_id ) );
  1435. if ( !empty( $check_ancestors ) ) {
  1436. $ancestors = bbp_get_forum_ancestors( $forum_id );
  1437. foreach ( (array) $ancestors as $ancestor ) {
  1438. if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) {
  1439. $retval = true;
  1440. }
  1441. }
  1442. }
  1443. return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
  1444. }
  1445. /**
  1446. * Is the forum public?
  1447. *
  1448. * @since bbPress (r2997)
  1449. *
  1450. * @param int $forum_id Optional. Forum id
  1451. * @param bool $check_ancestors Check if the ancestors are public (only if
  1452. * they're a category)
  1453. * @uses get_post_meta() To get the forum public meta
  1454. * @uses bbp_get_forum_ancestors() To get the forum ancestors
  1455. * @uses bbp_is_forum_category() To check if the forum is a category
  1456. * @uses bbp_is_forum_closed() To check if the forum is closed
  1457. * @return bool True if closed, false if not
  1458. */
  1459. function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
  1460. $forum_id = bbp_get_forum_id( $forum_id );
  1461. $visibility = bbp_get_forum_visibility( $forum_id );
  1462. // If post status is public, return true
  1463. $retval = ( bbp_get_public_status_id() === $visibility );
  1464. // Check ancestors and inherit their privacy setting for display
  1465. if ( !empty( $check_ancestors ) ) {
  1466. $ancestors = bbp_get_forum_ancestors( $forum_id );
  1467. foreach ( (array) $ancestors as $ancestor ) {
  1468. if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) {
  1469. $retval = true;
  1470. }
  1471. }
  1472. }
  1473. return (bool) apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
  1474. }
  1475. /**
  1476. * Is the forum private?
  1477. *
  1478. * @since bbPress (r2746)
  1479. *
  1480. * @param int $forum_id Optional. Forum id
  1481. * @param bool $check_ancestors Check if the ancestors are private (only if
  1482. * they're a category)
  1483. * @uses get_post_meta() To get the forum private meta
  1484. * @uses bbp_get_forum_ancestors() To get the forum ancestors
  1485. * @uses bbp_is_forum_category() To check if the forum is a category
  1486. * @uses bbp_is_forum_closed() To check if the forum is closed
  1487. * @return bool True if closed, false if not
  1488. */
  1489. function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
  1490. $forum_id = bbp_get_forum_id( $forum_id );
  1491. $visibility = bbp_get_forum_visibility( $forum_id );
  1492. // If post status is private, return true
  1493. $retval = ( bbp_get_private_status_id() === $visibility );
  1494. // Check ancestors and inherit their privacy setting for display
  1495. if ( !empty( $check_ancestors ) ) {
  1496. $ancestors = bbp_get_forum_ancestors( $forum_id );
  1497. foreach ( (array) $ancestors as $ancestor ) {
  1498. if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) {
  1499. $retval = true;
  1500. }
  1501. }
  1502. }
  1503. return (bool) apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
  1504. }
  1505. /**
  1506. * Is the forum hidden?
  1507. *
  1508. * @since bbPress (r2997)
  1509. *
  1510. * @param int $forum_id Optional. Forum id
  1511. * @param bool $check_ancestors Check if the ancestors are private (only if
  1512. * they're a category)
  1513. * @uses get_post_meta() To get the forum private meta
  1514. * @uses bbp_get_forum_ancestors() To get the forum ancestors
  1515. * @uses bbp_is_forum_category() To check if the forum is a category
  1516. * @uses bbp_is_forum_closed() To check if the forum is closed
  1517. * @return bool True if closed, false if not
  1518. */
  1519. function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
  1520. $forum_id = bbp_get_forum_id( $forum_id );
  1521. $visibility = bbp_get_forum_visibility( $forum_id );
  1522. // If post status is private, return true
  1523. $retval = ( bbp_get_hidden_status_id() === $visibility );
  1524. // Check ancestors and inherit their privacy setting for display
  1525. if ( !empty( $check_ancestors ) ) {
  1526. $ancestors = bbp_get_forum_ancestors( $forum_id );
  1527. foreach ( (array) $ancestors as $ancestor ) {
  1528. if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) {
  1529. $retval = true;
  1530. }
  1531. }
  1532. }
  1533. return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
  1534. }
  1535. /**
  1536. * Output the author of the forum
  1537. *
  1538. * @since bbPress (r3675)
  1539. *
  1540. * @param int $forum_id Optional. Forum id
  1541. * @uses bbp_get_forum_author() To get the forum author
  1542. */
  1543. function bbp_forum_author_display_name( $forum_id = 0 ) {
  1544. echo bbp_get_forum_author_display_name( $forum_id );
  1545. }
  1546. /**
  1547. * Return the author of the forum
  1548. *
  1549. * @since bbPress (r3675)
  1550. *
  1551. * @param int $forum_id Optional. Forum id
  1552. * @uses bbp_get_forum_id() To get the forum id
  1553. * @uses bbp_get_forum_author_id() To get the forum author id
  1554. * @uses get_the_author_meta() To get the display name of the author
  1555. * @uses apply_filters() Calls 'bbp_get_forum_author' with the author
  1556. * and forum id
  1557. * @return string Author of forum
  1558. */
  1559. function bbp_get_forum_author_display_name( $forum_id = 0 ) {
  1560. $forum_id = bbp_get_forum_id( $forum_id );
  1561. $author = get_the_author_meta( 'display_name', bbp_get_forum_author_id( $forum_id ) );
  1562. return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id );
  1563. }
  1564. /**
  1565. * Output the author ID of the forum
  1566. *
  1567. * @since bbPress (r3675)
  1568. *
  1569. * @param int $forum_id Optional. Forum id
  1570. * @uses bbp_get_forum_author_id() To get the forum author id
  1571. */
  1572. function bbp_forum_author_id( $forum_id = 0 ) {
  1573. echo bbp_get_forum_author_id( $forum_id );
  1574. }
  1575. /**
  1576. * Return the author ID of the forum
  1577. *
  1578. * @since bbPress (r3675)
  1579. *
  1580. * @param int $forum_id Optional. Forum id
  1581. * @uses bbp_get_forum_id() To get the forum id
  1582. * @uses get_post_field() To get the forum author id
  1583. * @uses apply_filters() Calls 'bbp_get_forum_author_id' with the author
  1584. * id and forum id
  1585. * @return string Author of forum
  1586. */
  1587. function bbp_get_forum_author_id( $forum_id = 0 ) {
  1588. $forum_id = bbp_get_forum_id( $forum_id );
  1589. $author_id = get_post_field( 'post_author', $forum_id );
  1590. return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id );
  1591. }
  1592. /**
  1593. * Replace forum meta details for users that cannot view them.
  1594. *
  1595. * @since bbPress (r3162)
  1596. *
  1597. * @param string $retval
  1598. * @param int $forum_id
  1599. *
  1600. * @uses bbp_is_forum_private()
  1601. * @uses current_user_can()
  1602. *
  1603. * @return string
  1604. */
  1605. function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
  1606. if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) )
  1607. $retval = '-';
  1608. return apply_filters( 'bbp_suppress_private_forum_meta', $retval );
  1609. }
  1610. /**
  1611. * Replace forum author details for users that cannot view them.
  1612. *
  1613. * @since bbPress (r3162)
  1614. *
  1615. * @param string $retval
  1616. * @param int $forum_id
  1617. *
  1618. * @uses bbp_is_forum_private()
  1619. * @uses get_post_field()
  1620. * @uses bbp_get_topic_post_type()
  1621. * @uses bbp_is_forum_private()
  1622. * @uses bbp_get_topic_forum_id()
  1623. * @uses bbp_get_reply_post_type()
  1624. * @uses bbp_get_reply_forum_id()
  1625. *
  1626. * @return string
  1627. */
  1628. function bbp_suppress_private_author_link( $author_link, $args ) {
  1629. // Assume the author link is the return value
  1630. $retval = $author_link;
  1631. // Show the normal author link
  1632. if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) {
  1633. // What post type are we looking at?
  1634. $post_type = get_post_field( 'post_type', $args['post_id'] );
  1635. switch ( $post_type ) {
  1636. // Topic
  1637. case bbp_get_topic_post_type() :
  1638. if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) )
  1639. $retval = '';
  1640. break;
  1641. // Reply
  1642. case bbp_get_reply_post_type() :
  1643. if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) )
  1644. $retval = '';
  1645. break;
  1646. // Post
  1647. default :
  1648. if ( bbp_is_forum_private( $args['post_id'] ) )
  1649. $retval = '';
  1650. break;
  1651. }
  1652. }
  1653. return apply_filters( 'bbp_suppress_private_author_link', $retval );
  1654. }
  1655. /**
  1656. * Output the row class of a forum
  1657. *
  1658. * @since bbPress (r2667)
  1659. *
  1660. * @param int $forum_id Optional. Forum ID.
  1661. * @param array Extra classes you can pass when calling this function
  1662. * @uses bbp_get_forum_class() To get the row class of the forum
  1663. */
  1664. function bbp_forum_class( $forum_id = 0, $classes = array() ) {
  1665. echo bbp_get_forum_class( $forum_id, $classes );
  1666. }
  1667. /**
  1668. * Return the row class of a forum
  1669. *
  1670. * @since bbPress (r2667)
  1671. *
  1672. * @param int $forum_id Optional. Forum ID
  1673. * @param array Extra classes you can pass when calling this function
  1674. * @uses bbp_get_forum_id() To validate the forum id
  1675. * @uses bbp_is_forum_category() To see if forum is a category
  1676. * @uses bbp_get_forum_status() To get the forum status
  1677. * @uses bbp_get_forum_visibility() To get the forum visibility
  1678. * @uses bbp_get_forum_parent_id() To get the forum parent id
  1679. * @uses get_post_class() To get all the classes including ours
  1680. * @uses apply_filters() Calls 'bbp_get_forum_class' with the classes
  1681. * @return string Row class of the forum
  1682. */
  1683. function bbp_get_forum_class( $forum_id = 0, $classes = array() ) {
  1684. $bbp = bbpress();
  1685. $forum_id = bbp_get_forum_id( $forum_id );
  1686. $count = isset( $bbp->forum_query->current_post ) ? $bbp->forum_query->current_post : 1;
  1687. $classes = (array) $classes;
  1688. // Get some classes
  1689. $classes[] = 'loop-item-' . $count;
  1690. $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd';
  1691. $classes[] = bbp_is_forum_category( $forum_id ) ? 'status-category' : '';
  1692. $classes[] = bbp_get_forum_subforum_count( $forum_id ) ? 'bbp-has-subforums' : '';
  1693. $classes[] = bbp_get_forum_parent_id( $forum_id ) ? 'bbp-parent-forum-' . bbp_get_forum_parent_id( $forum_id ) : '';
  1694. $classes[] = 'bbp-forum-status-' . bbp_get_forum_status( $forum_id );
  1695. $classes[] = 'bbp-forum-visibility-' . bbp_get_forum_visibility( $forum_id );
  1696. // Ditch the empties
  1697. $classes = array_filter( $classes );
  1698. $classes = get_post_class( $classes, $forum_id );
  1699. // Filter the results
  1700. $classes = apply_filters( 'bbp_get_forum_class', $classes, $forum_id );
  1701. $retval = 'class="' . implode( ' ', $classes ) . '"';
  1702. return $retval;
  1703. }
  1704. /** Single Forum **************************************************************/
  1705. /**
  1706. * Output a fancy description of the current forum, including total topics,
  1707. * total replies, and last activity.
  1708. *
  1709. * @since bbPress (r2860)
  1710. *
  1711. * @param array $args Arguments passed to alter output
  1712. * @uses bbp_get_single_forum_description() Return the eventual output
  1713. */
  1714. function bbp_single_forum_description( $args = '' ) {
  1715. echo bbp_get_single_forum_description( $args );
  1716. }
  1717. /**
  1718. * Return a fancy description of the current forum, including total
  1719. * topics, total replies, and last activity.
  1720. *
  1721. * @since bbPress (r2860)
  1722. *
  1723. * @param mixed $args This function supports these arguments:
  1724. * - forum_id: Forum id
  1725. * - before: Before the text
  1726. * - after: After the text
  1727. * - size: Size of the avatar
  1728. * @uses bbp_get_forum_id() To get the forum id
  1729. * @uses bbp_get_forum_topic_count() To get the forum topic count
  1730. * @uses bbp_get_forum_reply_count() To get the forum reply count
  1731. * @uses bbp_get_forum_freshness_link() To get the forum freshness link
  1732. * @uses bbp_get_forum_last_active_id() To get the forum last active id
  1733. * @uses bbp_get_author_link() To get the author link
  1734. * @uses add_filter() To add the 'view all' filter back
  1735. * @uses apply_filters() Calls 'bbp_get_single_forum_description' with
  1736. * the description and args
  1737. * @return string Filtered forum description
  1738. */
  1739. function bbp_get_single_forum_description( $args = '' ) {
  1740. // Parse arguments against default values
  1741. $r = bbp_parse_args( $args, array(
  1742. 'forum_id' => 0,
  1743. 'before' => '<div class="bbp-template-notice info"><p class="bbp-forum-description">',
  1744. 'after' => '</p></div>',
  1745. 'size' => 14,
  1746. 'feed' => true
  1747. ), 'get_single_forum_description' );
  1748. // Validate forum_id
  1749. $forum_id = bbp_get_forum_id( $r['forum_id'] );
  1750. // Unhook the 'view all' query var adder
  1751. remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
  1752. // Get some forum data
  1753. $tc_int = bbp_get_forum_topic_count( $forum_id, false );
  1754. $rc_int = bbp_get_forum_reply_count( $forum_id, false );
  1755. $topic_count = bbp_get_forum_topic_count( $forum_id );
  1756. $reply_count = bbp_get_forum_reply_count( $forum_id );
  1757. $last_active = bbp_get_forum_last_active_id( $forum_id );
  1758. // Has replies
  1759. if ( !empty( $reply_count ) ) {
  1760. $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count );
  1761. }
  1762. // Forum has active data
  1763. if ( !empty( $last_active ) ) {
  1764. $topic_text = bbp_get_forum_topics_link( $forum_id );
  1765. $time_since = bbp_get_forum_freshness_link( $forum_id );
  1766. $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) );
  1767. // Forum has no last active data
  1768. } else {
  1769. $topic_text = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count );
  1770. }
  1771. // Forum has active data
  1772. if ( !empty( $last_active ) ) {
  1773. if ( !empty( $reply_count ) ) {
  1774. if ( bbp_is_forum_category( $forum_id ) ) {
  1775. $retstr = sprintf( esc_html__( 'This category contains %1$s and %2$s, and was last updated by %3$s %4$s.', 'bbpress' ), $topic_text, $reply_text, $last_updated_by, $time_since );
  1776. } else {
  1777. $retstr = sprintf( esc_html__( 'This forum contains %1$s and %2$s, and was last updated by %3$s %4$s.', 'bbpress' ), $topic_text, $reply_text, $last_updated_by, $time_since );
  1778. }
  1779. } else {
  1780. if ( bbp_is_forum_category( $forum_id ) ) {
  1781. $retstr = sprintf( esc_html__( 'This category contains %1$s, and was last updated by %2$s %3$s.', 'bbpress' ), $topic_text, $last_updated_by, $time_since );
  1782. } else {
  1783. $retstr = sprintf( esc_html__( 'This forum contains %1$s, and was last updated by %2$s %3$s.', 'bbpress' ), $topic_text, $last_updated_by, $time_since );
  1784. }
  1785. }
  1786. // Forum has no last active data
  1787. } else {
  1788. if ( !empty( $reply_count ) ) {
  1789. if ( bbp_is_forum_category( $forum_id ) ) {
  1790. $retstr = sprintf( esc_html__( 'This category contains %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text );
  1791. } else {
  1792. $retstr = sprintf( esc_html__( 'This forum contains %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text );
  1793. }
  1794. } else {
  1795. if ( !empty( $topic_count ) ) {
  1796. if ( bbp_is_forum_category( $forum_id ) ) {
  1797. $retstr = sprintf( esc_html__( 'This category contains %1$s.', 'bbpress' ), $topic_text );
  1798. } else {
  1799. $retstr = sprintf( esc_html__( 'This forum contains %1$s.', 'bbpress' ), $topic_text );
  1800. }
  1801. } else {
  1802. $retstr = esc_html__( 'This forum is empty.', 'bbpress' );
  1803. }
  1804. }
  1805. }
  1806. // Add feeds
  1807. //$feed_links = ( !empty( $r['feed'] ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : '';
  1808. // Add the 'view all' filter back
  1809. add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
  1810. // Combine the elements together
  1811. $retstr = $r['before'] . $retstr . $r['after'];
  1812. // Return filtered result
  1813. return apply_filters( 'bbp_get_single_forum_description', $retstr, $r );
  1814. }
  1815. /** Forms *********************************************************************/
  1816. /**
  1817. * Output the value of forum title field
  1818. *
  1819. * @since bbPress (r3551)
  1820. *
  1821. * @uses bbp_get_form_forum_title() To get the value of forum title field
  1822. */
  1823. function bbp_form_forum_title() {
  1824. echo bbp_get_form_forum_title();
  1825. }
  1826. /**
  1827. * Return the value of forum title field
  1828. *
  1829. * @since bbPress (r3551)
  1830. *
  1831. * @uses bbp_is_forum_edit() To check if it's forum edit page
  1832. * @uses apply_filters() Calls 'bbp_get_form_forum_title' with the title
  1833. * @return string Value of forum title field
  1834. */
  1835. function bbp_get_form_forum_title() {
  1836. // Get _POST data
  1837. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_title'] ) ) {
  1838. $forum_title = $_POST['bbp_forum_title'];
  1839. // Get edit data
  1840. } elseif ( bbp_is_forum_edit() ) {
  1841. $forum_title = bbp_get_global_post_field( 'post_title', 'raw' );
  1842. // No data
  1843. } else {
  1844. $forum_title = '';
  1845. }
  1846. return apply_filters( 'bbp_get_form_forum_title', esc_attr( $forum_title ) );
  1847. }
  1848. /**
  1849. * Output the value of forum content field
  1850. *
  1851. * @since bbPress (r3551)
  1852. *
  1853. * @uses bbp_get_form_forum_content() To get value of forum content field
  1854. */
  1855. function bbp_form_forum_content() {
  1856. echo bbp_get_form_forum_content();
  1857. }
  1858. /**
  1859. * Return the value of forum content field
  1860. *
  1861. * @since bbPress (r3551)
  1862. *
  1863. * @uses bbp_is_forum_edit() To check if it's the forum edit page
  1864. * @uses apply_filters() Calls 'bbp_get_form_forum_content' with the content
  1865. * @return string Value of forum content field
  1866. */
  1867. function bbp_get_form_forum_content() {
  1868. // Get _POST data
  1869. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_content'] ) ) {
  1870. $forum_content = stripslashes( $_POST['bbp_forum_content'] );
  1871. // Get edit data
  1872. } elseif ( bbp_is_forum_edit() ) {
  1873. $forum_content = bbp_get_global_post_field( 'post_content', 'raw' );
  1874. // No data
  1875. } else {
  1876. $forum_content = '';
  1877. }
  1878. return apply_filters( 'bbp_get_form_forum_content', $forum_content );
  1879. }
  1880. /**
  1881. * Output value of forum parent
  1882. *
  1883. * @since bbPress (r3551)
  1884. *
  1885. * @uses bbp_get_form_forum_parent() To get the topic's forum id
  1886. */
  1887. function bbp_form_forum_parent() {
  1888. echo bbp_get_form_forum_parent();
  1889. }
  1890. /**
  1891. * Return value of forum parent
  1892. *
  1893. * @since bbPress (r3551)
  1894. *
  1895. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  1896. * @uses bbp_get_forum_parent_id() To get the topic forum id
  1897. * @uses apply_filters() Calls 'bbp_get_form_forum_parent' with the forum
  1898. * @return string Value of topic content field
  1899. */
  1900. function bbp_get_form_forum_parent() {
  1901. // Get _POST data
  1902. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_id'] ) ) {
  1903. $forum_parent = $_POST['bbp_forum_id'];
  1904. // Get edit data
  1905. } elseif ( bbp_is_forum_edit() ) {
  1906. $forum_parent = bbp_get_forum_parent_id();
  1907. // No data
  1908. } else {
  1909. $forum_parent = 0;
  1910. }
  1911. return apply_filters( 'bbp_get_form_forum_parent', esc_attr( $forum_parent ) );
  1912. }
  1913. /**
  1914. * Output value of forum type
  1915. *
  1916. * @since bbPress (r3563)
  1917. *
  1918. * @uses bbp_get_form_forum_type() To get the topic's forum id
  1919. */
  1920. function bbp_form_forum_type() {
  1921. echo bbp_get_form_forum_type();
  1922. }
  1923. /**
  1924. * Return value of forum type
  1925. *
  1926. * @since bbPress (r3563)
  1927. *
  1928. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  1929. * @uses bbp_get_forum_type_id() To get the topic forum id
  1930. * @uses apply_filters() Calls 'bbp_get_form_forum_type' with the forum
  1931. * @return string Value of topic content field
  1932. */
  1933. function bbp_get_form_forum_type() {
  1934. // Get _POST data
  1935. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_type'] ) ) {
  1936. $forum_type = $_POST['bbp_forum_type'];
  1937. // Get edit data
  1938. } elseif ( bbp_is_forum_edit() ) {
  1939. $forum_type = bbp_get_forum_type();
  1940. // No data
  1941. } else {
  1942. $forum_type = 'forum';
  1943. }
  1944. return apply_filters( 'bbp_get_form_forum_type', esc_attr( $forum_type ) );
  1945. }
  1946. /**
  1947. * Output value of forum visibility
  1948. *
  1949. * @since bbPress (r3563)
  1950. *
  1951. * @uses bbp_get_form_forum_visibility() To get the topic's forum id
  1952. */
  1953. function bbp_form_forum_visibility() {
  1954. echo bbp_get_form_forum_visibility();
  1955. }
  1956. /**
  1957. * Return value of forum visibility
  1958. *
  1959. * @since bbPress (r3563)
  1960. *
  1961. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  1962. * @uses bbp_get_forum_visibility_id() To get the topic forum id
  1963. * @uses apply_filters() Calls 'bbp_get_form_forum_visibility' with the forum
  1964. * @return string Value of topic content field
  1965. */
  1966. function bbp_get_form_forum_visibility() {
  1967. // Get _POST data
  1968. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) {
  1969. $forum_visibility = $_POST['bbp_forum_visibility'];
  1970. // Get edit data
  1971. } elseif ( bbp_is_forum_edit() ) {
  1972. $forum_visibility = bbp_get_forum_visibility();
  1973. // No data
  1974. } else {
  1975. $forum_visibility = bbpress()->public_status_id;
  1976. }
  1977. return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) );
  1978. }
  1979. /**
  1980. * Output checked value of forum subscription
  1981. *
  1982. * @since bbPress (r5156)
  1983. *
  1984. * @uses bbp_get_form_forum_subscribed() To get the subscribed checkbox value
  1985. */
  1986. function bbp_form_forum_subscribed() {
  1987. echo bbp_get_form_forum_subscribed();
  1988. }
  1989. /**
  1990. * Return checked value of forum subscription
  1991. *
  1992. * @since bbPress (r5156)
  1993. *
  1994. * @uses bbp_is_forum_edit() To check if it's the forum edit page
  1995. * @uses bbp_get_global_post_field() To get current post author
  1996. * @uses bbp_get_current_user_id() To get the current user id
  1997. * @uses bbp_is_user_subscribed_to_forum() To check if the user is
  1998. * subscribed to the forum
  1999. * @uses apply_filters() Calls 'bbp_get_form_forum_subscribed' with the
  2000. * option
  2001. * @return string Checked value of forum subscription
  2002. */
  2003. function bbp_get_form_forum_subscribed() {
  2004. // Get _POST data
  2005. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) {
  2006. $forum_subscribed = (bool) $_POST['bbp_forum_subscription'];
  2007. // Get edit data
  2008. } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) {
  2009. // Get current posts author
  2010. $post_author = bbp_get_global_post_field( 'post_author', 'raw' );
  2011. // Post author is not the current user
  2012. if ( bbp_get_current_user_id() !== $post_author ) {
  2013. $forum_subscribed = bbp_is_user_subscribed_to_forum( $post_author );
  2014. // Post author is the current user
  2015. } else {
  2016. $forum_subscribed = bbp_is_user_subscribed_to_forum( bbp_get_current_user_id() );
  2017. }
  2018. // Get current status
  2019. } elseif ( bbp_is_single_forum() ) {
  2020. $forum_subscribed = bbp_is_user_subscribed_to_forum( bbp_get_current_user_id() );
  2021. // No data
  2022. } else {
  2023. $forum_subscribed = false;
  2024. }
  2025. // Get checked output
  2026. $checked = checked( $forum_subscribed, true, false );
  2027. return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed );
  2028. }
  2029. /** Form Dropdowns ************************************************************/
  2030. /**
  2031. * Output value forum type dropdown
  2032. *
  2033. * @since bbPress (r3563)
  2034. *
  2035. * @param int $forum_id The forum id to use
  2036. * @uses bbp_get_form_forum_type() To get the topic's forum id
  2037. */
  2038. function bbp_form_forum_type_dropdown( $args = '' ) {
  2039. echo bbp_get_form_forum_type_dropdown( $args );
  2040. }
  2041. /**
  2042. * Return the forum type dropdown
  2043. *
  2044. * @since bbPress (r3563)
  2045. *
  2046. * @param int $forum_id The forum id to use
  2047. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  2048. * @uses bbp_get_forum_type() To get the forum type
  2049. * @uses apply_filters()
  2050. * @return string HTML select list for selecting forum type
  2051. */
  2052. function bbp_get_form_forum_type_dropdown( $args = '' ) {
  2053. // Backpat for handling passing of a forum ID as integer
  2054. if ( is_int( $args ) ) {
  2055. $forum_id = (int) $args;
  2056. $args = array();
  2057. } else {
  2058. $forum_id = 0;
  2059. }
  2060. // Parse arguments against default values
  2061. $r = bbp_parse_args( $args, array(
  2062. 'select_id' => 'bbp_forum_type',
  2063. 'tab' => bbp_get_tab_index(),
  2064. 'forum_id' => $forum_id,
  2065. 'selected' => false
  2066. ), 'forum_type_select' );
  2067. // No specific selected value passed
  2068. if ( empty( $r['selected'] ) ) {
  2069. // Post value is passed
  2070. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
  2071. $r['selected'] = $_POST[ $r['select_id'] ];
  2072. // No Post value was passed
  2073. } else {
  2074. // Edit topic
  2075. if ( bbp_is_forum_edit() ) {
  2076. $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
  2077. $r['selected'] = bbp_get_forum_type( $r['forum_id'] );
  2078. // New topic
  2079. } else {
  2080. $r['selected'] = bbp_get_public_status_id();
  2081. }
  2082. }
  2083. }
  2084. // Used variables
  2085. $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
  2086. // Start an output buffer, we'll finish it after the select loop
  2087. ob_start(); ?>
  2088. <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
  2089. <?php foreach ( bbp_get_forum_types() as $key => $label ) : ?>
  2090. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
  2091. <?php endforeach; ?>
  2092. </select>
  2093. <?php
  2094. // Return the results
  2095. return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r );
  2096. }
  2097. /**
  2098. * Output value forum status dropdown
  2099. *
  2100. * @since bbPress (r3563)
  2101. *
  2102. * @param int $forum_id The forum id to use
  2103. * @uses bbp_get_form_forum_status() To get the topic's forum id
  2104. */
  2105. function bbp_form_forum_status_dropdown( $args = '' ) {
  2106. echo bbp_get_form_forum_status_dropdown( $args );
  2107. }
  2108. /**
  2109. * Return the forum status dropdown
  2110. *
  2111. * @since bbPress (r3563)
  2112. *
  2113. * @param int $forum_id The forum id to use
  2114. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  2115. * @uses bbp_get_forum_status() To get the forum status
  2116. * @uses apply_filters()
  2117. * @return string HTML select list for selecting forum status
  2118. */
  2119. function bbp_get_form_forum_status_dropdown( $args = '' ) {
  2120. // Backpat for handling passing of a forum ID
  2121. if ( is_int( $args ) ) {
  2122. $forum_id = (int) $args;
  2123. $args = array();
  2124. } else {
  2125. $forum_id = 0;
  2126. }
  2127. // Parse arguments against default values
  2128. $r = bbp_parse_args( $args, array(
  2129. 'select_id' => 'bbp_forum_status',
  2130. 'tab' => bbp_get_tab_index(),
  2131. 'forum_id' => $forum_id,
  2132. 'selected' => false
  2133. ), 'forum_status_select' );
  2134. // No specific selected value passed
  2135. if ( empty( $r['selected'] ) ) {
  2136. // Post value is passed
  2137. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
  2138. $r['selected'] = $_POST[ $r['select_id'] ];
  2139. // No Post value was passed
  2140. } else {
  2141. // Edit topic
  2142. if ( bbp_is_forum_edit() ) {
  2143. $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
  2144. $r['selected'] = bbp_get_forum_status( $r['forum_id'] );
  2145. // New topic
  2146. } else {
  2147. $r['selected'] = bbp_get_public_status_id();
  2148. }
  2149. }
  2150. }
  2151. // Used variables
  2152. $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
  2153. // Start an output buffer, we'll finish it after the select loop
  2154. ob_start(); ?>
  2155. <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
  2156. <?php foreach ( bbp_get_forum_statuses() as $key => $label ) : ?>
  2157. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
  2158. <?php endforeach; ?>
  2159. </select>
  2160. <?php
  2161. // Return the results
  2162. return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r );
  2163. }
  2164. /**
  2165. * Output value forum visibility dropdown
  2166. *
  2167. * @since bbPress (r3563)
  2168. *
  2169. * @param int $forum_id The forum id to use
  2170. * @uses bbp_get_form_forum_visibility() To get the topic's forum id
  2171. */
  2172. function bbp_form_forum_visibility_dropdown( $args = '' ) {
  2173. echo bbp_get_form_forum_visibility_dropdown( $args );
  2174. }
  2175. /**
  2176. * Return the forum visibility dropdown
  2177. *
  2178. * @since bbPress (r3563)
  2179. *
  2180. * @param int $forum_id The forum id to use
  2181. * @uses bbp_is_topic_edit() To check if it's the topic edit page
  2182. * @uses bbp_get_forum_visibility() To get the forum visibility
  2183. * @uses apply_filters()
  2184. * @return string HTML select list for selecting forum visibility
  2185. */
  2186. function bbp_get_form_forum_visibility_dropdown( $args = '' ) {
  2187. // Backpat for handling passing of a forum ID
  2188. if ( is_int( $args ) ) {
  2189. $forum_id = (int) $args;
  2190. $args = array();
  2191. } else {
  2192. $forum_id = 0;
  2193. }
  2194. // Parse arguments against default values
  2195. $r = bbp_parse_args( $args, array(
  2196. 'select_id' => 'bbp_forum_visibility',
  2197. 'tab' => bbp_get_tab_index(),
  2198. 'forum_id' => $forum_id,
  2199. 'selected' => false
  2200. ), 'forum_type_select' );
  2201. // No specific selected value passed
  2202. if ( empty( $r['selected'] ) ) {
  2203. // Post value is passed
  2204. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
  2205. $r['selected'] = $_POST[ $r['select_id'] ];
  2206. // No Post value was passed
  2207. } else {
  2208. // Edit topic
  2209. if ( bbp_is_forum_edit() ) {
  2210. $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
  2211. $r['selected'] = bbp_get_forum_visibility( $r['forum_id'] );
  2212. // New topic
  2213. } else {
  2214. $r['selected'] = bbp_get_public_status_id();
  2215. }
  2216. }
  2217. }
  2218. // Used variables
  2219. $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
  2220. // Start an output buffer, we'll finish it after the select loop
  2221. ob_start(); ?>
  2222. <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>>
  2223. <?php foreach ( bbp_get_forum_visibilities() as $key => $label ) : ?>
  2224. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
  2225. <?php endforeach; ?>
  2226. </select>
  2227. <?php
  2228. // Return the results
  2229. return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r );
  2230. }
  2231. /** Feeds *********************************************************************/
  2232. /**
  2233. * Output the link for the forum feed
  2234. *
  2235. * @since bbPress (r3172)
  2236. *
  2237. * @param type $forum_id Optional. Forum ID.
  2238. *
  2239. * @uses bbp_get_forum_topics_feed_link()
  2240. */
  2241. function bbp_forum_topics_feed_link( $forum_id = 0 ) {
  2242. echo bbp_get_forum_topics_feed_link( $forum_id );
  2243. }
  2244. /**
  2245. * Retrieve the link for the forum feed
  2246. *
  2247. * @since bbPress (r3172)
  2248. *
  2249. * @param int $forum_id Optional. Forum ID.
  2250. *
  2251. * @uses bbp_get_forum_id()
  2252. * @uses get_option()
  2253. * @uses trailingslashit()
  2254. * @uses bbp_get_forum_permalink()
  2255. * @uses user_trailingslashit()
  2256. * @uses bbp_get_forum_post_type()
  2257. * @uses get_post_field()
  2258. * @uses apply_filters()
  2259. *
  2260. * @return string
  2261. */
  2262. function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
  2263. // Validate forum id
  2264. $forum_id = bbp_get_forum_id( $forum_id );
  2265. // Forum is valid
  2266. if ( !empty( $forum_id ) ) {
  2267. // Define local variable(s)
  2268. $link = '';
  2269. // Pretty permalinks
  2270. if ( get_option( 'permalink_structure' ) ) {
  2271. // Forum link
  2272. $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
  2273. $url = user_trailingslashit( $url, 'single_feed' );
  2274. // Unpretty permalinks
  2275. } else {
  2276. $url = home_url( add_query_arg( array(
  2277. 'feed' => 'rss2',
  2278. bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
  2279. ) ) );
  2280. }
  2281. $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link topics"><span>' . esc_attr__( 'Topics', 'bbpress' ) . '</span></a>';
  2282. }
  2283. return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
  2284. }
  2285. /**
  2286. * Output the link for the forum replies feed
  2287. *
  2288. * @since bbPress (r3172)
  2289. *
  2290. * @param type $forum_id Optional. Forum ID.
  2291. *
  2292. * @uses bbp_get_forum_replies_feed_link()
  2293. */
  2294. function bbp_forum_replies_feed_link( $forum_id = 0 ) {
  2295. echo bbp_get_forum_replies_feed_link( $forum_id );
  2296. }
  2297. /**
  2298. * Retrieve the link for the forum replies feed
  2299. *
  2300. * @since bbPress (r3172)
  2301. *
  2302. * @param int $forum_id Optional. Forum ID.
  2303. *
  2304. * @uses bbp_get_forum_id()
  2305. * @uses get_option()
  2306. * @uses trailingslashit()
  2307. * @uses bbp_get_forum_permalink()
  2308. * @uses user_trailingslashit()
  2309. * @uses bbp_get_forum_post_type()
  2310. * @uses get_post_field()
  2311. * @uses apply_filters()
  2312. *
  2313. * @return string
  2314. */
  2315. function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
  2316. // Validate forum id
  2317. $forum_id = bbp_get_forum_id( $forum_id );
  2318. // Forum is valid
  2319. if ( !empty( $forum_id ) ) {
  2320. // Define local variable(s)
  2321. $link = '';
  2322. // Pretty permalinks
  2323. if ( get_option( 'permalink_structure' ) ) {
  2324. // Forum link
  2325. $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
  2326. $url = user_trailingslashit( $url, 'single_feed' );
  2327. $url = add_query_arg( array( 'type' => 'reply' ), $url );
  2328. // Unpretty permalinks
  2329. } else {
  2330. $url = home_url( add_query_arg( array(
  2331. 'type' => 'reply',
  2332. 'feed' => 'rss2',
  2333. bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
  2334. ) ) );
  2335. }
  2336. $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link replies"><span>' . esc_html__( 'Replies', 'bbpress' ) . '</span></a>';
  2337. }
  2338. return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
  2339. }