/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 bbp_get_forum_topic_count_hidden() To get the forum hidden 
  1150. * topic count 
  1151. * @uses current_user_can() To check if the current user can edit others 
  1152. * topics 
  1153. * @uses add_query_arg() To add custom args to the url 
  1154. * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the 
  1155. * topics link and forum id 
  1156. */ 
  1157. function bbp_get_forum_topics_link( $forum_id = 0 ) { 
  1158. $forum = bbp_get_forum( $forum_id ); 
  1159. $forum_id = $forum->ID; 
  1160. $topics = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, false ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id ) ); 
  1161. $retval = ''; 
  1162.  
  1163. // First link never has view=all 
  1164. if ( bbp_get_view_all( 'edit_others_topics' ) ) 
  1165. $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_forum_permalink( $forum_id ) ) ) . "'>" . esc_html( $topics ) . "</a>"; 
  1166. else 
  1167. $retval .= esc_html( $topics ); 
  1168.  
  1169. // Get deleted topics 
  1170. $deleted = bbp_get_forum_topic_count_hidden( $forum_id ); 
  1171.  
  1172. // This forum has hidden topics 
  1173. if ( !empty( $deleted ) && current_user_can( 'edit_others_topics' ) ) { 
  1174.  
  1175. // Extra text 
  1176. $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted ); 
  1177.  
  1178. // No link 
  1179. if ( bbp_get_view_all() ) { 
  1180. $retval .= " $extra"; 
  1181.  
  1182. // Link 
  1183. } else { 
  1184. $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_forum_permalink( $forum_id ), true ) ) . "'>" . esc_html( $extra ) . "</a>"; 
  1185.  
  1186. return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id ); 
  1187.  
  1188. /** 
  1189. * Output total sub-forum count of a forum 
  1190. * 
  1191. * @since bbPress (r2464) 
  1192. * 
  1193. * @param int $forum_id Optional. Forum id to check 
  1194. * @param boolean $integer Optional. Whether or not to format the result 
  1195. * @uses bbp_get_forum_subforum_count() To get the forum's subforum count 
  1196. */ 
  1197. function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) { 
  1198. echo bbp_get_forum_subforum_count( $forum_id, $integer ); 
  1199. /** 
  1200. * Return total subforum count of a forum 
  1201. * 
  1202. * @since bbPress (r2464) 
  1203. * 
  1204. * @param int $forum_id Optional. Forum id 
  1205. * @param boolean $integer Optional. Whether or not to format the result 
  1206. * @uses bbp_get_forum_id() To get the forum id 
  1207. * @uses get_post_meta() To get the subforum count 
  1208. * @uses apply_filters() Calls 'bbp_get_forum_subforum_count' with the 
  1209. * subforum count and forum id 
  1210. * @return int Forum's subforum count 
  1211. */ 
  1212. function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) { 
  1213. $forum_id = bbp_get_forum_id( $forum_id ); 
  1214. $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ); 
  1215. $filter = ( true === $integer ) ? 'bbp_get_forum_subforum_count_int' : 'bbp_get_forum_subforum_count'; 
  1216.  
  1217. return apply_filters( $filter, $forum_count, $forum_id ); 
  1218.  
  1219. /** 
  1220. * Output total topic count of a forum 
  1221. * 
  1222. * @since bbPress (r2464) 
  1223. * 
  1224. * @param int $forum_id Optional. Forum id 
  1225. * @param bool $total_count Optional. To get the total count or normal count? 
  1226. * @param boolean $integer Optional. Whether or not to format the result 
  1227. * @uses bbp_get_forum_topic_count() To get the forum topic count 
  1228. */ 
  1229. function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) { 
  1230. echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer ); 
  1231. /** 
  1232. * Return total topic count of a forum 
  1233. * 
  1234. * @since bbPress (r2464) 
  1235. * 
  1236. * @param int $forum_id Optional. Forum id 
  1237. * @param bool $total_count Optional. To get the total count or normal 
  1238. * count? Defaults to total. 
  1239. * @param boolean $integer Optional. Whether or not to format the result 
  1240. * @uses bbp_get_forum_id() To get the forum id 
  1241. * @uses get_post_meta() To get the forum topic count 
  1242. * @uses apply_filters() Calls 'bbp_get_forum_topic_count' with the 
  1243. * topic count and forum id 
  1244. * @return int Forum topic count 
  1245. */ 
  1246. function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) { 
  1247. $forum_id = bbp_get_forum_id( $forum_id ); 
  1248. $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count'; 
  1249. $topics = (int) get_post_meta( $forum_id, $meta_key, true ); 
  1250. $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_int' : 'bbp_get_forum_topic_count'; 
  1251.  
  1252. return apply_filters( $filter, $topics, $forum_id ); 
  1253.  
  1254. /** 
  1255. * Output total reply count of a forum 
  1256. * 
  1257. * @since bbPress (r2464) 
  1258. * 
  1259. * @param int $forum_id Optional. Forum id 
  1260. * @param bool $total_count Optional. To get the total count or normal count? 
  1261. * @param boolean $integer Optional. Whether or not to format the result 
  1262. * @uses bbp_get_forum_reply_count() To get the forum reply count 
  1263. */ 
  1264. function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) { 
  1265. echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer ); 
  1266. /** 
  1267. * Return total post count of a forum 
  1268. * 
  1269. * @since bbPress (r2464) 
  1270. * 
  1271. * @param int $forum_id Optional. Forum id 
  1272. * @param bool $total_count Optional. To get the total count or normal 
  1273. * count? 
  1274. * @param boolean $integer Optional. Whether or not to format the result 
  1275. * @uses bbp_get_forum_id() To get the forum id 
  1276. * @uses get_post_meta() To get the forum reply count 
  1277. * @uses apply_filters() Calls 'bbp_get_forum_reply_count' with the 
  1278. * reply count and forum id 
  1279. * @return int Forum reply count 
  1280. */ 
  1281. function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) { 
  1282. $forum_id = bbp_get_forum_id( $forum_id ); 
  1283. $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; 
  1284. $replies = (int) get_post_meta( $forum_id, $meta_key, true ); 
  1285. $filter = ( true === $integer ) ? 'bbp_get_forum_reply_count_int' : 'bbp_get_forum_reply_count'; 
  1286.  
  1287. return apply_filters( $filter, $replies, $forum_id ); 
  1288.  
  1289. /** 
  1290. * Output total post count of a forum 
  1291. * 
  1292. * @since bbPress (r2954) 
  1293. * 
  1294. * @param int $forum_id Optional. Forum id 
  1295. * @param bool $total_count Optional. To get the total count or normal count? 
  1296. * @param boolean $integer Optional. Whether or not to format the result 
  1297. * @uses bbp_get_forum_post_count() To get the forum post count 
  1298. */ 
  1299. function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) { 
  1300. echo bbp_get_forum_post_count( $forum_id, $total_count, $integer ); 
  1301. /** 
  1302. * Return total post count of a forum 
  1303. * 
  1304. * @since bbPress (r2954) 
  1305. * 
  1306. * @param int $forum_id Optional. Forum id 
  1307. * @param bool $total_count Optional. To get the total count or normal 
  1308. * count? 
  1309. * @param boolean $integer Optional. Whether or not to format the result 
  1310. * @uses bbp_get_forum_id() To get the forum id 
  1311. * @uses get_post_meta() To get the forum post count 
  1312. * @uses apply_filters() Calls 'bbp_get_forum_post_count' with the 
  1313. * post count and forum id 
  1314. * @return int Forum post count 
  1315. */ 
  1316. function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) { 
  1317. $forum_id = bbp_get_forum_id( $forum_id ); 
  1318. $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true ); 
  1319. $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; 
  1320. $replies = (int) get_post_meta( $forum_id, $meta_key, true ); 
  1321. $retval = $replies + $topics; 
  1322. $filter = ( true === $integer ) ? 'bbp_get_forum_post_count_int' : 'bbp_get_forum_post_count'; 
  1323.  
  1324. return apply_filters( $filter, $retval, $forum_id ); 
  1325.  
  1326. /** 
  1327. * Output total hidden topic count of a forum (hidden includes trashed and 
  1328. * spammed topics) 
  1329. * 
  1330. * @since bbPress (r2883) 
  1331. * 
  1332. * @param int $forum_id Optional. Topic id 
  1333. * @param boolean $integer Optional. Whether or not to format the result 
  1334. * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count 
  1335. */ 
  1336. function bbp_forum_topic_count_hidden( $forum_id = 0, $integer = false ) { 
  1337. echo bbp_get_forum_topic_count_hidden( $forum_id, $integer ); 
  1338. /** 
  1339. * Return total hidden topic count of a forum (hidden includes trashed 
  1340. * and spammed topics) 
  1341. * 
  1342. * @since bbPress (r2883) 
  1343. * 
  1344. * @param int $forum_id Optional. Topic id 
  1345. * @param boolean $integer Optional. Whether or not to format the result 
  1346. * @uses bbp_get_forum_id() To get the forum id 
  1347. * @uses get_post_meta() To get the hidden topic count 
  1348. * @uses apply_filters() Calls 'bbp_get_forum_topic_count_hidden' with 
  1349. * the hidden topic count and forum id 
  1350. * @return int Topic hidden topic count 
  1351. */ 
  1352. function bbp_get_forum_topic_count_hidden( $forum_id = 0, $integer = false ) { 
  1353. $forum_id = bbp_get_forum_id( $forum_id ); 
  1354. $topics = (int) get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ); 
  1355. $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_hidden_int' : 'bbp_get_forum_topic_count_hidden'; 
  1356.  
  1357. return apply_filters( $filter, $topics, $forum_id ); 
  1358.  
  1359. /** 
  1360. * Output the status of the forum 
  1361. * 
  1362. * @since bbPress (r2667) 
  1363. * 
  1364. * @param int $forum_id Optional. Forum id 
  1365. * @uses bbp_get_forum_status() To get the forum status 
  1366. */ 
  1367. function bbp_forum_status( $forum_id = 0 ) { 
  1368. echo bbp_get_forum_status( $forum_id ); 
  1369. /** 
  1370. * Return the status of the forum 
  1371. * 
  1372. * @since bbPress (r2667) 
  1373. * 
  1374. * @param int $forum_id Optional. Forum id 
  1375. * @uses bbp_get_forum_id() To get the forum id 
  1376. * @uses get_post_status() To get the forum's status 
  1377. * @uses apply_filters() Calls 'bbp_get_forum_status' with the status 
  1378. * and forum id 
  1379. * @return string Status of forum 
  1380. */ 
  1381. function bbp_get_forum_status( $forum_id = 0 ) { 
  1382. $forum_id = bbp_get_forum_id( $forum_id ); 
  1383. $status = get_post_meta( $forum_id, '_bbp_status', true ); 
  1384. if ( empty( $status ) ) 
  1385. $status = 'open'; 
  1386.  
  1387. return apply_filters( 'bbp_get_forum_status', $status, $forum_id ); 
  1388.  
  1389. /** 
  1390. * Output the visibility of the forum 
  1391. * 
  1392. * @since bbPress (r2997) 
  1393. * 
  1394. * @param int $forum_id Optional. Forum id 
  1395. * @uses bbp_get_forum_visibility() To get the forum visibility 
  1396. */ 
  1397. function bbp_forum_visibility( $forum_id = 0 ) { 
  1398. echo bbp_get_forum_visibility( $forum_id ); 
  1399. /** 
  1400. * Return the visibility of the forum 
  1401. * 
  1402. * @since bbPress (r2997) 
  1403. * 
  1404. * @param int $forum_id Optional. Forum id 
  1405. * @uses bbp_get_forum_id() To get the forum id 
  1406. * @uses get_post_visibility() To get the forum's visibility 
  1407. * @uses apply_filters() Calls 'bbp_get_forum_visibility' with the visibility 
  1408. * and forum id 
  1409. * @return string Status of forum 
  1410. */ 
  1411. function bbp_get_forum_visibility( $forum_id = 0 ) { 
  1412. $forum_id = bbp_get_forum_id( $forum_id ); 
  1413.  
  1414. return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id ); 
  1415.  
  1416. /** 
  1417. * Output the type of the forum 
  1418. * 
  1419. * @since bbPress (r3563) 
  1420. * 
  1421. * @param int $forum_id Optional. Forum id 
  1422. * @uses bbp_get_forum_type() To get the forum type 
  1423. */ 
  1424. function bbp_forum_type( $forum_id = 0 ) { 
  1425. echo bbp_get_forum_type( $forum_id ); 
  1426. /** 
  1427. * Return the type of forum (category/forum/etc...) 
  1428. * 
  1429. * @since bbPress (r3563) 
  1430. * 
  1431. * @param int $forum_id Optional. Forum id 
  1432. * @uses get_post_meta() To get the forum category meta 
  1433. * @return bool Whether the forum is a category or not 
  1434. */ 
  1435. function bbp_get_forum_type( $forum_id = 0 ) { 
  1436. $forum_id = bbp_get_forum_id( $forum_id ); 
  1437. $retval = get_post_meta( $forum_id, '_bbp_forum_type', true ); 
  1438. if ( empty( $retval ) ) 
  1439. $retval = 'forum'; 
  1440.  
  1441. return apply_filters( 'bbp_get_forum_type', $retval, $forum_id ); 
  1442.  
  1443. /** 
  1444. * Is the forum a category? 
  1445. * 
  1446. * @since bbPress (r2746) 
  1447. * 
  1448. * @param int $forum_id Optional. Forum id 
  1449. * @uses bbp_get_forum_type() To get the forum type 
  1450. * @return bool Whether the forum is a category or not 
  1451. */ 
  1452. function bbp_is_forum_category( $forum_id = 0 ) { 
  1453. $forum_id = bbp_get_forum_id( $forum_id ); 
  1454. $type = bbp_get_forum_type( $forum_id ); 
  1455. $retval = ( !empty( $type ) && 'category' === $type ); 
  1456.  
  1457. return (bool) apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id ); 
  1458.  
  1459. /** 
  1460. * Is the forum open? 
  1461. * 
  1462. * @since bbPress (r2746) 
  1463. * @param int $forum_id Optional. Forum id 
  1464. * 
  1465. * @param int $forum_id Optional. Forum id 
  1466. * @uses bbp_is_forum_closed() To check if the forum is closed or not 
  1467. * @return bool Whether the forum is open or not 
  1468. */ 
  1469. function bbp_is_forum_open( $forum_id = 0 ) { 
  1470. return !bbp_is_forum_closed( $forum_id ); 
  1471.  
  1472. /** 
  1473. * Is the forum closed? 
  1474. * 
  1475. * @since bbPress (r2746) 
  1476. * 
  1477. * @param int $forum_id Optional. Forum id 
  1478. * @param bool $check_ancestors Check if the ancestors are closed (only 
  1479. * if they're a category) 
  1480. * @uses bbp_get_forum_status() To get the forum status 
  1481. * @uses bbp_get_forum_ancestors() To get the forum ancestors 
  1482. * @uses bbp_is_forum_category() To check if the forum is a category 
  1483. * @uses bbp_is_forum_closed() To check if the forum is closed 
  1484. * @return bool True if closed, false if not 
  1485. */ 
  1486. function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { 
  1487.  
  1488. $forum_id = bbp_get_forum_id( $forum_id ); 
  1489. $retval = ( bbp_get_closed_status_id() === bbp_get_forum_status( $forum_id ) ); 
  1490.  
  1491. if ( !empty( $check_ancestors ) ) { 
  1492. $ancestors = bbp_get_forum_ancestors( $forum_id ); 
  1493.  
  1494. foreach ( (array) $ancestors as $ancestor ) { 
  1495. if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) { 
  1496. $retval = true; 
  1497.  
  1498. return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors ); 
  1499.  
  1500. /** 
  1501. * Is the forum public? 
  1502. * 
  1503. * @since bbPress (r2997) 
  1504. * 
  1505. * @param int $forum_id Optional. Forum id 
  1506. * @param bool $check_ancestors Check if the ancestors are public (only if 
  1507. * they're a category) 
  1508. * @uses get_post_meta() To get the forum public meta 
  1509. * @uses bbp_get_forum_ancestors() To get the forum ancestors 
  1510. * @uses bbp_is_forum_category() To check if the forum is a category 
  1511. * @uses bbp_is_forum_closed() To check if the forum is closed 
  1512. * @return bool True if closed, false if not 
  1513. */ 
  1514. function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) { 
  1515.  
  1516. $forum_id = bbp_get_forum_id( $forum_id ); 
  1517. $visibility = bbp_get_forum_visibility( $forum_id ); 
  1518.  
  1519. // If post status is public, return true 
  1520. $retval = ( bbp_get_public_status_id() === $visibility ); 
  1521.  
  1522. // Check ancestors and inherit their privacy setting for display 
  1523. if ( !empty( $check_ancestors ) ) { 
  1524. $ancestors = bbp_get_forum_ancestors( $forum_id ); 
  1525.  
  1526. foreach ( (array) $ancestors as $ancestor ) { 
  1527. if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) { 
  1528. $retval = true; 
  1529.  
  1530. return (bool) apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors ); 
  1531.  
  1532. /** 
  1533. * Is the forum private? 
  1534. * 
  1535. * @since bbPress (r2746) 
  1536. * 
  1537. * @param int $forum_id Optional. Forum id 
  1538. * @param bool $check_ancestors Check if the ancestors are private (only if 
  1539. * they're a category) 
  1540. * @uses get_post_meta() To get the forum private meta 
  1541. * @uses bbp_get_forum_ancestors() To get the forum ancestors 
  1542. * @uses bbp_is_forum_category() To check if the forum is a category 
  1543. * @uses bbp_is_forum_closed() To check if the forum is closed 
  1544. * @return bool True if closed, false if not 
  1545. */ 
  1546. function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) { 
  1547.  
  1548. $forum_id = bbp_get_forum_id( $forum_id ); 
  1549. $visibility = bbp_get_forum_visibility( $forum_id ); 
  1550.  
  1551. // If post status is private, return true 
  1552. $retval = ( bbp_get_private_status_id() === $visibility ); 
  1553.  
  1554. // Check ancestors and inherit their privacy setting for display 
  1555. if ( !empty( $check_ancestors ) ) { 
  1556. $ancestors = bbp_get_forum_ancestors( $forum_id ); 
  1557.  
  1558. foreach ( (array) $ancestors as $ancestor ) { 
  1559. if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) { 
  1560. $retval = true; 
  1561.  
  1562. return (bool) apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors ); 
  1563.  
  1564. /** 
  1565. * Is the forum hidden? 
  1566. * 
  1567. * @since bbPress (r2997) 
  1568. * 
  1569. * @param int $forum_id Optional. Forum id 
  1570. * @param bool $check_ancestors Check if the ancestors are private (only if 
  1571. * they're a category) 
  1572. * @uses get_post_meta() To get the forum private meta 
  1573. * @uses bbp_get_forum_ancestors() To get the forum ancestors 
  1574. * @uses bbp_is_forum_category() To check if the forum is a category 
  1575. * @uses bbp_is_forum_closed() To check if the forum is closed 
  1576. * @return bool True if closed, false if not 
  1577. */ 
  1578. function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) { 
  1579.  
  1580. $forum_id = bbp_get_forum_id( $forum_id ); 
  1581. $visibility = bbp_get_forum_visibility( $forum_id ); 
  1582.  
  1583. // If post status is private, return true 
  1584. $retval = ( bbp_get_hidden_status_id() === $visibility ); 
  1585.  
  1586. // Check ancestors and inherit their privacy setting for display 
  1587. if ( !empty( $check_ancestors ) ) { 
  1588. $ancestors = bbp_get_forum_ancestors( $forum_id ); 
  1589.  
  1590. foreach ( (array) $ancestors as $ancestor ) { 
  1591. if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) { 
  1592. $retval = true; 
  1593.  
  1594. return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors ); 
  1595.  
  1596. /** 
  1597. * Output the author of the forum 
  1598. * 
  1599. * @since bbPress (r3675) 
  1600. * 
  1601. * @param int $forum_id Optional. Forum id 
  1602. * @uses bbp_get_forum_author() To get the forum author 
  1603. */ 
  1604. function bbp_forum_author_display_name( $forum_id = 0 ) { 
  1605. echo bbp_get_forum_author_display_name( $forum_id ); 
  1606. /** 
  1607. * Return the author of the forum 
  1608. * 
  1609. * @since bbPress (r3675) 
  1610. * 
  1611. * @param int $forum_id Optional. Forum id 
  1612. * @uses bbp_get_forum_id() To get the forum id 
  1613. * @uses bbp_get_forum_author_id() To get the forum author id 
  1614. * @uses get_the_author_meta() To get the display name of the author 
  1615. * @uses apply_filters() Calls 'bbp_get_forum_author' with the author 
  1616. * and forum id 
  1617. * @return string Author of forum 
  1618. */ 
  1619. function bbp_get_forum_author_display_name( $forum_id = 0 ) { 
  1620. $forum_id = bbp_get_forum_id( $forum_id ); 
  1621. $author = get_the_author_meta( 'display_name', bbp_get_forum_author_id( $forum_id ) ); 
  1622.  
  1623. return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id ); 
  1624.  
  1625. /** 
  1626. * Output the author ID of the forum 
  1627. * 
  1628. * @since bbPress (r3675) 
  1629. * 
  1630. * @param int $forum_id Optional. Forum id 
  1631. * @uses bbp_get_forum_author_id() To get the forum author id 
  1632. */ 
  1633. function bbp_forum_author_id( $forum_id = 0 ) { 
  1634. echo bbp_get_forum_author_id( $forum_id ); 
  1635. /** 
  1636. * Return the author ID of the forum 
  1637. * 
  1638. * @since bbPress (r3675) 
  1639. * 
  1640. * @param int $forum_id Optional. Forum id 
  1641. * @uses bbp_get_forum_id() To get the forum id 
  1642. * @uses get_post_field() To get the forum author id 
  1643. * @uses apply_filters() Calls 'bbp_get_forum_author_id' with the author 
  1644. * id and forum id 
  1645. * @return string Author of forum 
  1646. */ 
  1647. function bbp_get_forum_author_id( $forum_id = 0 ) { 
  1648. $forum_id = bbp_get_forum_id( $forum_id ); 
  1649. $author_id = get_post_field( 'post_author', $forum_id ); 
  1650.  
  1651. return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id ); 
  1652.  
  1653. /** 
  1654. * Replace forum meta details for users that cannot view them. 
  1655. * 
  1656. * @since bbPress (r3162) 
  1657. * 
  1658. * @param string $retval 
  1659. * @param int $forum_id 
  1660. * 
  1661. * @uses bbp_is_forum_private() 
  1662. * @uses current_user_can() 
  1663. * 
  1664. * @return string 
  1665. */ 
  1666. function bbp_suppress_private_forum_meta( $retval, $forum_id ) { 
  1667. if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) ) 
  1668. $retval = '-'; 
  1669.  
  1670. return apply_filters( 'bbp_suppress_private_forum_meta', $retval ); 
  1671.  
  1672. /** 
  1673. * Replace forum author details for users that cannot view them. 
  1674. * 
  1675. * @since bbPress (r3162) 
  1676. * 
  1677. * @param string $retval 
  1678. * @param int $forum_id 
  1679. * 
  1680. * @uses bbp_is_forum_private() 
  1681. * @uses get_post_field() 
  1682. * @uses bbp_get_topic_post_type() 
  1683. * @uses bbp_is_forum_private() 
  1684. * @uses bbp_get_topic_forum_id() 
  1685. * @uses bbp_get_reply_post_type() 
  1686. * @uses bbp_get_reply_forum_id() 
  1687. * 
  1688. * @return string 
  1689. */ 
  1690. function bbp_suppress_private_author_link( $author_link, $args ) { 
  1691.  
  1692. // Assume the author link is the return value 
  1693. $retval = $author_link; 
  1694.  
  1695. // Show the normal author link 
  1696. if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) { 
  1697.  
  1698. // What post type are we looking at? 
  1699. $post_type = get_post_field( 'post_type', $args['post_id'] ); 
  1700.  
  1701. switch ( $post_type ) { 
  1702.  
  1703. // Topic 
  1704. case bbp_get_topic_post_type() : 
  1705. if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) ) 
  1706. $retval = ''; 
  1707.  
  1708. break; 
  1709.  
  1710. // Reply 
  1711. case bbp_get_reply_post_type() : 
  1712. if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) ) 
  1713. $retval = ''; 
  1714.  
  1715. break; 
  1716.  
  1717. // Post 
  1718. default : 
  1719. if ( bbp_is_forum_private( $args['post_id'] ) ) 
  1720. $retval = ''; 
  1721.  
  1722. break; 
  1723.  
  1724. return apply_filters( 'bbp_suppress_private_author_link', $retval ); 
  1725.  
  1726. /** 
  1727. * Output the row class of a forum 
  1728. * 
  1729. * @since bbPress (r2667) 
  1730. * 
  1731. * @param int $forum_id Optional. Forum ID. 
  1732. * @param array Extra classes you can pass when calling this function 
  1733. * @uses bbp_get_forum_class() To get the row class of the forum 
  1734. */ 
  1735. function bbp_forum_class( $forum_id = 0, $classes = array() ) { 
  1736. echo bbp_get_forum_class( $forum_id, $classes ); 
  1737. /** 
  1738. * Return the row class of a forum 
  1739. * 
  1740. * @since bbPress (r2667) 
  1741. * 
  1742. * @param int $forum_id Optional. Forum ID 
  1743. * @param array Extra classes you can pass when calling this function 
  1744. * @uses bbp_get_forum_id() To validate the forum id 
  1745. * @uses bbp_is_forum_category() To see if forum is a category 
  1746. * @uses bbp_get_forum_status() To get the forum status 
  1747. * @uses bbp_get_forum_visibility() To get the forum visibility 
  1748. * @uses bbp_get_forum_parent_id() To get the forum parent id 
  1749. * @uses get_post_class() To get all the classes including ours 
  1750. * @uses apply_filters() Calls 'bbp_get_forum_class' with the classes 
  1751. * @return string Row class of the forum 
  1752. */ 
  1753. function bbp_get_forum_class( $forum_id = 0, $classes = array() ) { 
  1754. $bbp = bbpress(); 
  1755. $forum_id = bbp_get_forum_id( $forum_id ); 
  1756. $count = isset( $bbp->forum_query->current_post ) ? $bbp->forum_query->current_post : 1; 
  1757. $classes = (array) $classes; 
  1758.  
  1759. // Get some classes 
  1760. $classes[] = 'loop-item-' . $count; 
  1761. $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd'; 
  1762. $classes[] = bbp_is_forum_category( $forum_id ) ? 'status-category' : ''; 
  1763. $classes[] = bbp_get_forum_subforum_count( $forum_id ) ? 'bbp-has-subforums' : ''; 
  1764. $classes[] = bbp_get_forum_parent_id( $forum_id ) ? 'bbp-parent-forum-' . bbp_get_forum_parent_id( $forum_id ) : ''; 
  1765. $classes[] = 'bbp-forum-status-' . bbp_get_forum_status( $forum_id ); 
  1766. $classes[] = 'bbp-forum-visibility-' . bbp_get_forum_visibility( $forum_id ); 
  1767.  
  1768. // Ditch the empties 
  1769. $classes = array_filter( $classes ); 
  1770. $classes = get_post_class( $classes, $forum_id ); 
  1771.  
  1772. // Filter the results 
  1773. $classes = apply_filters( 'bbp_get_forum_class', $classes, $forum_id ); 
  1774. $retval = 'class="' . implode( ' ', $classes ) . '"'; 
  1775.  
  1776. return $retval; 
  1777.  
  1778. /** Single Forum **************************************************************/ 
  1779.  
  1780. /** 
  1781. * Output a fancy description of the current forum, including total topics,  
  1782. * total replies, and last activity. 
  1783. * 
  1784. * @since bbPress (r2860) 
  1785. * 
  1786. * @param array $args Arguments passed to alter output 
  1787. * @uses bbp_get_single_forum_description() Return the eventual output 
  1788. */ 
  1789. function bbp_single_forum_description( $args = '' ) { 
  1790. echo bbp_get_single_forum_description( $args ); 
  1791. /** 
  1792. * Return a fancy description of the current forum, including total 
  1793. * topics, total replies, and last activity. 
  1794. * 
  1795. * @since bbPress (r2860) 
  1796. * 
  1797. * @param mixed $args This function supports these arguments: 
  1798. * - forum_id: Forum id 
  1799. * - before: Before the text 
  1800. * - after: After the text 
  1801. * - size: Size of the avatar 
  1802. * @uses bbp_get_forum_id() To get the forum id 
  1803. * @uses bbp_get_forum_topic_count() To get the forum topic count 
  1804. * @uses bbp_get_forum_reply_count() To get the forum reply count 
  1805. * @uses bbp_get_forum_freshness_link() To get the forum freshness link 
  1806. * @uses bbp_get_forum_last_active_id() To get the forum last active id 
  1807. * @uses bbp_get_author_link() To get the author link 
  1808. * @uses add_filter() To add the 'view all' filter back 
  1809. * @uses apply_filters() Calls 'bbp_get_single_forum_description' with 
  1810. * the description and args 
  1811. * @return string Filtered forum description 
  1812. */ 
  1813. function bbp_get_single_forum_description( $args = '' ) { 
  1814.  
  1815. // Parse arguments against default values 
  1816. $r = bbp_parse_args( $args, array( 
  1817. 'forum_id' => 0,  
  1818. 'before' => '<div class="bbp-template-notice info"><p class="bbp-forum-description">',  
  1819. 'after' => '</p></div>',  
  1820. 'size' => 14,  
  1821. 'feed' => true 
  1822. ), 'get_single_forum_description' ); 
  1823.  
  1824. // Validate forum_id 
  1825. $forum_id = bbp_get_forum_id( $r['forum_id'] ); 
  1826.  
  1827. // Unhook the 'view all' query var adder 
  1828. remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' ); 
  1829.  
  1830. // Get some forum data 
  1831. $tc_int = bbp_get_forum_topic_count( $forum_id, false ); 
  1832. $rc_int = bbp_get_forum_reply_count( $forum_id, false ); 
  1833. $topic_count = bbp_get_forum_topic_count( $forum_id ); 
  1834. $reply_count = bbp_get_forum_reply_count( $forum_id ); 
  1835. $last_active = bbp_get_forum_last_active_id( $forum_id ); 
  1836.  
  1837. // Has replies 
  1838. if ( !empty( $reply_count ) ) { 
  1839. $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count ); 
  1840.  
  1841. // Forum has active data 
  1842. if ( !empty( $last_active ) ) { 
  1843. $topic_text = bbp_get_forum_topics_link( $forum_id ); 
  1844. $time_since = bbp_get_forum_freshness_link( $forum_id ); 
  1845. $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) ); 
  1846.  
  1847. // Forum has no last active data 
  1848. } else { 
  1849. $topic_text = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count ); 
  1850.  
  1851. // Forum has active data 
  1852. if ( !empty( $last_active ) ) { 
  1853.  
  1854. if ( !empty( $reply_count ) ) { 
  1855.  
  1856. if ( bbp_is_forum_category( $forum_id ) ) { 
  1857. $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 ); 
  1858. } else { 
  1859. $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 ); 
  1860.  
  1861. } else { 
  1862.  
  1863. if ( bbp_is_forum_category( $forum_id ) ) { 
  1864. $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 ); 
  1865. } else { 
  1866. $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 ); 
  1867.  
  1868. // Forum has no last active data 
  1869. } else { 
  1870.  
  1871. if ( !empty( $reply_count ) ) { 
  1872.  
  1873. if ( bbp_is_forum_category( $forum_id ) ) { 
  1874. $retstr = sprintf( esc_html__( 'This category contains %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text ); 
  1875. } else { 
  1876. $retstr = sprintf( esc_html__( 'This forum contains %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text ); 
  1877.  
  1878. } else { 
  1879.  
  1880. if ( !empty( $topic_count ) ) { 
  1881.  
  1882. if ( bbp_is_forum_category( $forum_id ) ) { 
  1883. $retstr = sprintf( esc_html__( 'This category contains %1$s.', 'bbpress' ), $topic_text ); 
  1884. } else { 
  1885. $retstr = sprintf( esc_html__( 'This forum contains %1$s.', 'bbpress' ), $topic_text ); 
  1886.  
  1887. } else { 
  1888. $retstr = esc_html__( 'This forum is empty.', 'bbpress' ); 
  1889.  
  1890. // Add feeds 
  1891. //$feed_links = ( !empty( $r['feed'] ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : ''; 
  1892.  
  1893. // Add the 'view all' filter back 
  1894. add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' ); 
  1895.  
  1896. // Combine the elements together 
  1897. $retstr = $r['before'] . $retstr . $r['after']; 
  1898.  
  1899. // Return filtered result 
  1900. return apply_filters( 'bbp_get_single_forum_description', $retstr, $r ); 
  1901.  
  1902. /** Forms *********************************************************************/ 
  1903.  
  1904. /** 
  1905. * Output the value of forum title field 
  1906. * 
  1907. * @since bbPress (r3551) 
  1908. * 
  1909. * @uses bbp_get_form_forum_title() To get the value of forum title field 
  1910. */ 
  1911. function bbp_form_forum_title() { 
  1912. echo bbp_get_form_forum_title(); 
  1913. /** 
  1914. * Return the value of forum title field 
  1915. * 
  1916. * @since bbPress (r3551) 
  1917. * 
  1918. * @uses bbp_is_forum_edit() To check if it's forum edit page 
  1919. * @uses apply_filters() Calls 'bbp_get_form_forum_title' with the title 
  1920. * @return string Value of forum title field 
  1921. */ 
  1922. function bbp_get_form_forum_title() { 
  1923.  
  1924. // Get _POST data 
  1925. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_title'] ) ) { 
  1926. $forum_title = $_POST['bbp_forum_title']; 
  1927.  
  1928. // Get edit data 
  1929. } elseif ( bbp_is_forum_edit() ) { 
  1930. $forum_title = bbp_get_global_post_field( 'post_title', 'raw' ); 
  1931.  
  1932. // No data 
  1933. } else { 
  1934. $forum_title = ''; 
  1935.  
  1936. return apply_filters( 'bbp_get_form_forum_title', esc_attr( $forum_title ) ); 
  1937.  
  1938. /** 
  1939. * Output the value of forum content field 
  1940. * 
  1941. * @since bbPress (r3551) 
  1942. * 
  1943. * @uses bbp_get_form_forum_content() To get value of forum content field 
  1944. */ 
  1945. function bbp_form_forum_content() { 
  1946. echo bbp_get_form_forum_content(); 
  1947. /** 
  1948. * Return the value of forum content field 
  1949. * 
  1950. * @since bbPress (r3551) 
  1951. * 
  1952. * @uses bbp_is_forum_edit() To check if it's the forum edit page 
  1953. * @uses apply_filters() Calls 'bbp_get_form_forum_content' with the content 
  1954. * @return string Value of forum content field 
  1955. */ 
  1956. function bbp_get_form_forum_content() { 
  1957.  
  1958. // Get _POST data 
  1959. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_content'] ) ) { 
  1960. $forum_content = stripslashes( $_POST['bbp_forum_content'] ); 
  1961.  
  1962. // Get edit data 
  1963. } elseif ( bbp_is_forum_edit() ) { 
  1964. $forum_content = bbp_get_global_post_field( 'post_content', 'raw' ); 
  1965.  
  1966. // No data 
  1967. } else { 
  1968. $forum_content = ''; 
  1969.  
  1970. return apply_filters( 'bbp_get_form_forum_content', $forum_content ); 
  1971.  
  1972. /** 
  1973. * Output value of forum parent 
  1974. * 
  1975. * @since bbPress (r3551) 
  1976. * 
  1977. * @uses bbp_get_form_forum_parent() To get the topic's forum id 
  1978. */ 
  1979. function bbp_form_forum_parent() { 
  1980. echo bbp_get_form_forum_parent(); 
  1981. /** 
  1982. * Return value of forum parent 
  1983. * 
  1984. * @since bbPress (r3551) 
  1985. * 
  1986. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  1987. * @uses bbp_get_forum_parent_id() To get the topic forum id 
  1988. * @uses apply_filters() Calls 'bbp_get_form_forum_parent' with the forum 
  1989. * @return string Value of topic content field 
  1990. */ 
  1991. function bbp_get_form_forum_parent() { 
  1992.  
  1993. // Get _POST data 
  1994. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_id'] ) ) { 
  1995. $forum_parent = $_POST['bbp_forum_id']; 
  1996.  
  1997. // Get edit data 
  1998. } elseif ( bbp_is_forum_edit() ) { 
  1999. $forum_parent = bbp_get_forum_parent_id(); 
  2000.  
  2001. // No data 
  2002. } else { 
  2003. $forum_parent = 0; 
  2004.  
  2005. return apply_filters( 'bbp_get_form_forum_parent', esc_attr( $forum_parent ) ); 
  2006.  
  2007. /** 
  2008. * Output value of forum type 
  2009. * 
  2010. * @since bbPress (r3563) 
  2011. * 
  2012. * @uses bbp_get_form_forum_type() To get the topic's forum id 
  2013. */ 
  2014. function bbp_form_forum_type() { 
  2015. echo bbp_get_form_forum_type(); 
  2016. /** 
  2017. * Return value of forum type 
  2018. * 
  2019. * @since bbPress (r3563) 
  2020. * 
  2021. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  2022. * @uses bbp_get_forum_type_id() To get the topic forum id 
  2023. * @uses apply_filters() Calls 'bbp_get_form_forum_type' with the forum 
  2024. * @return string Value of topic content field 
  2025. */ 
  2026. function bbp_get_form_forum_type() { 
  2027.  
  2028. // Get _POST data 
  2029. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_type'] ) ) { 
  2030. $forum_type = $_POST['bbp_forum_type']; 
  2031.  
  2032. // Get edit data 
  2033. } elseif ( bbp_is_forum_edit() ) { 
  2034. $forum_type = bbp_get_forum_type(); 
  2035.  
  2036. // No data 
  2037. } else { 
  2038. $forum_type = 'forum'; 
  2039.  
  2040. return apply_filters( 'bbp_get_form_forum_type', esc_attr( $forum_type ) ); 
  2041.  
  2042. /** 
  2043. * Output value of forum visibility 
  2044. * 
  2045. * @since bbPress (r3563) 
  2046. * 
  2047. * @uses bbp_get_form_forum_visibility() To get the topic's forum id 
  2048. */ 
  2049. function bbp_form_forum_visibility() { 
  2050. echo bbp_get_form_forum_visibility(); 
  2051. /** 
  2052. * Return value of forum visibility 
  2053. * 
  2054. * @since bbPress (r3563) 
  2055. * 
  2056. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  2057. * @uses bbp_get_forum_visibility_id() To get the topic forum id 
  2058. * @uses apply_filters() Calls 'bbp_get_form_forum_visibility' with the forum 
  2059. * @return string Value of topic content field 
  2060. */ 
  2061. function bbp_get_form_forum_visibility() { 
  2062.  
  2063. // Get _POST data 
  2064. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) { 
  2065. $forum_visibility = $_POST['bbp_forum_visibility']; 
  2066.  
  2067. // Get edit data 
  2068. } elseif ( bbp_is_forum_edit() ) { 
  2069. $forum_visibility = bbp_get_forum_visibility(); 
  2070.  
  2071. // No data 
  2072. } else { 
  2073. $forum_visibility = bbpress()->public_status_id; 
  2074.  
  2075. return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) ); 
  2076.  
  2077. /** 
  2078. * Output checked value of forum subscription 
  2079. * 
  2080. * @since bbPress (r5156) 
  2081. * 
  2082. * @uses bbp_get_form_forum_subscribed() To get the subscribed checkbox value 
  2083. */ 
  2084. function bbp_form_forum_subscribed() { 
  2085. echo bbp_get_form_forum_subscribed(); 
  2086. /** 
  2087. * Return checked value of forum subscription 
  2088. * 
  2089. * @since bbPress (r5156) 
  2090. * 
  2091. * @uses bbp_is_forum_edit() To check if it's the forum edit page 
  2092. * @uses bbp_get_global_post_field() To get current post author 
  2093. * @uses bbp_get_current_user_id() To get the current user id 
  2094. * @uses bbp_is_user_subscribed_to_forum() To check if the user is 
  2095. * subscribed to the forum 
  2096. * @uses apply_filters() Calls 'bbp_get_form_forum_subscribed' with the 
  2097. * option 
  2098. * @return string Checked value of forum subscription 
  2099. */ 
  2100. function bbp_get_form_forum_subscribed() { 
  2101.  
  2102. // Get _POST data 
  2103. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) { 
  2104. $forum_subscribed = (bool) $_POST['bbp_forum_subscription']; 
  2105.  
  2106. // Get edit data 
  2107. } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) { 
  2108.  
  2109. // Get current posts author 
  2110. $post_author = bbp_get_global_post_field( 'post_author', 'raw' ); 
  2111.  
  2112. // Post author is not the current user 
  2113. if ( bbp_get_current_user_id() !== $post_author ) { 
  2114. $forum_subscribed = bbp_is_user_subscribed_to_forum( $post_author ); 
  2115.  
  2116. // Post author is the current user 
  2117. } else { 
  2118. $forum_subscribed = bbp_is_user_subscribed_to_forum( bbp_get_current_user_id() ); 
  2119.  
  2120. // Get current status 
  2121. } elseif ( bbp_is_single_forum() ) { 
  2122. $forum_subscribed = bbp_is_user_subscribed_to_forum( bbp_get_current_user_id() ); 
  2123.  
  2124. // No data 
  2125. } else { 
  2126. $forum_subscribed = false; 
  2127.  
  2128. // Get checked output 
  2129. $checked = checked( $forum_subscribed, true, false ); 
  2130.  
  2131. return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed ); 
  2132.  
  2133. /** Form Dropdowns ************************************************************/ 
  2134.  
  2135. /** 
  2136. * Output value forum type dropdown 
  2137. * 
  2138. * @since bbPress (r3563) 
  2139. * 
  2140. * @param int $forum_id The forum id to use 
  2141. * @uses bbp_get_form_forum_type() To get the topic's forum id 
  2142. */ 
  2143. function bbp_form_forum_type_dropdown( $args = '' ) { 
  2144. echo bbp_get_form_forum_type_dropdown( $args ); 
  2145. /** 
  2146. * Return the forum type dropdown 
  2147. * 
  2148. * @since bbPress (r3563) 
  2149. * 
  2150. * @param int $forum_id The forum id to use 
  2151. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  2152. * @uses bbp_get_forum_type() To get the forum type 
  2153. * @uses apply_filters() 
  2154. * @return string HTML select list for selecting forum type 
  2155. */ 
  2156. function bbp_get_form_forum_type_dropdown( $args = '' ) { 
  2157.  
  2158. // Backpat for handling passing of a forum ID as integer 
  2159. if ( is_int( $args ) ) { 
  2160. $forum_id = (int) $args; 
  2161. $args = array(); 
  2162. } else { 
  2163. $forum_id = 0; 
  2164.  
  2165. // Parse arguments against default values 
  2166. $r = bbp_parse_args( $args, array( 
  2167. 'select_id' => 'bbp_forum_type',  
  2168. 'tab' => bbp_get_tab_index(),  
  2169. 'forum_id' => $forum_id,  
  2170. 'selected' => false 
  2171. ), 'forum_type_select' ); 
  2172.  
  2173. // No specific selected value passed 
  2174. if ( empty( $r['selected'] ) ) { 
  2175.  
  2176. // Post value is passed 
  2177. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 
  2178. $r['selected'] = $_POST[ $r['select_id'] ]; 
  2179.  
  2180. // No Post value was passed 
  2181. } else { 
  2182.  
  2183. // Edit topic 
  2184. if ( bbp_is_forum_edit() ) { 
  2185. $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] ); 
  2186. $r['selected'] = bbp_get_forum_type( $r['forum_id'] ); 
  2187.  
  2188. // New topic 
  2189. } else { 
  2190. $r['selected'] = bbp_get_public_status_id(); 
  2191.  
  2192. // Used variables 
  2193. $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; 
  2194.  
  2195. // Start an output buffer, we'll finish it after the select loop 
  2196. ob_start(); ?> 
  2197.  
  2198. <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>> 
  2199.  
  2200. <?php foreach ( bbp_get_forum_types() as $key => $label ) : ?> 
  2201.  
  2202. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 
  2203.  
  2204. <?php endforeach; ?> 
  2205.  
  2206. </select> 
  2207.  
  2208. <?php 
  2209.  
  2210. // Return the results 
  2211. return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r ); 
  2212.  
  2213. /** 
  2214. * Output value forum status dropdown 
  2215. * 
  2216. * @since bbPress (r3563) 
  2217. * 
  2218. * @param int $forum_id The forum id to use 
  2219. * @uses bbp_get_form_forum_status() To get the topic's forum id 
  2220. */ 
  2221. function bbp_form_forum_status_dropdown( $args = '' ) { 
  2222. echo bbp_get_form_forum_status_dropdown( $args ); 
  2223. /** 
  2224. * Return the forum status dropdown 
  2225. * 
  2226. * @since bbPress (r3563) 
  2227. * 
  2228. * @param int $forum_id The forum id to use 
  2229. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  2230. * @uses bbp_get_forum_status() To get the forum status 
  2231. * @uses apply_filters() 
  2232. * @return string HTML select list for selecting forum status 
  2233. */ 
  2234. function bbp_get_form_forum_status_dropdown( $args = '' ) { 
  2235.  
  2236. // Backpat for handling passing of a forum ID 
  2237. if ( is_int( $args ) ) { 
  2238. $forum_id = (int) $args; 
  2239. $args = array(); 
  2240. } else { 
  2241. $forum_id = 0; 
  2242.  
  2243. // Parse arguments against default values 
  2244. $r = bbp_parse_args( $args, array( 
  2245. 'select_id' => 'bbp_forum_status',  
  2246. 'tab' => bbp_get_tab_index(),  
  2247. 'forum_id' => $forum_id,  
  2248. 'selected' => false 
  2249. ), 'forum_status_select' ); 
  2250.  
  2251. // No specific selected value passed 
  2252. if ( empty( $r['selected'] ) ) { 
  2253.  
  2254. // Post value is passed 
  2255. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 
  2256. $r['selected'] = $_POST[ $r['select_id'] ]; 
  2257.  
  2258. // No Post value was passed 
  2259. } else { 
  2260.  
  2261. // Edit topic 
  2262. if ( bbp_is_forum_edit() ) { 
  2263. $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] ); 
  2264. $r['selected'] = bbp_get_forum_status( $r['forum_id'] ); 
  2265.  
  2266. // New topic 
  2267. } else { 
  2268. $r['selected'] = bbp_get_public_status_id(); 
  2269.  
  2270. // Used variables 
  2271. $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; 
  2272.  
  2273. // Start an output buffer, we'll finish it after the select loop 
  2274. ob_start(); ?> 
  2275.  
  2276. <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>> 
  2277.  
  2278. <?php foreach ( bbp_get_forum_statuses() as $key => $label ) : ?> 
  2279.  
  2280. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 
  2281.  
  2282. <?php endforeach; ?> 
  2283.  
  2284. </select> 
  2285.  
  2286. <?php 
  2287.  
  2288. // Return the results 
  2289. return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r ); 
  2290.  
  2291. /** 
  2292. * Output value forum visibility dropdown 
  2293. * 
  2294. * @since bbPress (r3563) 
  2295. * 
  2296. * @param int $forum_id The forum id to use 
  2297. * @uses bbp_get_form_forum_visibility() To get the topic's forum id 
  2298. */ 
  2299. function bbp_form_forum_visibility_dropdown( $args = '' ) { 
  2300. echo bbp_get_form_forum_visibility_dropdown( $args ); 
  2301. /** 
  2302. * Return the forum visibility dropdown 
  2303. * 
  2304. * @since bbPress (r3563) 
  2305. * 
  2306. * @param int $forum_id The forum id to use 
  2307. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  2308. * @uses bbp_get_forum_visibility() To get the forum visibility 
  2309. * @uses apply_filters() 
  2310. * @return string HTML select list for selecting forum visibility 
  2311. */ 
  2312. function bbp_get_form_forum_visibility_dropdown( $args = '' ) { 
  2313.  
  2314. // Backpat for handling passing of a forum ID 
  2315. if ( is_int( $args ) ) { 
  2316. $forum_id = (int) $args; 
  2317. $args = array(); 
  2318. } else { 
  2319. $forum_id = 0; 
  2320.  
  2321. // Parse arguments against default values 
  2322. $r = bbp_parse_args( $args, array( 
  2323. 'select_id' => 'bbp_forum_visibility',  
  2324. 'tab' => bbp_get_tab_index(),  
  2325. 'forum_id' => $forum_id,  
  2326. 'selected' => false 
  2327. ), 'forum_type_select' ); 
  2328.  
  2329. // No specific selected value passed 
  2330. if ( empty( $r['selected'] ) ) { 
  2331.  
  2332. // Post value is passed 
  2333. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 
  2334. $r['selected'] = $_POST[ $r['select_id'] ]; 
  2335.  
  2336. // No Post value was passed 
  2337. } else { 
  2338.  
  2339. // Edit topic 
  2340. if ( bbp_is_forum_edit() ) { 
  2341. $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] ); 
  2342. $r['selected'] = bbp_get_forum_visibility( $r['forum_id'] ); 
  2343.  
  2344. // New topic 
  2345. } else { 
  2346. $r['selected'] = bbp_get_public_status_id(); 
  2347.  
  2348. // Used variables 
  2349. $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; 
  2350.  
  2351. // Start an output buffer, we'll finish it after the select loop 
  2352. ob_start(); ?> 
  2353.  
  2354. <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select"<?php echo $tab; ?>> 
  2355.  
  2356. <?php foreach ( bbp_get_forum_visibilities() as $key => $label ) : ?> 
  2357.  
  2358. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 
  2359.  
  2360. <?php endforeach; ?> 
  2361.  
  2362. </select> 
  2363.  
  2364. <?php 
  2365.  
  2366. // Return the results 
  2367. return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r ); 
  2368.  
  2369. /** Feeds *********************************************************************/ 
  2370.  
  2371. /** 
  2372. * Output the link for the forum feed 
  2373. * 
  2374. * @since bbPress (r3172) 
  2375. * 
  2376. * @param type $forum_id Optional. Forum ID. 
  2377. * 
  2378. * @uses bbp_get_forum_topics_feed_link() 
  2379. */ 
  2380. function bbp_forum_topics_feed_link( $forum_id = 0 ) { 
  2381. echo bbp_get_forum_topics_feed_link( $forum_id ); 
  2382. /** 
  2383. * Retrieve the link for the forum feed 
  2384. * 
  2385. * @since bbPress (r3172) 
  2386. * 
  2387. * @param int $forum_id Optional. Forum ID. 
  2388. * 
  2389. * @uses bbp_get_forum_id() 
  2390. * @uses get_option() 
  2391. * @uses trailingslashit() 
  2392. * @uses bbp_get_forum_permalink() 
  2393. * @uses user_trailingslashit() 
  2394. * @uses bbp_get_forum_post_type() 
  2395. * @uses get_post_field() 
  2396. * @uses apply_filters() 
  2397. * 
  2398. * @return string 
  2399. */ 
  2400. function bbp_get_forum_topics_feed_link( $forum_id = 0 ) { 
  2401.  
  2402. // Validate forum id 
  2403. $forum_id = bbp_get_forum_id( $forum_id ); 
  2404.  
  2405. // Forum is valid 
  2406. if ( !empty( $forum_id ) ) { 
  2407.  
  2408. // Define local variable(s) 
  2409. $link = ''; 
  2410.  
  2411. // Pretty permalinks 
  2412. if ( get_option( 'permalink_structure' ) ) { 
  2413.  
  2414. // Forum link 
  2415. $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed'; 
  2416. $url = user_trailingslashit( $url, 'single_feed' ); 
  2417.  
  2418. // Unpretty permalinks 
  2419. } else { 
  2420. $url = home_url( add_query_arg( array( 
  2421. 'feed' => 'rss2',  
  2422. bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id ) 
  2423. ) ) ); 
  2424.  
  2425. $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link topics"><span>' . esc_attr__( 'Topics', 'bbpress' ) . '</span></a>'; 
  2426.  
  2427. return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id ); 
  2428.  
  2429. /** 
  2430. * Output the link for the forum replies feed 
  2431. * 
  2432. * @since bbPress (r3172) 
  2433. * 
  2434. * @param type $forum_id Optional. Forum ID. 
  2435. * 
  2436. * @uses bbp_get_forum_replies_feed_link() 
  2437. */ 
  2438. function bbp_forum_replies_feed_link( $forum_id = 0 ) { 
  2439. echo bbp_get_forum_replies_feed_link( $forum_id ); 
  2440. /** 
  2441. * Retrieve the link for the forum replies feed 
  2442. * 
  2443. * @since bbPress (r3172) 
  2444. * 
  2445. * @param int $forum_id Optional. Forum ID. 
  2446. * 
  2447. * @uses bbp_get_forum_id() 
  2448. * @uses get_option() 
  2449. * @uses trailingslashit() 
  2450. * @uses bbp_get_forum_permalink() 
  2451. * @uses user_trailingslashit() 
  2452. * @uses bbp_get_forum_post_type() 
  2453. * @uses get_post_field() 
  2454. * @uses apply_filters() 
  2455. * 
  2456. * @return string 
  2457. */ 
  2458. function bbp_get_forum_replies_feed_link( $forum_id = 0 ) { 
  2459.  
  2460. // Validate forum id 
  2461. $forum_id = bbp_get_forum_id( $forum_id ); 
  2462.  
  2463. // Forum is valid 
  2464. if ( !empty( $forum_id ) ) { 
  2465.  
  2466. // Define local variable(s) 
  2467. $link = ''; 
  2468.  
  2469. // Pretty permalinks 
  2470. if ( get_option( 'permalink_structure' ) ) { 
  2471.  
  2472. // Forum link 
  2473. $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed'; 
  2474. $url = user_trailingslashit( $url, 'single_feed' ); 
  2475. $url = add_query_arg( array( 'type' => 'reply' ), $url ); 
  2476.  
  2477. // Unpretty permalinks 
  2478. } else { 
  2479. $url = home_url( add_query_arg( array( 
  2480. 'type' => 'reply',  
  2481. 'feed' => 'rss2',  
  2482. bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id ) 
  2483. ) ) ); 
  2484.  
  2485. $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link replies"><span>' . esc_html__( 'Replies', 'bbpress' ) . '</span></a>'; 
  2486.  
  2487. return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id ); 
.