/includes/forums/template.php

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