/includes/topics/template.php

  1. <?php 
  2.  
  3. /** 
  4. * bbPress Topic 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 topics 
  17. * 
  18. * @since bbPress (r2857) 
  19. * 
  20. * @uses bbp_get_topic_post_type() To get the topic post type 
  21. */ 
  22. function bbp_topic_post_type() { 
  23. echo bbp_get_topic_post_type(); 
  24. /** 
  25. * Return the unique id of the custom post type for topics 
  26. * 
  27. * @since bbPress (r2857) 
  28. * 
  29. * @uses apply_filters() Calls 'bbp_get_topic_post_type' with the topic 
  30. * post type id 
  31. * @return string The unique topic post type id 
  32. */ 
  33. function bbp_get_topic_post_type() { 
  34. return apply_filters( 'bbp_get_topic_post_type', bbpress()->topic_post_type ); 
  35.  
  36. /** 
  37. * Return array of labels used by the topic post type 
  38. * 
  39. * @since bbPress (r5129) 
  40. * 
  41. * @return array 
  42. */ 
  43. function bbp_get_topic_post_type_labels() { 
  44. return apply_filters( 'bbp_get_topic_post_type_labels', array( 
  45. 'name' => __( 'Topics', 'bbpress' ),  
  46. 'menu_name' => __( 'Topics', 'bbpress' ),  
  47. 'singular_name' => __( 'Topic', 'bbpress' ),  
  48. 'all_items' => __( 'All Topics', 'bbpress' ),  
  49. 'add_new' => __( 'New Topic', 'bbpress' ),  
  50. 'add_new_item' => __( 'Create New Topic', 'bbpress' ),  
  51. 'edit' => __( 'Edit', 'bbpress' ),  
  52. 'edit_item' => __( 'Edit Topic', 'bbpress' ),  
  53. 'new_item' => __( 'New Topic', 'bbpress' ),  
  54. 'view' => __( 'View Topic', 'bbpress' ),  
  55. 'view_item' => __( 'View Topic', 'bbpress' ),  
  56. 'search_items' => __( 'Search Topics', 'bbpress' ),  
  57. 'not_found' => __( 'No topics found', 'bbpress' ),  
  58. 'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),  
  59. 'parent_item_colon' => __( 'Forum:', 'bbpress' ) 
  60. ) ); 
  61.  
  62. /** 
  63. * Return array of topic post type rewrite settings 
  64. * 
  65. * @since bbPress (r5129) 
  66. * 
  67. * @return array 
  68. */ 
  69. function bbp_get_topic_post_type_rewrite() { 
  70. return apply_filters( 'bbp_get_topic_post_type_rewrite', array( 
  71. 'slug' => bbp_get_topic_slug(),  
  72. 'with_front' => false 
  73. ) ); 
  74.  
  75. /** 
  76. * Return array of features the topic post type supports 
  77. * 
  78. * @since bbPress (r5129) 
  79. * 
  80. * @return array 
  81. */ 
  82. function bbp_get_topic_post_type_supports() { 
  83. return apply_filters( 'bbp_get_topic_post_type_supports', array( 
  84. 'title',  
  85. 'editor',  
  86. 'revisions' 
  87. ) ); 
  88.  
  89. /** 
  90. * The plugin version of bbPress comes with two topic display options: 
  91. * - Traditional: Topics are included in the reply loop (default) 
  92. * - New Style: Topics appear as "lead" posts, ahead of replies 
  93. * 
  94. * @since bbPress (r2954) 
  95. * @param $show_lead Optional. Default false 
  96. * @return bool Yes if the topic appears as a lead, otherwise false 
  97. */ 
  98. function bbp_show_lead_topic( $show_lead = false ) { 
  99.  
  100. // Never separate the lead topic in feeds 
  101. if ( is_feed() ) 
  102. return false; 
  103.  
  104. return (bool) apply_filters( 'bbp_show_lead_topic', (bool) $show_lead ); 
  105.  
  106. /** Topic Loop ****************************************************************/ 
  107.  
  108. /** 
  109. * The main topic loop. WordPress makes this easy for us 
  110. * 
  111. * @since bbPress (r2485) 
  112. * 
  113. * @param mixed $args All the arguments supported by {@link WP_Query} 
  114. * @uses current_user_can() To check if the current user can edit other's topics 
  115. * @uses bbp_get_topic_post_type() To get the topic post type 
  116. * @uses WP_Query To make query and get the topics 
  117. * @uses is_page() To check if it's a page 
  118. * @uses bbp_is_single_forum() To check if it's a forum 
  119. * @uses bbp_get_forum_id() To get the forum id 
  120. * @uses bbp_get_paged() To get the current page value 
  121. * @uses bbp_get_super_stickies() To get the super stickies 
  122. * @uses bbp_get_stickies() To get the forum stickies 
  123. * @uses wpdb::get_results() To execute our query and get the results 
  124. * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks 
  125. * @uses get_permalink() To get the permalink 
  126. * @uses add_query_arg() To add custom args to the url 
  127. * @uses apply_filters() Calls 'bbp_topics_pagination' with the pagination args 
  128. * @uses paginate_links() To paginate the links 
  129. * @uses apply_filters() Calls 'bbp_has_topics' with 
  130. * bbPres::topic_query::have_posts() 
  131. * and bbPres::topic_query 
  132. * @return object Multidimensional array of topic information 
  133. */ 
  134. function bbp_has_topics( $args = '' ) { 
  135. global $wp_rewrite; 
  136.  
  137. /** Defaults **************************************************************/ 
  138.  
  139. // Other defaults 
  140. $default_topic_search = !empty( $_REQUEST['ts'] ) ? $_REQUEST['ts'] : false; 
  141. $default_show_stickies = (bool) ( bbp_is_single_forum() || bbp_is_topic_archive() ) && ( false === $default_topic_search ); 
  142. $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any'; 
  143.  
  144. // Default argument array 
  145. $default = array( 
  146. 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics 
  147. 'post_parent' => $default_post_parent, // Forum ID 
  148. 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time 
  149. 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',  
  150. 'order' => 'DESC', // 'ASC', 'DESC' 
  151. 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page 
  152. 'paged' => bbp_get_paged(), // Page Number 
  153. 's' => $default_topic_search, // Topic Search 
  154. 'show_stickies' => $default_show_stickies, // Ignore sticky topics? 
  155. 'max_num_pages' => false, // Maximum number of pages to show 
  156. ); 
  157.  
  158. // What are the default allowed statuses (based on user caps) 
  159. if ( bbp_get_view_all() ) { 
  160.  
  161. // Default view=all statuses 
  162. $post_statuses = array( 
  163. bbp_get_public_status_id(),  
  164. bbp_get_closed_status_id(),  
  165. bbp_get_spam_status_id(),  
  166. bbp_get_trash_status_id() 
  167. ); 
  168.  
  169. // Add support for private status 
  170. if ( current_user_can( 'read_private_topics' ) ) { 
  171. $post_statuses[] = bbp_get_private_status_id(); 
  172.  
  173. // Join post statuses together 
  174. $default['post_status'] = implode( ', ', $post_statuses ); 
  175.  
  176. // Lean on the 'perm' query var value of 'readable' to provide statuses 
  177. } else { 
  178. $default['perm'] = 'readable'; 
  179.  
  180. // Maybe query for topic tags 
  181. if ( bbp_is_topic_tag() ) { 
  182. $default['term'] = bbp_get_topic_tag_slug(); 
  183. $default['taxonomy'] = bbp_get_topic_tag_tax_id(); 
  184.  
  185. /** Setup *****************************************************************/ 
  186.  
  187. // Parse arguments against default values 
  188. $r = bbp_parse_args( $args, $default, 'has_topics' ); 
  189.  
  190. // Get bbPress 
  191. $bbp = bbpress(); 
  192.  
  193. // Call the query 
  194. $bbp->topic_query = new WP_Query( $r ); 
  195.  
  196. // Set post_parent back to 0 if originally set to 'any' 
  197. if ( 'any' === $r['post_parent'] ) 
  198. $r['post_parent'] = 0; 
  199.  
  200. // Limited the number of pages shown 
  201. if ( !empty( $r['max_num_pages'] ) ) 
  202. $bbp->topic_query->max_num_pages = $r['max_num_pages']; 
  203.  
  204. /** Stickies **************************************************************/ 
  205.  
  206. // Put sticky posts at the top of the posts array 
  207. if ( !empty( $r['show_stickies'] ) && $r['paged'] <= 1 ) { 
  208.  
  209. // Get super stickies and stickies in this forum 
  210. $stickies = bbp_get_super_stickies(); 
  211.  
  212. // Get stickies for current forum 
  213. if ( !empty( $r['post_parent'] ) ) { 
  214. $stickies = array_merge( $stickies, bbp_get_stickies( $r['post_parent'] ) ); 
  215.  
  216. // Remove any duplicate stickies 
  217. $stickies = array_unique( $stickies ); 
  218.  
  219. // We have stickies 
  220. if ( is_array( $stickies ) && !empty( $stickies ) ) { 
  221.  
  222. // Start the offset at -1 so first sticky is at correct 0 offset 
  223. $sticky_offset = -1; 
  224.  
  225. // Loop over topics and relocate stickies to the front. 
  226. foreach ( $stickies as $sticky_index => $sticky_ID ) { 
  227.  
  228. // Get the post offset from the posts array 
  229. $post_offsets = wp_filter_object_list( $bbp->topic_query->posts, array( 'ID' => $sticky_ID ), 'OR', 'ID' ); 
  230.  
  231. // Continue if no post offsets 
  232. if ( empty( $post_offsets ) ) { 
  233. continue; 
  234.  
  235. // Loop over posts in current query and splice them into position 
  236. foreach ( array_keys( $post_offsets ) as $post_offset ) { 
  237. $sticky_offset++; 
  238.  
  239. $sticky = $bbp->topic_query->posts[$post_offset]; 
  240.  
  241. // Remove sticky from current position 
  242. array_splice( $bbp->topic_query->posts, $post_offset, 1 ); 
  243.  
  244. // Move to front, after other stickies 
  245. array_splice( $bbp->topic_query->posts, $sticky_offset, 0, array( $sticky ) ); 
  246.  
  247. // Cleanup 
  248. unset( $stickies[$sticky_index] ); 
  249. unset( $sticky ); 
  250.  
  251. // Cleanup 
  252. unset( $post_offsets ); 
  253.  
  254. // Cleanup 
  255. unset( $sticky_offset ); 
  256.  
  257. // If any posts have been excluded specifically, Ignore those that are sticky. 
  258. if ( !empty( $stickies ) && !empty( $r['post__not_in'] ) ) { 
  259. $stickies = array_diff( $stickies, $r['post__not_in'] ); 
  260.  
  261. // Fetch sticky posts that weren't in the query results 
  262. if ( !empty( $stickies ) ) { 
  263.  
  264. // Query to use in get_posts to get sticky posts 
  265. $sticky_query = array( 
  266. 'post_type' => bbp_get_topic_post_type(),  
  267. 'post_parent' => 'any',  
  268. 'meta_key' => '_bbp_last_active_time',  
  269. 'orderby' => 'meta_value',  
  270. 'order' => 'DESC',  
  271. 'include' => $stickies 
  272. ); 
  273.  
  274. // Cleanup 
  275. unset( $stickies ); 
  276.  
  277. // Conditionally exclude private/hidden forum ID's 
  278. $exclude_forum_ids = bbp_exclude_forum_ids( 'array' ); 
  279. if ( ! empty( $exclude_forum_ids ) ) { 
  280. $sticky_query['post_parent__not_in'] = $exclude_forum_ids; 
  281.  
  282. // What are the default allowed statuses (based on user caps) 
  283. if ( bbp_get_view_all() ) { 
  284. $sticky_query['post_status'] = $r['post_status']; 
  285.  
  286. // Lean on the 'perm' query var value of 'readable' to provide statuses 
  287. } else { 
  288. $sticky_query['post_status'] = $r['perm']; 
  289.  
  290. // Get all stickies 
  291. $sticky_posts = get_posts( $sticky_query ); 
  292. if ( !empty( $sticky_posts ) ) { 
  293.  
  294. // Get a count of the visible stickies 
  295. $sticky_count = count( $sticky_posts ); 
  296.  
  297. // Merge the stickies topics with the query topics . 
  298. $bbp->topic_query->posts = array_merge( $sticky_posts, $bbp->topic_query->posts ); 
  299.  
  300. // Adjust loop and counts for new sticky positions 
  301. $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count; 
  302. $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count; 
  303.  
  304. // Cleanup 
  305. unset( $sticky_posts ); 
  306.  
  307. // If no limit to posts per page, set it to the current post_count 
  308. if ( -1 === $r['posts_per_page'] ) 
  309. $r['posts_per_page'] = $bbp->topic_query->post_count; 
  310.  
  311. // Add pagination values to query object 
  312. $bbp->topic_query->posts_per_page = $r['posts_per_page']; 
  313. $bbp->topic_query->paged = $r['paged']; 
  314.  
  315. // Only add pagination if query returned results 
  316. if ( ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page ) { 
  317.  
  318. // Limit the number of topics shown based on maximum allowed pages 
  319. if ( ( !empty( $r['max_num_pages'] ) ) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count ) 
  320. $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count; 
  321.  
  322. // If pretty permalinks are enabled, make our pagination pretty 
  323. if ( $wp_rewrite->using_permalinks() ) { 
  324.  
  325. // User's topics 
  326. if ( bbp_is_single_user_topics() ) { 
  327. $base = bbp_get_user_topics_created_url( bbp_get_displayed_user_id() ); 
  328.  
  329. // User's favorites 
  330. } elseif ( bbp_is_favorites() ) { 
  331. $base = bbp_get_favorites_permalink( bbp_get_displayed_user_id() ); 
  332.  
  333. // User's subscriptions 
  334. } elseif ( bbp_is_subscriptions() ) { 
  335. $base = bbp_get_subscriptions_permalink( bbp_get_displayed_user_id() ); 
  336.  
  337. // Root profile page 
  338. } elseif ( bbp_is_single_user() ) { 
  339. $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() ); 
  340.  
  341. // View 
  342. } elseif ( bbp_is_single_view() ) { 
  343. $base = bbp_get_view_url(); 
  344.  
  345. // Topic tag 
  346. } elseif ( bbp_is_topic_tag() ) { 
  347. $base = bbp_get_topic_tag_link(); 
  348.  
  349. // Page or single post 
  350. } elseif ( is_page() || is_single() ) { 
  351. $base = get_permalink(); 
  352.  
  353. // Forum archive 
  354. } elseif ( bbp_is_forum_archive() ) { 
  355. $base = bbp_get_forums_url(); 
  356.  
  357. // Topic archive 
  358. } elseif ( bbp_is_topic_archive() ) { 
  359. $base = bbp_get_topics_url(); 
  360.  
  361. // Default 
  362. } else { 
  363. $base = get_permalink( (int) $r['post_parent'] ); 
  364.  
  365. // Use pagination base 
  366. $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); 
  367.  
  368. // Unpretty pagination 
  369. } else { 
  370. $base = add_query_arg( 'paged', '%#%' ); 
  371.  
  372. // Pagination settings with filter 
  373. $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array ( 
  374. 'base' => $base,  
  375. 'format' => '',  
  376. 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil( (int) $bbp->topic_query->found_posts / (int) $r['posts_per_page'] ),  
  377. 'current' => (int) $bbp->topic_query->paged,  
  378. 'prev_text' => is_rtl() ? '→' : '←',  
  379. 'next_text' => is_rtl() ? '←' : '→',  
  380. 'mid_size' => 1 
  381. ) ); 
  382.  
  383. // Add pagination to query object 
  384. $bbp->topic_query->pagination_links = paginate_links( $bbp_topic_pagination ); 
  385.  
  386. // Remove first page from pagination 
  387. $bbp->topic_query->pagination_links = str_replace( $wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links ); 
  388.  
  389. // Return object 
  390. return apply_filters( 'bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query ); 
  391.  
  392. /** 
  393. * Whether there are more topics available in the loop 
  394. * 
  395. * @since bbPress (r2485) 
  396. * 
  397. * @uses WP_Query bbPress::topic_query::have_posts() 
  398. * @return object Topic information 
  399. */ 
  400. function bbp_topics() { 
  401.  
  402. // Put into variable to check against next 
  403. $have_posts = bbpress()->topic_query->have_posts(); 
  404.  
  405. // Reset the post data when finished 
  406. if ( empty( $have_posts ) ) 
  407. wp_reset_postdata(); 
  408.  
  409. return $have_posts; 
  410.  
  411. /** 
  412. * Loads up the current topic in the loop 
  413. * 
  414. * @since bbPress (r2485) 
  415. * 
  416. * @uses WP_Query bbPress::topic_query::the_post() 
  417. * @return object Topic information 
  418. */ 
  419. function bbp_the_topic() { 
  420. return bbpress()->topic_query->the_post(); 
  421.  
  422. /** 
  423. * Output the topic id 
  424. * 
  425. * @since bbPress (r2485) 
  426. * 
  427. * @uses bbp_get_topic_id() To get the topic id 
  428. */ 
  429. function bbp_topic_id( $topic_id = 0) { 
  430. echo bbp_get_topic_id( $topic_id ); 
  431. /** 
  432. * Return the topic id 
  433. * 
  434. * @since bbPress (r2485) 
  435. * 
  436. * @param $topic_id Optional. Used to check emptiness 
  437. * @uses bbPress::topic_query::post::ID To get the topic id 
  438. * @uses bbp_is_topic() To check if the search result is a topic 
  439. * @uses bbp_is_single_topic() To check if it's a topic page 
  440. * @uses bbp_is_topic_edit() To check if it's a topic edit page 
  441. * @uses bbp_is_single_reply() To check if it it's a reply page 
  442. * @uses bbp_is_reply_edit() To check if it's a reply edit page 
  443. * @uses bbp_get_reply_topic_edit() To get the reply topic id 
  444. * @uses get_post_field() To get the post's post type 
  445. * @uses WP_Query::post::ID To get the topic id 
  446. * @uses bbp_get_topic_post_type() To get the topic post type 
  447. * @uses apply_filters() Calls 'bbp_get_topic_id' with the topic id and 
  448. * supplied topic id 
  449. * @return int The topic id 
  450. */ 
  451. function bbp_get_topic_id( $topic_id = 0 ) { 
  452. global $wp_query; 
  453.  
  454. $bbp = bbpress(); 
  455.  
  456. // Easy empty checking 
  457. if ( !empty( $topic_id ) && is_numeric( $topic_id ) ) { 
  458. $bbp_topic_id = $topic_id; 
  459.  
  460. // Currently inside a topic loop 
  461. } elseif ( !empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) ) { 
  462. $bbp_topic_id = $bbp->topic_query->post->ID; 
  463.  
  464. // Currently inside a search loop 
  465. } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) { 
  466. $bbp_topic_id = $bbp->search_query->post->ID; 
  467.  
  468. // Currently viewing/editing a topic, likely alone 
  469. } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && !empty( $bbp->current_topic_id ) ) { 
  470. $bbp_topic_id = $bbp->current_topic_id; 
  471.  
  472. // Currently viewing/editing a topic, likely in a loop 
  473. } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) { 
  474. $bbp_topic_id = $wp_query->post->ID; 
  475.  
  476. // Currently viewing/editing a reply 
  477. } elseif ( bbp_is_single_reply() || bbp_is_reply_edit() ) { 
  478. $bbp_topic_id = bbp_get_reply_topic_id(); 
  479.  
  480. // Fallback 
  481. } else { 
  482. $bbp_topic_id = 0; 
  483.  
  484. return (int) apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id ); 
  485.  
  486. /** 
  487. * Gets a topic 
  488. * 
  489. * @since bbPress (r2787) 
  490. * 
  491. * @param int|object $topic Topic id or topic object 
  492. * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT 
  493. * @param string $filter Optional Sanitation filter. See {@link sanitize_post()} 
  494. * @uses get_post() To get the topic 
  495. * @uses apply_filters() Calls 'bbp_get_topic' with the topic, output type and 
  496. * sanitation filter 
  497. * @return mixed Null if error or topic (in specified form) if success 
  498. */ 
  499. function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) { 
  500.  
  501. // Use topic ID 
  502. if ( empty( $topic ) || is_numeric( $topic ) ) 
  503. $topic = bbp_get_topic_id( $topic ); 
  504.  
  505. // Attempt to load the topic 
  506. $topic = get_post( $topic, OBJECT, $filter ); 
  507. if ( empty( $topic ) ) 
  508. return $topic; 
  509.  
  510. // Bail if post_type is not a topic 
  511. if ( $topic->post_type !== bbp_get_topic_post_type() ) 
  512. return null; 
  513.  
  514. // Tweak the data type to return 
  515. if ( $output === OBJECT ) { 
  516. return $topic; 
  517.  
  518. } elseif ( $output === ARRAY_A ) { 
  519. $_topic = get_object_vars( $topic ); 
  520. return $_topic; 
  521.  
  522. } elseif ( $output === ARRAY_N ) { 
  523. $_topic = array_values( get_object_vars( $topic ) ); 
  524. return $_topic; 
  525.  
  526.  
  527. return apply_filters( 'bbp_get_topic', $topic, $output, $filter ); 
  528.  
  529. /** 
  530. * Output the link to the topic in the topic loop 
  531. * 
  532. * @since bbPress (r2485) 
  533. * 
  534. * @param int $topic_id Optional. Topic id 
  535. * @param $string $redirect_to Optional. Pass a redirect value for use with 
  536. * shortcodes and other fun things. 
  537. * @uses bbp_get_topic_permalink() To get the topic permalink 
  538. */ 
  539. function bbp_topic_permalink( $topic_id = 0, $redirect_to = '' ) { 
  540. echo esc_url( bbp_get_topic_permalink( $topic_id, $redirect_to ) ); 
  541. /** 
  542. * Return the link to the topic 
  543. * 
  544. * @since bbPress (r2485) 
  545. * 
  546. * @param int $topic_id Optional. Topic id 
  547. * @param $string $redirect_to Optional. Pass a redirect value for use with 
  548. * shortcodes and other fun things. 
  549. * @uses bbp_get_topic_id() To get the topic id 
  550. * @uses get_permalink() To get the topic permalink 
  551. * @uses esc_url_raw() To clean the redirect_to url 
  552. * @uses apply_filters() Calls 'bbp_get_topic_permalink' with the link 
  553. * and topic id 
  554. * @return string Permanent link to topic 
  555. */ 
  556. function bbp_get_topic_permalink( $topic_id = 0, $redirect_to = '' ) { 
  557. $topic_id = bbp_get_topic_id( $topic_id ); 
  558.  
  559. // Use the redirect address 
  560. if ( !empty( $redirect_to ) ) { 
  561. $topic_permalink = esc_url_raw( $redirect_to ); 
  562.  
  563. // Use the topic permalink 
  564. } else { 
  565. $topic_permalink = get_permalink( $topic_id ); 
  566.  
  567. return apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $topic_id ); 
  568.  
  569. /** 
  570. * Output the title of the topic 
  571. * 
  572. * @since bbPress (r2485) 
  573. * 
  574. * @param int $topic_id Optional. Topic id 
  575. * @uses bbp_get_topic_title() To get the topic title 
  576. */ 
  577. function bbp_topic_title( $topic_id = 0 ) { 
  578. echo bbp_get_topic_title( $topic_id ); 
  579. /** 
  580. * Return the title of the topic 
  581. * 
  582. * @since bbPress (r2485) 
  583. * 
  584. * @param int $topic_id Optional. Topic id 
  585. * @uses bbp_get_topic_id() To get the topic id 
  586. * @uses get_the_title() To get the title 
  587. * @uses apply_filters() Calls 'bbp_get_topic_title' with the title and 
  588. * topic id 
  589. * @return string Title of topic 
  590. */ 
  591. function bbp_get_topic_title( $topic_id = 0 ) { 
  592. $topic_id = bbp_get_topic_id( $topic_id ); 
  593. $title = get_the_title( $topic_id ); 
  594.  
  595. return apply_filters( 'bbp_get_topic_title', $title, $topic_id ); 
  596.  
  597. /** 
  598. * Output the topic archive title 
  599. * 
  600. * @since bbPress (r3249) 
  601. * 
  602. * @param string $title Default text to use as title 
  603. */ 
  604. function bbp_topic_archive_title( $title = '' ) { 
  605. echo bbp_get_topic_archive_title( $title ); 
  606. /** 
  607. * Return the topic archive title 
  608. * 
  609. * @since bbPress (r3249) 
  610. * 
  611. * @param string $title Default text to use as title 
  612. * 
  613. * @uses bbp_get_page_by_path() Check if page exists at root path 
  614. * @uses get_the_title() Use the page title at the root path 
  615. * @uses get_post_type_object() Load the post type object 
  616. * @uses bbp_get_topic_post_type() Get the topic post type ID 
  617. * @uses get_post_type_labels() Get labels for topic post type 
  618. * @uses apply_filters() Allow output to be manipulated 
  619. * 
  620. * @return string The topic archive title 
  621. */ 
  622. function bbp_get_topic_archive_title( $title = '' ) { 
  623.  
  624. // If no title was passed 
  625. if ( empty( $title ) ) { 
  626.  
  627. // Set root text to page title 
  628. $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() ); 
  629. if ( !empty( $page ) ) { 
  630. $title = get_the_title( $page->ID ); 
  631.  
  632. // Default to topic post type name label 
  633. } else { 
  634. $tto = get_post_type_object( bbp_get_topic_post_type() ); 
  635. $title = $tto->labels->name; 
  636.  
  637. return apply_filters( 'bbp_get_topic_archive_title', $title ); 
  638.  
  639. /** 
  640. * Output the content of the topic 
  641. * 
  642. * @since bbPress (r2780) 
  643. * 
  644. * @param int $topic_id Optional. Topic id 
  645. * @uses bbp_get_topic_content() To get the topic content 
  646. */ 
  647. function bbp_topic_content( $topic_id = 0 ) { 
  648. echo bbp_get_topic_content( $topic_id ); 
  649. /** 
  650. * Return the content of the topic 
  651. * 
  652. * @since bbPress (r2780) 
  653. * 
  654. * @param int $topic_id Optional. Topic id 
  655. * @uses bbp_get_topic_id() To get the topic id 
  656. * @uses post_password_required() To check if the topic requires pass 
  657. * @uses get_the_password_form() To get the password form 
  658. * @uses get_post_field() To get the content post field 
  659. * @uses apply_filters() Calls 'bbp_get_topic_content' with the content 
  660. * and topic id 
  661. * @return string Content of the topic 
  662. */ 
  663. function bbp_get_topic_content( $topic_id = 0 ) { 
  664. $topic_id = bbp_get_topic_id( $topic_id ); 
  665.  
  666. // Check if password is required 
  667. if ( post_password_required( $topic_id ) ) 
  668. return get_the_password_form(); 
  669.  
  670. $content = get_post_field( 'post_content', $topic_id ); 
  671.  
  672. return apply_filters( 'bbp_get_topic_content', $content, $topic_id ); 
  673.  
  674. /** 
  675. * Output the excerpt of the topic 
  676. * 
  677. * @since bbPress (r2780) 
  678. * 
  679. * @param int $topic_id Optional. Topic id 
  680. * @param int $length Optional. Length of the excerpt. Defaults to 100 letters 
  681. * @uses bbp_get_topic_excerpt() To get the topic excerpt 
  682. */ 
  683. function bbp_topic_excerpt( $topic_id = 0, $length = 100 ) { 
  684. echo bbp_get_topic_excerpt( $topic_id, $length ); 
  685. /** 
  686. * Return the excerpt of the topic 
  687. * 
  688. * @since bbPress (r2780) 
  689. * 
  690. * @param int $topic_id Optional. topic id 
  691. * @param int $length Optional. Length of the excerpt. Defaults to 100 
  692. * letters 
  693. * @uses bbp_get_topic_id() To get the topic id 
  694. * @uses get_post_field() To get the excerpt 
  695. * @uses bbp_get_topic_content() To get the topic content 
  696. * @uses apply_filters() Calls 'bbp_get_topic_excerpt' with the excerpt,  
  697. * topic id and length 
  698. * @return string topic Excerpt 
  699. */ 
  700. function bbp_get_topic_excerpt( $topic_id = 0, $length = 100 ) { 
  701. $topic_id = bbp_get_topic_id( $topic_id ); 
  702. $length = (int) $length; 
  703. $excerpt = get_post_field( 'post_excerpt', $topic_id ); 
  704.  
  705. if ( empty( $excerpt ) ) { 
  706. $excerpt = bbp_get_topic_content( $topic_id ); 
  707.  
  708. $excerpt = trim( strip_tags( $excerpt ) ); 
  709.  
  710. // Multibyte support 
  711. if ( function_exists( 'mb_strlen' ) ) { 
  712. $excerpt_length = mb_strlen( $excerpt ); 
  713. } else { 
  714. $excerpt_length = strlen( $excerpt ); 
  715.  
  716. if ( !empty( $length ) && ( $excerpt_length > $length ) ) { 
  717. $excerpt = substr( $excerpt, 0, $length - 1 ); 
  718. $excerpt .= '…'; 
  719.  
  720. return apply_filters( 'bbp_get_topic_excerpt', $excerpt, $topic_id, $length ); 
  721.  
  722. /** 
  723. * Output the post date and time of a topic 
  724. * 
  725. * @since bbPress (r4155) 
  726. * 
  727. * @param int $topic_id Optional. Topic id. 
  728. * @param bool $humanize Optional. Humanize output using time_since 
  729. * @param bool $gmt Optional. Use GMT 
  730. * @uses bbp_get_topic_post_date() to get the output 
  731. */ 
  732. function bbp_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) { 
  733. echo bbp_get_topic_post_date( $topic_id, $humanize, $gmt ); 
  734. /** 
  735. * Return the post date and time of a topic 
  736. * 
  737. * @since bbPress (r4155) 
  738. * 
  739. * @param int $topic_id Optional. Topic id. 
  740. * @param bool $humanize Optional. Humanize output using time_since 
  741. * @param bool $gmt Optional. Use GMT 
  742. * @uses bbp_get_topic_id() To get the topic id 
  743. * @uses get_post_time() to get the topic post time 
  744. * @uses bbp_get_time_since() to maybe humanize the topic post time 
  745. * @return string 
  746. */ 
  747. function bbp_get_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) { 
  748. $topic_id = bbp_get_topic_id( $topic_id ); 
  749.  
  750. // 4 days, 4 hours ago 
  751. if ( !empty( $humanize ) ) { 
  752. $gmt_s = !empty( $gmt ) ? 'U' : 'G'; 
  753. $date = get_post_time( $gmt_s, $gmt, $topic_id ); 
  754. $time = false; // For filter below 
  755. $result = bbp_get_time_since( $date ); 
  756.  
  757. // August 4, 2012 at 2:37 pm 
  758. } else { 
  759. $date = get_post_time( get_option( 'date_format' ), $gmt, $topic_id, true ); 
  760. $time = get_post_time( get_option( 'time_format' ), $gmt, $topic_id, true ); 
  761. $result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time ); 
  762.  
  763. return apply_filters( 'bbp_get_topic_post_date', $result, $topic_id, $humanize, $gmt, $date, $time ); 
  764.  
  765. /** 
  766. * Output pagination links of a topic within the topic loop 
  767. * 
  768. * @since bbPress (r2966) 
  769. * 
  770. * @param mixed $args See {@link bbp_get_topic_pagination()} 
  771. * @uses bbp_get_topic_pagination() To get the topic pagination links 
  772. */ 
  773. function bbp_topic_pagination( $args = '' ) { 
  774. echo bbp_get_topic_pagination( $args ); 
  775. /** 
  776. * Returns pagination links of a topic within the topic loop 
  777. * 
  778. * @since bbPress (r2966) 
  779. * 
  780. * @param mixed $args This function supports these arguments: 
  781. * - topic_id: Topic id 
  782. * - before: Before the links 
  783. * - after: After the links 
  784. * @uses bbp_get_topic_id() To get the topic id 
  785. * @uses WP_Rewrite::using_permalinks() To check if the blog is using 
  786. * permalinks 
  787. * @uses user_trailingslashit() To add a trailing slash 
  788. * @uses trailingslashit() To add a trailing slash 
  789. * @uses get_permalink() To get the permalink of the topic 
  790. * @uses add_query_arg() To add query args 
  791. * @uses bbp_get_topic_reply_count() To get topic reply count 
  792. * @uses bbp_show_topic_lead() Are we showing the topic as a lead? 
  793. * @uses get_option() To get replies per page option 
  794. * @uses paginate_links() To paginate the links 
  795. * @uses apply_filters() Calls 'bbp_get_topic_pagination' with the links 
  796. * and arguments 
  797. * @return string Pagination links 
  798. */ 
  799. function bbp_get_topic_pagination( $args = '' ) { 
  800. global $wp_rewrite; 
  801.  
  802. // Bail if threading replies 
  803. if ( bbp_thread_replies() ) { 
  804. return; 
  805.  
  806. // Parse arguments against default values 
  807. $r = bbp_parse_args( $args, array( 
  808. 'topic_id' => bbp_get_topic_id(),  
  809. 'before' => '<span class="bbp-topic-pagination">',  
  810. 'after' => '</span>',  
  811. ), 'get_topic_pagination' ); 
  812.  
  813. // If pretty permalinks are enabled, make our pagination pretty 
  814. if ( $wp_rewrite->using_permalinks() ) { 
  815. $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); 
  816. } else { 
  817. $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) ); 
  818.  
  819. // Get total and add 1 if topic is included in the reply loop 
  820. $total = bbp_get_topic_reply_count( $r['topic_id'], true ); 
  821.  
  822. // Bump if topic is in loop 
  823. if ( !bbp_show_lead_topic() ) 
  824. $total++; 
  825.  
  826. // Pagination settings 
  827. $pagination = array( 
  828. 'base' => $base,  
  829. 'format' => '',  
  830. 'total' => ceil( (int) $total / (int) bbp_get_replies_per_page() ),  
  831. 'current' => 0,  
  832. 'prev_next' => false,  
  833. 'mid_size' => 2,  
  834. 'end_size' => 3,  
  835. 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 
  836. ); 
  837.  
  838. // Add pagination to query object 
  839. $pagination_links = paginate_links( $pagination ); 
  840. if ( !empty( $pagination_links ) ) { 
  841.  
  842. // Remove first page from pagination 
  843. if ( $wp_rewrite->using_permalinks() ) { 
  844. $pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $pagination_links ); 
  845. } else { 
  846. $pagination_links = str_replace( '&paged=1', '', $pagination_links ); 
  847.  
  848. // Add before and after to pagination links 
  849. $pagination_links = $r['before'] . $pagination_links . $r['after']; 
  850.  
  851. return apply_filters( 'bbp_get_topic_pagination', $pagination_links, $args ); 
  852.  
  853. /** 
  854. * Append revisions to the topic content 
  855. * 
  856. * @since bbPress (r2782) 
  857. * 
  858. * @param string $content Optional. Content to which we need to append the revisions to 
  859. * @param int $topic_id Optional. Topic id 
  860. * @uses bbp_get_topic_revision_log() To get the topic revision log 
  861. * @uses apply_filters() Calls 'bbp_topic_append_revisions' with the processed 
  862. * content, original content and topic id 
  863. * @return string Content with the revisions appended 
  864. */ 
  865. function bbp_topic_content_append_revisions( $content = '', $topic_id = 0 ) { 
  866.  
  867. // Bail if in admin or feed 
  868. if ( is_admin() || is_feed() ) 
  869. return; 
  870.  
  871. // Validate the ID 
  872. $topic_id = bbp_get_topic_id( $topic_id ); 
  873.  
  874. return apply_filters( 'bbp_topic_append_revisions', $content . bbp_get_topic_revision_log( $topic_id ), $content, $topic_id ); 
  875.  
  876. /** 
  877. * Output the revision log of the topic 
  878. * 
  879. * @since bbPress (r2782) 
  880. * 
  881. * @param int $topic_id Optional. Topic id 
  882. * @uses bbp_get_topic_revision_log() To get the topic revision log 
  883. */ 
  884. function bbp_topic_revision_log( $topic_id = 0 ) { 
  885. echo bbp_get_topic_revision_log( $topic_id ); 
  886. /** 
  887. * Return the formatted revision log of the topic 
  888. * 
  889. * @since bbPress (r2782) 
  890. * 
  891. * @param int $topic_id Optional. Topic id 
  892. * @uses bbp_get_topic_id() To get the topic id 
  893. * @uses bbp_get_topic_revisions() To get the topic revisions 
  894. * @uses bbp_get_topic_raw_revision_log() To get the raw revision log 
  895. * @uses bbp_get_topic_author_display_name() To get the topic author 
  896. * @uses bbp_get_author_link() To get the topic author link 
  897. * @uses bbp_convert_date() To convert the date 
  898. * @uses bbp_get_time_since() To get the time in since format 
  899. * @uses apply_filters() Calls 'bbp_get_topic_revision_log' with the 
  900. * log and topic id 
  901. * @return string Revision log of the topic 
  902. */ 
  903. function bbp_get_topic_revision_log( $topic_id = 0 ) { 
  904. // Create necessary variables 
  905. $topic_id = bbp_get_topic_id( $topic_id ); 
  906. $revision_log = bbp_get_topic_raw_revision_log( $topic_id ); 
  907.  
  908. if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) ) 
  909. return false; 
  910.  
  911. $revisions = bbp_get_topic_revisions( $topic_id ); 
  912. if ( empty( $revisions ) ) 
  913. return false; 
  914.  
  915. $r = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '" class="bbp-topic-revision-log">' . "\n\n"; 
  916.  
  917. // Loop through revisions 
  918. foreach ( (array) $revisions as $revision ) { 
  919.  
  920. if ( empty( $revision_log[$revision->ID] ) ) { 
  921. $author_id = $revision->post_author; 
  922. $reason = ''; 
  923. } else { 
  924. $author_id = $revision_log[$revision->ID]['author']; 
  925. $reason = $revision_log[$revision->ID]['reason']; 
  926.  
  927. $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_topic_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); 
  928. $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); 
  929.  
  930. $r .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-topic-revision-log-item">' . "\n"; 
  931. if ( !empty( $reason ) ) { 
  932. $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; 
  933. } else { 
  934. $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; 
  935. $r .= "\t" . '</li>' . "\n"; 
  936.  
  937.  
  938. $r .= "\n" . '</ul>' . "\n\n"; 
  939.  
  940. return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id ); 
  941. /** 
  942. * Return the raw revision log of the topic 
  943. * 
  944. * @since bbPress (r2782) 
  945. * 
  946. * @param int $topic_id Optional. Topic id 
  947. * @uses bbp_get_topic_id() To get the topic id 
  948. * @uses get_post_meta() To get the revision log meta 
  949. * @uses apply_filters() Calls 'bbp_get_topic_raw_revision_log' 
  950. * with the log and topic id 
  951. * @return string Raw revision log of the topic 
  952. */ 
  953. function bbp_get_topic_raw_revision_log( $topic_id = 0 ) { 
  954. $topic_id = bbp_get_topic_id( $topic_id ); 
  955.  
  956. $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true ); 
  957. $revision_log = empty( $revision_log ) ? array() : $revision_log; 
  958.  
  959. return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id ); 
  960.  
  961. /** 
  962. * Return the revisions of the topic 
  963. * 
  964. * @since bbPress (r2782) 
  965. * 
  966. * @param int $topic_id Optional. Topic id 
  967. * @uses bbp_get_topic_id() To get the topic id 
  968. * @uses wp_get_post_revisions() To get the topic revisions 
  969. * @uses apply_filters() Calls 'bbp_get_topic_revisions' 
  970. * with the revisions and topic id 
  971. * @return string Topic revisions 
  972. */ 
  973. function bbp_get_topic_revisions( $topic_id = 0 ) { 
  974. $topic_id = bbp_get_topic_id( $topic_id ); 
  975. $revisions = wp_get_post_revisions( $topic_id, array( 'order' => 'ASC' ) ); 
  976.  
  977. return apply_filters( 'bbp_get_topic_revisions', $revisions, $topic_id ); 
  978.  
  979. /** 
  980. * Return the revision count of the topic 
  981. * 
  982. * @since bbPress (r2782) 
  983. * 
  984. * @param int $topic_id Optional. Topic id 
  985. * @uses bbp_get_topic_revisions() To get the topic revisions 
  986. * @uses apply_filters() Calls 'bbp_get_topic_revision_count' 
  987. * with the revision count and topic id 
  988. * @return string Topic revision count 
  989. */ 
  990. function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) { 
  991. $count = (int) count( bbp_get_topic_revisions( $topic_id ) ); 
  992. $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count'; 
  993.  
  994. return apply_filters( $filter, $count, $topic_id ); 
  995.  
  996. /** 
  997. * Output the status of the topic 
  998. * 
  999. * @since bbPress (r2667) 
  1000. * 
  1001. * @param int $topic_id Optional. Topic id 
  1002. * @uses bbp_get_topic_status() To get the topic status 
  1003. */ 
  1004. function bbp_topic_status( $topic_id = 0 ) { 
  1005. echo bbp_get_topic_status( $topic_id ); 
  1006. /** 
  1007. * Return the status of the topic 
  1008. * 
  1009. * @since bbPress (r2667) 
  1010. * 
  1011. * @param int $topic_id Optional. Topic id 
  1012. * @uses bbp_get_topic_id() To get the topic id 
  1013. * @uses get_post_status() To get the topic status 
  1014. * @uses apply_filters() Calls 'bbp_get_topic_status' with the status 
  1015. * and topic id 
  1016. * @return string Status of topic 
  1017. */ 
  1018. function bbp_get_topic_status( $topic_id = 0 ) { 
  1019. $topic_id = bbp_get_topic_id( $topic_id ); 
  1020.  
  1021. return apply_filters( 'bbp_get_topic_status', get_post_status( $topic_id ), $topic_id ); 
  1022.  
  1023. /** 
  1024. * Is the topic open to new replies? 
  1025. * 
  1026. * @since bbPress (r2727) 
  1027. * 
  1028. * @uses bbp_get_topic_status() 
  1029. * 
  1030. * @param int $topic_id Optional. Topic id 
  1031. * @uses bbp_is_topic_closed() To check if the topic is closed 
  1032. * @return bool True if open, false if closed. 
  1033. */ 
  1034. function bbp_is_topic_open( $topic_id = 0 ) { 
  1035. return !bbp_is_topic_closed( $topic_id ); 
  1036.  
  1037. /** 
  1038. * Is the topic closed to new replies? 
  1039. * 
  1040. * @since bbPress (r2746) 
  1041. * 
  1042. * @param int $topic_id Optional. Topic id 
  1043. * @uses bbp_get_topic_status() To get the topic status 
  1044. * @uses apply_filters() Calls 'bbp_is_topic_closed' with the topic id 
  1045. * 
  1046. * @return bool True if closed, false if not. 
  1047. */ 
  1048. function bbp_is_topic_closed( $topic_id = 0 ) { 
  1049. $closed = bbp_get_topic_status( $topic_id ) === bbp_get_closed_status_id(); 
  1050. return (bool) apply_filters( 'bbp_is_topic_closed', (bool) $closed, $topic_id ); 
  1051.  
  1052. /** 
  1053. * Is the topic a sticky or super sticky? 
  1054. * 
  1055. * @since bbPress (r2754) 
  1056. * 
  1057. * @param int $topic_id Optional. Topic id 
  1058. * @param int $check_super Optional. If set to true and if the topic is not a 
  1059. * normal sticky, it is checked if it is a super 
  1060. * sticky or not. Defaults to true. 
  1061. * @uses bbp_get_topic_id() To get the topic id 
  1062. * @uses bbp_get_topic_forum_id() To get the topic forum id 
  1063. * @uses bbp_get_stickies() To get the stickies 
  1064. * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky 
  1065. * @return bool True if sticky or super sticky, false if not. 
  1066. */ 
  1067. function bbp_is_topic_sticky( $topic_id = 0, $check_super = true ) { 
  1068. $topic_id = bbp_get_topic_id( $topic_id ); 
  1069. $forum_id = bbp_get_topic_forum_id( $topic_id ); 
  1070. $stickies = bbp_get_stickies( $forum_id ); 
  1071.  
  1072. if ( in_array( $topic_id, $stickies ) || ( !empty( $check_super ) && bbp_is_topic_super_sticky( $topic_id ) ) ) 
  1073. return true; 
  1074.  
  1075. return false; 
  1076.  
  1077. /** 
  1078. * Is the topic a super sticky? 
  1079. * 
  1080. * @since bbPress (r2754) 
  1081. * 
  1082. * @param int $topic_id Optional. Topic id 
  1083. * @uses bbp_get_topic_id() To get the topic id 
  1084. * @uses bbp_get_super_stickies() To get the super stickies 
  1085. * @return bool True if super sticky, false if not. 
  1086. */ 
  1087. function bbp_is_topic_super_sticky( $topic_id = 0 ) { 
  1088. $topic_id = bbp_get_topic_id( $topic_id ); 
  1089. $stickies = bbp_get_super_stickies( $topic_id ); 
  1090.  
  1091. return in_array( $topic_id, $stickies ); 
  1092.  
  1093. /** 
  1094. * Is the topic not spam or deleted? 
  1095. * 
  1096. * @since bbPress (r3496) 
  1097. * 
  1098. * @param int $topic_id Optional. Topic id 
  1099. * @uses bbp_get_topic_id() To get the topic id 
  1100. * @uses bbp_get_topic_status() To get the topic status 
  1101. * @uses apply_filters() Calls 'bbp_is_topic_published' with the topic id 
  1102. * @return bool True if published, false if not. 
  1103. */ 
  1104. function bbp_is_topic_published( $topic_id = 0 ) { 
  1105. $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_public_status_id(); 
  1106. return (bool) apply_filters( 'bbp_is_topic_published', (bool) $topic_status, $topic_id ); 
  1107.  
  1108. /** 
  1109. * Is the topic marked as spam? 
  1110. * 
  1111. * @since bbPress (r2727) 
  1112. * 
  1113. * @param int $topic_id Optional. Topic id 
  1114. * @uses bbp_get_topic_id() To get the topic id 
  1115. * @uses bbp_get_topic_status() To get the topic status 
  1116. * @uses apply_filters() Calls 'bbp_is_topic_spam' with the topic id 
  1117. * @return bool True if spam, false if not. 
  1118. */ 
  1119. function bbp_is_topic_spam( $topic_id = 0 ) { 
  1120. $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_spam_status_id(); 
  1121. return (bool) apply_filters( 'bbp_is_topic_spam', (bool) $topic_status, $topic_id ); 
  1122.  
  1123. /** 
  1124. * Is the topic trashed? 
  1125. * 
  1126. * @since bbPress (r2888) 
  1127. * 
  1128. * @param int $topic_id Optional. Topic id 
  1129. * @uses bbp_get_topic_id() To get the topic id 
  1130. * @uses bbp_get_topic_status() To get the topic status 
  1131. * @uses apply_filters() Calls 'bbp_is_topic_trash' with the topic id 
  1132. * @return bool True if trashed, false if not. 
  1133. */ 
  1134. function bbp_is_topic_trash( $topic_id = 0 ) { 
  1135. $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_trash_status_id(); 
  1136. return (bool) apply_filters( 'bbp_is_topic_trash', (bool) $topic_status, $topic_id ); 
  1137.  
  1138. /** 
  1139. * Is the posted by an anonymous user? 
  1140. * 
  1141. * @since bbPress (r2753) 
  1142. * 
  1143. * @param int $topic_id Optional. Topic id 
  1144. * @uses bbp_get_topic_id() To get the topic id 
  1145. * @uses bbp_get_topic_author_id() To get the topic author id 
  1146. * @uses get_post_meta() To get the anonymous user name and email meta 
  1147. * @uses apply_filters() Calls 'bbp_is_topic_anonymous' with the topic id 
  1148. * @return bool True if the post is by an anonymous user, false if not. 
  1149. */ 
  1150. function bbp_is_topic_anonymous( $topic_id = 0 ) { 
  1151. $topic_id = bbp_get_topic_id( $topic_id ); 
  1152. $retval = false; 
  1153.  
  1154. if ( !bbp_get_topic_author_id( $topic_id ) ) 
  1155. $retval = true; 
  1156.  
  1157. elseif ( get_post_meta( $topic_id, '_bbp_anonymous_name', true ) ) 
  1158. $retval = true; 
  1159.  
  1160. elseif ( get_post_meta( $topic_id, '_bbp_anonymous_email', true ) ) 
  1161. $retval = true; 
  1162.  
  1163. // The topic is by an anonymous user 
  1164. return (bool) apply_filters( 'bbp_is_topic_anonymous', $retval, $topic_id ); 
  1165.  
  1166. /** 
  1167. * Deprecated. Use bbp_topic_author_display_name() instead. 
  1168. * 
  1169. * Output the author of the topic. 
  1170. * 
  1171. * @since bbPress (r2590) 
  1172. * @deprecated bbPress (r5119) 
  1173. * 
  1174. * @param int $topic_id Optional. Topic id 
  1175. * @uses bbp_get_topic_author() To get the topic author 
  1176. */ 
  1177. function bbp_topic_author( $topic_id = 0 ) { 
  1178. echo bbp_get_topic_author( $topic_id ); 
  1179. /** 
  1180. * Deprecated. Use bbp_get_topic_author_display_name() instead. 
  1181. * 
  1182. * Return the author of the topic 
  1183. * 
  1184. * @since bbPress (r2590) 
  1185. * @deprecated bbPress (r5119) 
  1186. * 
  1187. * @param int $topic_id Optional. Topic id 
  1188. * @uses bbp_get_topic_id() To get the topic id 
  1189. * @uses bbp_is_topic_anonymous() To check if the topic is by an 
  1190. * anonymous user 
  1191. * @uses bbp_get_topic_author_id() To get the topic author id 
  1192. * @uses get_the_author_meta() To get the display name of the author 
  1193. * @uses get_post_meta() To get the name of the anonymous poster 
  1194. * @uses apply_filters() Calls 'bbp_get_topic_author' with the author 
  1195. * and topic id 
  1196. * @return string Author of topic 
  1197. */ 
  1198. function bbp_get_topic_author( $topic_id = 0 ) { 
  1199. $topic_id = bbp_get_topic_id( $topic_id ); 
  1200.  
  1201. if ( !bbp_is_topic_anonymous( $topic_id ) ) { 
  1202. $author = get_the_author_meta( 'display_name', bbp_get_topic_author_id( $topic_id ) ); 
  1203. } else { 
  1204. $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true ); 
  1205.  
  1206. return apply_filters( 'bbp_get_topic_author', $author, $topic_id ); 
  1207.  
  1208. /** 
  1209. * Output the author ID of the topic 
  1210. * 
  1211. * @since bbPress (r2590) 
  1212. * 
  1213. * @param int $topic_id Optional. Topic id 
  1214. * @uses bbp_get_topic_author_id() To get the topic author id 
  1215. */ 
  1216. function bbp_topic_author_id( $topic_id = 0 ) { 
  1217. echo bbp_get_topic_author_id( $topic_id ); 
  1218. /** 
  1219. * Return the author ID of the topic 
  1220. * 
  1221. * @since bbPress (r2590) 
  1222. * 
  1223. * @param int $topic_id Optional. Topic id 
  1224. * @uses bbp_get_topic_id() To get the topic id 
  1225. * @uses get_post_field() To get the topic author id 
  1226. * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the author 
  1227. * id and topic id 
  1228. * @return string Author of topic 
  1229. */ 
  1230. function bbp_get_topic_author_id( $topic_id = 0 ) { 
  1231. $topic_id = bbp_get_topic_id( $topic_id ); 
  1232. $author_id = get_post_field( 'post_author', $topic_id ); 
  1233.  
  1234. return (int) apply_filters( 'bbp_get_topic_author_id', (int) $author_id, $topic_id ); 
  1235.  
  1236. /** 
  1237. * Output the author display_name of the topic 
  1238. * 
  1239. * @since bbPress (r2590) 
  1240. * 
  1241. * @param int $topic_id Optional. Topic id 
  1242. * @uses bbp_get_topic_author_display_name() To get the topic author's display 
  1243. * name 
  1244. */ 
  1245. function bbp_topic_author_display_name( $topic_id = 0 ) { 
  1246. echo bbp_get_topic_author_display_name( $topic_id ); 
  1247. /** 
  1248. * Return the author display_name of the topic 
  1249. * 
  1250. * @since bbPress (r2485) 
  1251. * 
  1252. * @param int $topic_id Optional. Topic id 
  1253. * @uses bbp_get_topic_id() To get the topic id 
  1254. * @uses bbp_is_topic_anonymous() To check if the topic is by an 
  1255. * anonymous user 
  1256. * @uses bbp_get_topic_author_id() To get the topic author id 
  1257. * @uses get_the_author_meta() To get the author meta 
  1258. * @uses get_post_meta() To get the anonymous user name 
  1259. * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the 
  1260. * display name and topic id 
  1261. * @return string Topic's author's display name 
  1262. */ 
  1263. function bbp_get_topic_author_display_name( $topic_id = 0 ) { 
  1264. $topic_id = bbp_get_topic_id( $topic_id ); 
  1265.  
  1266. // Check for anonymous user 
  1267. if ( !bbp_is_topic_anonymous( $topic_id ) ) { 
  1268.  
  1269. // Get the author ID 
  1270. $author_id = bbp_get_topic_author_id( $topic_id ); 
  1271.  
  1272. // Try to get a display name 
  1273. $author_name = get_the_author_meta( 'display_name', $author_id ); 
  1274.  
  1275. // Fall back to user login 
  1276. if ( empty( $author_name ) ) { 
  1277. $author_name = get_the_author_meta( 'user_login', $author_id ); 
  1278.  
  1279. // User does not have an account 
  1280. } else { 
  1281. $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true ); 
  1282.  
  1283. // If nothing could be found anywhere, use Anonymous 
  1284. if ( empty( $author_name ) ) 
  1285. $author_name = __( 'Anonymous', 'bbpress' ); 
  1286.  
  1287. // Encode possible UTF8 display names 
  1288. if ( seems_utf8( $author_name ) === false ) 
  1289. $author_name = utf8_encode( $author_name ); 
  1290.  
  1291. return apply_filters( 'bbp_get_topic_author_display_name', $author_name, $topic_id ); 
  1292.  
  1293. /** 
  1294. * Output the author avatar of the topic 
  1295. * 
  1296. * @since bbPress (r2590) 
  1297. * 
  1298. * @param int $topic_id Optional. Topic id 
  1299. * @param int $size Optional. Avatar size. Defaults to 40 
  1300. * @uses bbp_get_topic_author_avatar() To get the topic author avatar 
  1301. */ 
  1302. function bbp_topic_author_avatar( $topic_id = 0, $size = 40 ) { 
  1303. echo bbp_get_topic_author_avatar( $topic_id, $size ); 
  1304. /** 
  1305. * Return the author avatar of the topic 
  1306. * 
  1307. * @since bbPress (r2590) 
  1308. * 
  1309. * @param int $topic_id Optional. Topic id 
  1310. * @param int $size Optional. Avatar size. Defaults to 40 
  1311. * @uses bbp_get_topic_id() To get the topic id 
  1312. * @uses bbp_is_topic_anonymous() To check if the topic is by an 
  1313. * anonymous user 
  1314. * @uses bbp_get_topic_author_id() To get the topic author id 
  1315. * @uses get_post_meta() To get the anonymous user's email 
  1316. * @uses get_avatar() To get the avatar 
  1317. * @uses apply_filters() Calls 'bbp_get_topic_author_avatar' with the 
  1318. * avatar, topic id and size 
  1319. * @return string Avatar of the author of the topic 
  1320. */ 
  1321. function bbp_get_topic_author_avatar( $topic_id = 0, $size = 40 ) { 
  1322. $author_avatar = ''; 
  1323.  
  1324. $topic_id = bbp_get_topic_id( $topic_id ); 
  1325. if ( !empty( $topic_id ) ) { 
  1326. if ( !bbp_is_topic_anonymous( $topic_id ) ) { 
  1327. $author_avatar = get_avatar( bbp_get_topic_author_id( $topic_id ), $size ); 
  1328. } else { 
  1329. $author_avatar = get_avatar( get_post_meta( $topic_id, '_bbp_anonymous_email', true ), $size ); 
  1330.  
  1331. return apply_filters( 'bbp_get_topic_author_avatar', $author_avatar, $topic_id, $size ); 
  1332.  
  1333. /** 
  1334. * Output the author link of the topic 
  1335. * 
  1336. * @since bbPress (r2717) 
  1337. * 
  1338. * @param mixed|int $args If it is an integer, it is used as topic_id. Optional. 
  1339. * @uses bbp_get_topic_author_link() To get the topic author link 
  1340. */ 
  1341. function bbp_topic_author_link( $args = '' ) { 
  1342. echo bbp_get_topic_author_link( $args ); 
  1343. /** 
  1344. * Return the author link of the topic 
  1345. * 
  1346. * @since bbPress (r2717) 
  1347. * 
  1348. * @param mixed|int $args If it is an integer, it is used as topic id. 
  1349. * Optional. 
  1350. * @uses bbp_get_topic_id() To get the topic id 
  1351. * @uses bbp_get_topic_author_display_name() To get the topic author 
  1352. * @uses bbp_is_topic_anonymous() To check if the topic is by an 
  1353. * anonymous user 
  1354. * @uses bbp_get_topic_author_url() To get the topic author url 
  1355. * @uses bbp_get_topic_author_avatar() To get the topic author avatar 
  1356. * @uses bbp_get_topic_author_display_name() To get the topic author display 
  1357. * name 
  1358. * @uses bbp_get_user_display_role() To get the topic author display role 
  1359. * @uses bbp_get_topic_author_id() To get the topic author id 
  1360. * @uses apply_filters() Calls 'bbp_get_topic_author_link' with the link 
  1361. * and args 
  1362. * @return string Author link of topic 
  1363. */ 
  1364. function bbp_get_topic_author_link( $args = '' ) { 
  1365.  
  1366. // Parse arguments against default values 
  1367. $r = bbp_parse_args( $args, array( 
  1368. 'post_id' => 0,  
  1369. 'link_title' => '',  
  1370. 'type' => 'both',  
  1371. 'size' => 80,  
  1372. 'sep' => ' ',  
  1373. 'show_role' => false 
  1374. ), 'get_topic_author_link' ); 
  1375.  
  1376. // Used as topic_id 
  1377. if ( is_numeric( $args ) ) { 
  1378. $topic_id = bbp_get_topic_id( $args ); 
  1379. } else { 
  1380. $topic_id = bbp_get_topic_id( $r['post_id'] ); 
  1381.  
  1382. // Topic ID is good 
  1383. if ( !empty( $topic_id ) ) { 
  1384.  
  1385. // Get some useful topic information 
  1386. $author_url = bbp_get_topic_author_url( $topic_id ); 
  1387. $anonymous = bbp_is_topic_anonymous( $topic_id ); 
  1388.  
  1389. // Tweak link title if empty 
  1390. if ( empty( $r['link_title'] ) ) { 
  1391. $link_title = sprintf( empty( $anonymous ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_topic_author_display_name( $topic_id ) ); 
  1392.  
  1393. // Use what was passed if not 
  1394. } else { 
  1395. $link_title = $r['link_title']; 
  1396.  
  1397. // Setup title and author_links array 
  1398. $link_title = !empty( $link_title ) ? ' title="' . esc_attr( $link_title ) . '"' : ''; 
  1399. $author_links = array(); 
  1400.  
  1401. // Get avatar 
  1402. if ( 'avatar' === $r['type'] || 'both' === $r['type'] ) { 
  1403. $author_links['avatar'] = bbp_get_topic_author_avatar( $topic_id, $r['size'] ); 
  1404.  
  1405. // Get display name 
  1406. if ( 'name' === $r['type'] || 'both' === $r['type'] ) { 
  1407. $author_links['name'] = bbp_get_topic_author_display_name( $topic_id ); 
  1408.  
  1409. // Link class 
  1410. $link_class = ' class="bbp-author-' . esc_attr( $r['type'] ) . '"'; 
  1411.  
  1412. // Add links if not anonymous 
  1413. if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) { 
  1414.  
  1415. // Assemble the links 
  1416. foreach ( $author_links as $link => $link_text ) { 
  1417. $link_class = ' class="bbp-author-' . esc_attr( $link ) . '"'; 
  1418. $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text ); 
  1419.  
  1420. if ( true === $r['show_role'] ) { 
  1421. $author_link[] = bbp_get_topic_author_role( array( 'topic_id' => $topic_id ) ); 
  1422.  
  1423. $author_link = implode( $r['sep'], $author_link ); 
  1424.  
  1425. // No links if anonymous 
  1426. } else { 
  1427. $author_link = implode( $r['sep'], $author_links ); 
  1428.  
  1429. } else { 
  1430. $author_link = ''; 
  1431.  
  1432. return apply_filters( 'bbp_get_topic_author_link', $author_link, $args ); 
  1433.  
  1434. /** 
  1435. * Output the author url of the topic 
  1436. * 
  1437. * @since bbPress (r2590) 
  1438. * 
  1439. * @param int $topic_id Optional. Topic id 
  1440. * @uses bbp_get_topic_author_url() To get the topic author url 
  1441. */ 
  1442. function bbp_topic_author_url( $topic_id = 0 ) { 
  1443. echo esc_url( bbp_get_topic_author_url( $topic_id ) ); 
  1444.  
  1445. /** 
  1446. * Return the author url of the topic 
  1447. * 
  1448. * @since bbPress (r2590) 
  1449. * 
  1450. * @param int $topic_id Optional. Topic id 
  1451. * @uses bbp_get_topic_id() To get the topic id 
  1452. * @uses bbp_is_topic_anonymous() To check if the topic is by an anonymous 
  1453. * user or not 
  1454. * @uses bbp_user_has_profile() To check if the user has a profile 
  1455. * @uses bbp_get_topic_author_id() To get topic author id 
  1456. * @uses bbp_get_user_profile_url() To get profile url 
  1457. * @uses get_post_meta() To get anonmous user's website 
  1458. * @uses apply_filters() Calls 'bbp_get_topic_author_url' with the link & 
  1459. * topic id 
  1460. * @return string Author URL of topic 
  1461. */ 
  1462. function bbp_get_topic_author_url( $topic_id = 0 ) { 
  1463. $topic_id = bbp_get_topic_id( $topic_id ); 
  1464.  
  1465. // Check for anonymous user or non-existant user 
  1466. if ( !bbp_is_topic_anonymous( $topic_id ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) { 
  1467. $author_url = bbp_get_user_profile_url( bbp_get_topic_author_id( $topic_id ) ); 
  1468. } else { 
  1469. $author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true ); 
  1470.  
  1471. // Set empty author_url as empty string 
  1472. if ( empty( $author_url ) ) { 
  1473. $author_url = ''; 
  1474.  
  1475. return apply_filters( 'bbp_get_topic_author_url', $author_url, $topic_id ); 
  1476.  
  1477. /** 
  1478. * Output the topic author email address 
  1479. * 
  1480. * @since bbPress (r3445) 
  1481. * 
  1482. * @param int $topic_id Optional. Reply id 
  1483. * @uses bbp_get_topic_author_email() To get the topic author email 
  1484. */ 
  1485. function bbp_topic_author_email( $topic_id = 0 ) { 
  1486. echo bbp_get_topic_author_email( $topic_id ); 
  1487. /** 
  1488. * Return the topic author email address 
  1489. * 
  1490. * @since bbPress (r3445) 
  1491. * 
  1492. * @param int $topic_id Optional. Reply id 
  1493. * @uses bbp_get_topic_id() To get the topic id 
  1494. * @uses bbp_is_topic_anonymous() To check if the topic is by an anonymous 
  1495. * user 
  1496. * @uses bbp_get_topic_author_id() To get the topic author id 
  1497. * @uses get_userdata() To get the user data 
  1498. * @uses get_post_meta() To get the anonymous poster's email 
  1499. * @uses apply_filters() Calls bbp_get_topic_author_email with the author 
  1500. * email & topic id 
  1501. * @return string Topic author email address 
  1502. */ 
  1503. function bbp_get_topic_author_email( $topic_id = 0 ) { 
  1504. $topic_id = bbp_get_topic_id( $topic_id ); 
  1505.  
  1506. // Not anonymous user 
  1507. if ( !bbp_is_topic_anonymous( $topic_id ) ) { 
  1508.  
  1509. // Use topic author email address 
  1510. $user_id = bbp_get_topic_author_id( $topic_id ); 
  1511. $user = get_userdata( $user_id ); 
  1512. $author_email = !empty( $user->user_email ) ? $user->user_email : ''; 
  1513.  
  1514. // Anonymous 
  1515. } else { 
  1516.  
  1517. // Get email from post meta 
  1518. $author_email = get_post_meta( $topic_id, '_bbp_anonymous_email', true ); 
  1519.  
  1520. // Sanity check for missing email address 
  1521. if ( empty( $author_email ) ) { 
  1522. $author_email = ''; 
  1523.  
  1524. return apply_filters( 'bbp_get_topic_author_email', $author_email, $topic_id ); 
  1525.  
  1526. /** 
  1527. * Output the topic author role 
  1528. * 
  1529. * @since bbPress (r3860) 
  1530. * 
  1531. * @param array $args Optional. 
  1532. * @uses bbp_get_topic_author_role() To get the topic author role 
  1533. */ 
  1534. function bbp_topic_author_role( $args = array() ) { 
  1535. echo bbp_get_topic_author_role( $args ); 
  1536. /** 
  1537. * Return the topic author role 
  1538. * 
  1539. * @since bbPress (r3860) 
  1540. * 
  1541. * @param array $args Optional. 
  1542. * @uses bbp_get_topic_id() To get the topic id 
  1543. * @uses bbp_get_user_display_role() To get the user display role 
  1544. * @uses bbp_get_topic_author_id() To get the topic author id 
  1545. * @uses apply_filters() Calls bbp_get_topic_author_role with the author 
  1546. * role & args 
  1547. * @return string topic author role 
  1548. */ 
  1549. function bbp_get_topic_author_role( $args = array() ) { 
  1550.  
  1551. // Parse arguments against default values 
  1552. $r = bbp_parse_args( $args, array( 
  1553. 'topic_id' => 0,  
  1554. 'class' => 'bbp-author-role',  
  1555. 'before' => '',  
  1556. 'after' => '' 
  1557. ), 'get_topic_author_role' ); 
  1558.  
  1559. $topic_id = bbp_get_topic_id( $r['topic_id'] ); 
  1560. $role = bbp_get_user_display_role( bbp_get_topic_author_id( $topic_id ) ); 
  1561. $author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], $r['class'], $role, $r['after'] ); 
  1562.  
  1563. return apply_filters( 'bbp_get_topic_author_role', $author_role, $r ); 
  1564.  
  1565.  
  1566. /** 
  1567. * Output the title of the forum a topic belongs to 
  1568. * 
  1569. * @since bbPress (r2485) 
  1570. * 
  1571. * @param int $topic_id Optional. Topic id 
  1572. * @uses bbp_get_topic_forum_title() To get the topic's forum title 
  1573. */ 
  1574. function bbp_topic_forum_title( $topic_id = 0 ) { 
  1575. echo bbp_get_topic_forum_title( $topic_id ); 
  1576. /** 
  1577. * Return the title of the forum a topic belongs to 
  1578. * 
  1579. * @since bbPress (r2485) 
  1580. * 
  1581. * @param int $topic_id Optional. Topic id 
  1582. * @uses bbp_get_topic_id() To get topic id 
  1583. * @uses bbp_get_topic_forum_id() To get topic's forum id 
  1584. * @uses apply_filters() Calls 'bbp_get_topic_forum' with the forum 
  1585. * title and topic id 
  1586. * @return string Topic forum title 
  1587. */ 
  1588. function bbp_get_topic_forum_title( $topic_id = 0 ) { 
  1589. $topic_id = bbp_get_topic_id( $topic_id ); 
  1590. $forum_id = bbp_get_topic_forum_id( $topic_id ); 
  1591.  
  1592. return apply_filters( 'bbp_get_topic_forum', bbp_get_forum_title( $forum_id ), $topic_id, $forum_id ); 
  1593.  
  1594. /** 
  1595. * Output the forum id a topic belongs to 
  1596. * 
  1597. * @since bbPress (r2491) 
  1598. * 
  1599. * @param int $topic_id Optional. Topic id 
  1600. * @uses bbp_get_topic_forum_id() 
  1601. */ 
  1602. function bbp_topic_forum_id( $topic_id = 0 ) { 
  1603. echo bbp_get_topic_forum_id( $topic_id ); 
  1604. /** 
  1605. * Return the forum id a topic belongs to 
  1606. * 
  1607. * @since bbPress (r2491) 
  1608. * 
  1609. * @param int $topic_id Optional. Topic id 
  1610. * @uses bbp_get_topic_id() To get topic id 
  1611. * @uses get_post_meta() To retrieve get topic's forum id meta 
  1612. * @uses apply_filters() Calls 'bbp_get_topic_forum_id' with the forum 
  1613. * id and topic id 
  1614. * @return int Topic forum id 
  1615. */ 
  1616. function bbp_get_topic_forum_id( $topic_id = 0 ) { 
  1617. $topic_id = bbp_get_topic_id( $topic_id ); 
  1618. $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true ); 
  1619.  
  1620. return (int) apply_filters( 'bbp_get_topic_forum_id', (int) $forum_id, $topic_id ); 
  1621.  
  1622. /** 
  1623. * Output the topics last active ID 
  1624. * 
  1625. * @since bbPress (r2860) 
  1626. * 
  1627. * @param int $topic_id Optional. Forum id 
  1628. * @uses bbp_get_topic_last_active_id() To get the topic's last active id 
  1629. */ 
  1630. function bbp_topic_last_active_id( $topic_id = 0 ) { 
  1631. echo bbp_get_topic_last_active_id( $topic_id ); 
  1632. /** 
  1633. * Return the topics last active ID 
  1634. * 
  1635. * @since bbPress (r2860) 
  1636. * 
  1637. * @param int $topic_id Optional. Forum id 
  1638. * @uses bbp_get_topic_id() To get the topic id 
  1639. * @uses get_post_meta() To get the topic's last active id 
  1640. * @uses apply_filters() Calls 'bbp_get_topic_last_active_id' with 
  1641. * the last active id and topic id 
  1642. * @return int Forum's last active id 
  1643. */ 
  1644. function bbp_get_topic_last_active_id( $topic_id = 0 ) { 
  1645. $topic_id = bbp_get_topic_id( $topic_id ); 
  1646. $active_id = get_post_meta( $topic_id, '_bbp_last_active_id', true ); 
  1647.  
  1648. return (int) apply_filters( 'bbp_get_topic_last_active_id', (int) $active_id, $topic_id ); 
  1649.  
  1650. /** 
  1651. * Output the topics last update date/time (aka freshness) 
  1652. * 
  1653. * @since bbPress (r2625) 
  1654. * 
  1655. * @param int $topic_id Optional. Topic id 
  1656. * @uses bbp_get_topic_last_active_time() To get topic freshness 
  1657. */ 
  1658. function bbp_topic_last_active_time( $topic_id = 0 ) { 
  1659. echo bbp_get_topic_last_active_time( $topic_id ); 
  1660. /** 
  1661. * Return the topics last update date/time (aka freshness) 
  1662. * 
  1663. * @since bbPress (r2625) 
  1664. * 
  1665. * @param int $topic_id Optional. Topic id 
  1666. * @uses bbp_get_topic_id() To get topic id 
  1667. * @uses get_post_meta() To get the topic lst active meta 
  1668. * @uses bbp_get_topic_last_reply_id() To get topic last reply id 
  1669. * @uses get_post_field() To get the post date of topic/reply 
  1670. * @uses bbp_convert_date() To convert date 
  1671. * @uses bbp_get_time_since() To get time in since format 
  1672. * @uses apply_filters() Calls 'bbp_get_topic_last_active' with topic 
  1673. * freshness and topic id 
  1674. * @return string Topic freshness 
  1675. */ 
  1676. function bbp_get_topic_last_active_time( $topic_id = 0 ) { 
  1677. $topic_id = bbp_get_topic_id( $topic_id ); 
  1678.  
  1679. // Try to get the most accurate freshness time possible 
  1680. $last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true ); 
  1681. if ( empty( $last_active ) ) { 
  1682. $reply_id = bbp_get_topic_last_reply_id( $topic_id ); 
  1683. if ( !empty( $reply_id ) ) { 
  1684. $last_active = get_post_field( 'post_date', $reply_id ); 
  1685. } else { 
  1686. $last_active = get_post_field( 'post_date', $topic_id ); 
  1687.  
  1688. $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; 
  1689.  
  1690. // Return the time since 
  1691. return apply_filters( 'bbp_get_topic_last_active', $last_active, $topic_id ); 
  1692.  
  1693. /** Topic Subscriptions *******************************************************/ 
  1694.  
  1695. /** 
  1696. * Output the topic subscription link 
  1697. * 
  1698. * @since bbPress (r5156) 
  1699. * 
  1700. * @uses bbp_get_topic_subscription_link() 
  1701. */ 
  1702. function bbp_topic_subscription_link( $args = array() ) { 
  1703. echo bbp_get_topic_subscription_link( $args ); 
  1704.  
  1705. /** 
  1706. * Get the forum subscription link 
  1707. * 
  1708. * A custom wrapper for bbp_get_user_subscribe_link() 
  1709. * 
  1710. * @since bbPress (r5156) 
  1711. * 
  1712. * @uses bbp_parse_args() 
  1713. * @uses bbp_get_user_subscribe_link() 
  1714. * @uses apply_filters() Calls 'bbp_get_topic_subscribe_link' 
  1715. */ 
  1716. function bbp_get_topic_subscription_link( $args = array() ) { 
  1717.  
  1718. // No link 
  1719. $retval = false; 
  1720.  
  1721. // Parse the arguments 
  1722. $r = bbp_parse_args( $args, array( 
  1723. 'user_id' => 0,  
  1724. 'topic_id' => 0,  
  1725. 'before' => ' | ',  
  1726. 'after' => '',  
  1727. 'subscribe' => __( 'Subscribe', 'bbpress' ),  
  1728. 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ) 
  1729. ), 'get_forum_subscribe_link' ); 
  1730.  
  1731. // Get the link 
  1732. $retval = bbp_get_user_subscribe_link( $r ); 
  1733.  
  1734. return apply_filters( 'bbp_get_topic_subscribe_link', $retval, $r ); 
  1735.  
  1736. /** Topic Favorites ***********************************************************/ 
  1737.  
  1738. /** 
  1739. * Output the topic favorite link 
  1740. * 
  1741. * @since bbPress (r5156) 
  1742. * 
  1743. * @uses bbp_get_topic_favorite_link() 
  1744. */ 
  1745. function bbp_topic_favorite_link( $args = array() ) { 
  1746. echo bbp_get_topic_favorite_link( $args ); 
  1747.  
  1748. /** 
  1749. * Get the forum favorite link 
  1750. * 
  1751. * A custom wrapper for bbp_get_user_favorite_link() 
  1752. * 
  1753. * @since bbPress (r5156) 
  1754. * 
  1755. * @uses bbp_parse_args() 
  1756. * @uses bbp_get_user_favorites_link() 
  1757. * @uses apply_filters() Calls 'bbp_get_topic_favorite_link' 
  1758. */ 
  1759. function bbp_get_topic_favorite_link( $args = array() ) { 
  1760.  
  1761. // No link 
  1762. $retval = false; 
  1763.  
  1764. // Parse the arguments 
  1765. $r = bbp_parse_args( $args, array( 
  1766. 'user_id' => 0,  
  1767. 'topic_id' => 0,  
  1768. 'before' => '',  
  1769. 'after' => '',  
  1770. 'favorite' => __( 'Favorite', 'bbpress' ),  
  1771. 'favorited' => __( 'Unfavorite', 'bbpress' ) 
  1772. ), 'get_forum_favorite_link' ); 
  1773.  
  1774. // Get the link 
  1775. $retval = bbp_get_user_favorites_link( $r ); 
  1776.  
  1777. return apply_filters( 'bbp_get_topic_favorite_link', $retval, $r ); 
  1778.  
  1779. /** Topic Last Reply **********************************************************/ 
  1780.  
  1781. /** 
  1782. * Output the id of the topics last reply 
  1783. * 
  1784. * @since bbPress (r2625) 
  1785. * 
  1786. * @param int $topic_id Optional. Topic id 
  1787. * @uses bbp_get_topic_last_reply_id() To get the topic last reply id 
  1788. */ 
  1789. function bbp_topic_last_reply_id( $topic_id = 0 ) { 
  1790. echo bbp_get_topic_last_reply_id( $topic_id ); 
  1791. /** 
  1792. * Return the topics last update date/time (aka freshness) 
  1793. * 
  1794. * @since bbPress (r2625) 
  1795. * 
  1796. * @param int $topic_id Optional. Topic id 
  1797. * @uses bbp_get_topic_id() To get the topic id 
  1798. * @uses get_post_meta() To get the last reply id meta 
  1799. * @uses apply_filters() Calls 'bbp_get_topic_last_reply_id' with the 
  1800. * last reply id and topic id 
  1801. * @return int Topic last reply id 
  1802. */ 
  1803. function bbp_get_topic_last_reply_id( $topic_id = 0 ) { 
  1804. $topic_id = bbp_get_topic_id( $topic_id ); 
  1805. $reply_id = get_post_meta( $topic_id, '_bbp_last_reply_id', true ); 
  1806.  
  1807. if ( empty( $reply_id ) ) 
  1808. $reply_id = $topic_id; 
  1809.  
  1810. return (int) apply_filters( 'bbp_get_topic_last_reply_id', (int) $reply_id, $topic_id ); 
  1811.  
  1812. /** 
  1813. * Output the title of the last reply inside a topic 
  1814. * 
  1815. * @param int $topic_id Optional. Topic id 
  1816. * @uses bbp_get_topic_last_reply_title() To get the topic last reply title 
  1817. */ 
  1818. function bbp_topic_last_reply_title( $topic_id = 0 ) { 
  1819. echo bbp_get_topic_last_reply_title( $topic_id ); 
  1820. /** 
  1821. * Return the title of the last reply inside a topic 
  1822. * 
  1823. * @param int $topic_id Optional. Topic id 
  1824. * @uses bbp_get_topic_id() To get the topic id 
  1825. * @uses bbp_get_topic_last_reply_id() To get the topic last reply id 
  1826. * @uses bbp_get_reply_title() To get the reply title 
  1827. * @uses apply_filters() Calls 'bbp_get_topic_last_topic_title' with 
  1828. * the reply title and topic id 
  1829. * @return string Topic last reply title 
  1830. */ 
  1831. function bbp_get_topic_last_reply_title( $topic_id = 0 ) { 
  1832. $topic_id = bbp_get_topic_id( $topic_id ); 
  1833. return apply_filters( 'bbp_get_topic_last_topic_title', bbp_get_reply_title( bbp_get_topic_last_reply_id( $topic_id ) ), $topic_id ); 
  1834.  
  1835. /** 
  1836. * Output the link to the last reply in a topic 
  1837. * 
  1838. * @since bbPress (r2464) 
  1839. * 
  1840. * @param int $topic_id Optional. Topic id 
  1841. * @uses bbp_get_topic_last_reply_permalink() To get the topic's last reply link 
  1842. */ 
  1843. function bbp_topic_last_reply_permalink( $topic_id = 0 ) { 
  1844. echo esc_url( bbp_get_topic_last_reply_permalink( $topic_id ) ); 
  1845. /** 
  1846. * Return the link to the last reply in a topic 
  1847. * 
  1848. * @since bbPress (r2464) 
  1849. * 
  1850. * @param int $topic_id Optional. Topic id 
  1851. * @uses bbp_get_topic_id() To get the topic id 
  1852. * @uses bbp_get_topic_last_reply_id() To get the topic last reply id 
  1853. * @uses bbp_get_reply_permalink() To get the reply permalink 
  1854. * @uses apply_filters() Calls 'bbp_get_topic_last_topic_permalink' with 
  1855. * the reply permalink and topic id 
  1856. * @return string Permanent link to the reply 
  1857. */ 
  1858. function bbp_get_topic_last_reply_permalink( $topic_id = 0 ) { 
  1859. $topic_id = bbp_get_topic_id( $topic_id ); 
  1860. return apply_filters( 'bbp_get_topic_last_reply_permalink', bbp_get_reply_permalink( bbp_get_topic_last_reply_id( $topic_id ) ) ); 
  1861.  
  1862. /** 
  1863. * Output the link to the last reply in a topic 
  1864. * 
  1865. * @since bbPress (r2683) 
  1866. * 
  1867. * @param int $topic_id Optional. Topic id 
  1868. * @uses bbp_get_topic_last_reply_url() To get the topic last reply url 
  1869. */ 
  1870. function bbp_topic_last_reply_url( $topic_id = 0 ) { 
  1871. echo esc_url( bbp_get_topic_last_reply_url( $topic_id ) ); 
  1872. /** 
  1873. * Return the link to the last reply in a topic 
  1874. * 
  1875. * @since bbPress (r2683) 
  1876. * 
  1877. * @param int $topic_id Optional. Topic id 
  1878. * @uses bbp_get_topic_id() To get the topic id 
  1879. * @uses bbp_get_topic_last_reply_id() To get the topic last reply id 
  1880. * @uses bbp_get_reply_url() To get the reply url 
  1881. * @uses bbp_get_reply_permalink() To get the reply permalink 
  1882. * @uses apply_filters() Calls 'bbp_get_topic_last_topic_url' with 
  1883. * the reply url and topic id 
  1884. * @return string Topic last reply url 
  1885. */ 
  1886. function bbp_get_topic_last_reply_url( $topic_id = 0 ) { 
  1887. $topic_id = bbp_get_topic_id( $topic_id ); 
  1888. $reply_id = bbp_get_topic_last_reply_id( $topic_id ); 
  1889.  
  1890. if ( !empty( $reply_id ) && ( $reply_id !== $topic_id ) ) { 
  1891. $reply_url = bbp_get_reply_url( $reply_id ); 
  1892. } else { 
  1893. $reply_url = bbp_get_topic_permalink( $topic_id ); 
  1894.  
  1895. return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url ); 
  1896.  
  1897. /** 
  1898. * Output link to the most recent activity inside a topic, complete with link 
  1899. * attributes and content. 
  1900. * 
  1901. * @since bbPress (r2625) 
  1902. * 
  1903. * @param int $topic_id Optional. Topic id 
  1904. * @uses bbp_get_topic_freshness_link() To get the topic freshness link 
  1905. */ 
  1906. function bbp_topic_freshness_link( $topic_id = 0 ) { 
  1907. echo bbp_get_topic_freshness_link( $topic_id ); 
  1908. /** 
  1909. * Returns link to the most recent activity inside a topic, complete 
  1910. * with link attributes and content. 
  1911. * 
  1912. * @since bbPress (r2625) 
  1913. * 
  1914. * @param int $topic_id Optional. Topic id 
  1915. * @uses bbp_get_topic_id() To get the topic id 
  1916. * @uses bbp_get_topic_last_reply_url() To get the topic last reply url 
  1917. * @uses bbp_get_topic_last_reply_title() To get the reply title 
  1918. * @uses bbp_get_topic_last_active_time() To get the topic freshness 
  1919. * @uses apply_filters() Calls 'bbp_get_topic_freshness_link' with the 
  1920. * link and topic id 
  1921. * @return string Topic freshness link 
  1922. */ 
  1923. function bbp_get_topic_freshness_link( $topic_id = 0 ) { 
  1924. $topic_id = bbp_get_topic_id( $topic_id ); 
  1925. $link_url = bbp_get_topic_last_reply_url( $topic_id ); 
  1926. $title = bbp_get_topic_last_reply_title( $topic_id ); 
  1927. $time_since = bbp_get_topic_last_active_time( $topic_id ); 
  1928.  
  1929. if ( !empty( $time_since ) ) 
  1930. $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>'; 
  1931. else 
  1932. $anchor = __( 'No Replies', 'bbpress' ); 
  1933.  
  1934. return apply_filters( 'bbp_get_topic_freshness_link', $anchor, $topic_id, $time_since, $link_url, $title ); 
  1935.  
  1936. /** 
  1937. * Output the replies link of the topic 
  1938. * 
  1939. * @since bbPress (r2740) 
  1940. * 
  1941. * @param int $topic_id Optional. Topic id 
  1942. * @uses bbp_get_topic_replies_link() To get the topic replies link 
  1943. */ 
  1944. function bbp_topic_replies_link( $topic_id = 0 ) { 
  1945. echo bbp_get_topic_replies_link( $topic_id ); 
  1946.  
  1947. /** 
  1948. * Return the replies link of the topic 
  1949. * 
  1950. * @since bbPress (r2740) 
  1951. * 
  1952. * @param int $topic_id Optional. Topic id 
  1953. * @uses bbp_get_topic_id() To get the topic id 
  1954. * @uses bbp_get_topic() To get the topic 
  1955. * @uses bbp_get_topic_reply_count() To get the topic reply count 
  1956. * @uses bbp_get_topic_permalink() To get the topic permalink 
  1957. * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden 
  1958. * reply count 
  1959. * @uses current_user_can() To check if the current user can edit others 
  1960. * replies 
  1961. * @uses apply_filters() Calls 'bbp_get_topic_replies_link' with the 
  1962. * replies link and topic id 
  1963. */ 
  1964. function bbp_get_topic_replies_link( $topic_id = 0 ) { 
  1965.  
  1966. $topic = bbp_get_topic( bbp_get_topic_id( (int) $topic_id ) ); 
  1967. $topic_id = $topic->ID; 
  1968. $replies = sprintf( _n( '%s reply', '%s replies', bbp_get_topic_reply_count( $topic_id, true ), 'bbpress' ), bbp_get_topic_reply_count( $topic_id ) ); 
  1969. $retval = ''; 
  1970.  
  1971. // First link never has view=all 
  1972. if ( bbp_get_view_all( 'edit_others_replies' ) ) 
  1973. $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) ) ) . "'>$replies</a>"; 
  1974. else 
  1975. $retval .= $replies; 
  1976.  
  1977. // Any deleted replies? 
  1978. $deleted = bbp_get_topic_reply_count_hidden( $topic_id ); 
  1979.  
  1980. // This forum has hidden topics 
  1981. if ( !empty( $deleted ) && current_user_can( 'edit_others_replies' ) ) { 
  1982.  
  1983. // Extra text 
  1984. $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted ); 
  1985.  
  1986. // No link 
  1987. if ( bbp_get_view_all() ) { 
  1988. $retval .= " $extra"; 
  1989.  
  1990. // Link 
  1991. } else { 
  1992. $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_topic_permalink( $topic_id ), true ) ) . "'>$extra</a>"; 
  1993.  
  1994. return apply_filters( 'bbp_get_topic_replies_link', $retval, $topic_id ); 
  1995.  
  1996. /** 
  1997. * Output total reply count of a topic 
  1998. * 
  1999. * @since bbPress (r2485) 
  2000. * 
  2001. * @param int $topic_id Optional. Topic id 
  2002. * @param boolean $integer Optional. Whether or not to format the result 
  2003. * @uses bbp_get_topic_reply_count() To get the topic reply count 
  2004. */ 
  2005. function bbp_topic_reply_count( $topic_id = 0, $integer = false ) { 
  2006. echo bbp_get_topic_reply_count( $topic_id, $integer ); 
  2007. /** 
  2008. * Return total reply count of a topic 
  2009. * 
  2010. * @since bbPress (r2485) 
  2011. * 
  2012. * @param int $topic_id Optional. Topic id 
  2013. * @param boolean $integer Optional. Whether or not to format the result 
  2014. * @uses bbp_get_topic_id() To get the topic id 
  2015. * @uses get_post_meta() To get the topic reply count meta 
  2016. * @uses apply_filters() Calls 'bbp_get_topic_reply_count' with the 
  2017. * reply count and topic id 
  2018. * @return int Reply count 
  2019. */ 
  2020. function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) { 
  2021. $topic_id = bbp_get_topic_id( $topic_id ); 
  2022. $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ); 
  2023. $filter = ( true === $integer ) ? 'bbp_get_topic_reply_count_int' : 'bbp_get_topic_reply_count'; 
  2024.  
  2025. return apply_filters( $filter, $replies, $topic_id ); 
  2026.  
  2027. /** 
  2028. * Output total post count of a topic 
  2029. * 
  2030. * @since bbPress (r2954) 
  2031. * 
  2032. * @param int $topic_id Optional. Topic id 
  2033. * @param boolean $integer Optional. Whether or not to format the result 
  2034. * @uses bbp_get_topic_post_count() To get the topic post count 
  2035. */ 
  2036. function bbp_topic_post_count( $topic_id = 0, $integer = false ) { 
  2037. echo bbp_get_topic_post_count( $topic_id, $integer ); 
  2038. /** 
  2039. * Return total post count of a topic 
  2040. * 
  2041. * @since bbPress (r2954) 
  2042. * 
  2043. * @param int $topic_id Optional. Topic id 
  2044. * @param boolean $integer Optional. Whether or not to format the result 
  2045. * @uses bbp_get_topic_id() To get the topic id 
  2046. * @uses get_post_meta() To get the topic post count meta 
  2047. * @uses apply_filters() Calls 'bbp_get_topic_post_count' with the 
  2048. * post count and topic id 
  2049. * @return int Post count 
  2050. */ 
  2051. function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) { 
  2052. $topic_id = bbp_get_topic_id( $topic_id ); 
  2053. $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ) + 1; 
  2054. $filter = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count'; 
  2055.  
  2056. return apply_filters( $filter, $replies, $topic_id ); 
  2057.  
  2058. /** 
  2059. * Output total hidden reply count of a topic (hidden includes trashed and 
  2060. * spammed replies) 
  2061. * 
  2062. * @since bbPress (r2740) 
  2063. * 
  2064. * @param int $topic_id Optional. Topic id 
  2065. * @param boolean $integer Optional. Whether or not to format the result 
  2066. * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count 
  2067. */ 
  2068. function bbp_topic_reply_count_hidden( $topic_id = 0, $integer = false ) { 
  2069. echo bbp_get_topic_reply_count_hidden( $topic_id, $integer ); 
  2070. /** 
  2071. * Return total hidden reply count of a topic (hidden includes trashed 
  2072. * and spammed replies) 
  2073. * 
  2074. * @since bbPress (r2740) 
  2075. * 
  2076. * @param int $topic_id Optional. Topic id 
  2077. * @param boolean $integer Optional. Whether or not to format the result 
  2078. * @uses bbp_get_topic_id() To get the topic id 
  2079. * @uses get_post_meta() To get the hidden reply count 
  2080. * @uses apply_filters() Calls 'bbp_get_topic_reply_count_hidden' with 
  2081. * the hidden reply count and topic id 
  2082. * @return int Topic hidden reply count 
  2083. */ 
  2084. function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) { 
  2085. $topic_id = bbp_get_topic_id( $topic_id ); 
  2086. $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ); 
  2087. $filter = ( true === $integer ) ? 'bbp_get_topic_reply_count_hidden_int' : 'bbp_get_topic_reply_count_hidden'; 
  2088.  
  2089. return apply_filters( $filter, $replies, $topic_id ); 
  2090.  
  2091. /** 
  2092. * Output total voice count of a topic 
  2093. * 
  2094. * @since bbPress (r2567) 
  2095. * 
  2096. * @param int $topic_id Optional. Topic id 
  2097. * @uses bbp_get_topic_voice_count() To get the topic voice count 
  2098. */ 
  2099. function bbp_topic_voice_count( $topic_id = 0, $integer = false ) { 
  2100. echo bbp_get_topic_voice_count( $topic_id, $integer ); 
  2101. /** 
  2102. * Return total voice count of a topic 
  2103. * 
  2104. * @since bbPress (r2567) 
  2105. * 
  2106. * @param int $topic_id Optional. Topic id 
  2107. * @uses bbp_get_topic_id() To get the topic id 
  2108. * @uses get_post_meta() To get the voice count meta 
  2109. * @uses apply_filters() Calls 'bbp_get_topic_voice_count' with the 
  2110. * voice count and topic id 
  2111. * @return int Voice count of the topic 
  2112. */ 
  2113. function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) { 
  2114. $topic_id = bbp_get_topic_id( $topic_id ); 
  2115. $voices = (int) get_post_meta( $topic_id, '_bbp_voice_count', true ); 
  2116. $filter = ( true === $integer ) ? 'bbp_get_topic_voice_count_int' : 'bbp_get_topic_voice_count'; 
  2117.  
  2118. return apply_filters( $filter, $voices, $topic_id ); 
  2119.  
  2120. /** 
  2121. * Output a the tags of a topic 
  2122. * 
  2123. * @param int $topic_id Optional. Topic id 
  2124. * @param mixed $args See {@link bbp_get_topic_tag_list()} 
  2125. * @uses bbp_get_topic_tag_list() To get the topic tag list 
  2126. */ 
  2127. function bbp_topic_tag_list( $topic_id = 0, $args = '' ) { 
  2128. echo bbp_get_topic_tag_list( $topic_id, $args ); 
  2129. /** 
  2130. * Return the tags of a topic 
  2131. * 
  2132. * @param int $topic_id Optional. Topic id 
  2133. * @param array $args This function supports these arguments: 
  2134. * - before: Before the tag list 
  2135. * - sep: Tag separator 
  2136. * - after: After the tag list 
  2137. * @uses bbp_get_topic_id() To get the topic id 
  2138. * @uses get_the_term_list() To get the tags list 
  2139. * @return string Tag list of the topic 
  2140. */ 
  2141. function bbp_get_topic_tag_list( $topic_id = 0, $args = '' ) { 
  2142.  
  2143. // Bail if topic-tags are off 
  2144. if ( ! bbp_allow_topic_tags() ) 
  2145. return; 
  2146.  
  2147. // Parse arguments against default values 
  2148. $r = bbp_parse_args( $args, array( 
  2149. 'before' => '<div class="bbp-topic-tags"><p>' . esc_html__( 'Tagged:', 'bbpress' ) . ' ',  
  2150. 'sep' => ', ',  
  2151. 'after' => '</p></div>' 
  2152. ), 'get_topic_tag_list' ); 
  2153.  
  2154. $topic_id = bbp_get_topic_id( $topic_id ); 
  2155.  
  2156. // Topic is spammed, so display pre-spam terms 
  2157. if ( bbp_is_topic_spam( $topic_id ) ) { 
  2158.  
  2159. // Get pre-spam terms 
  2160. $terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true ); 
  2161.  
  2162. // If terms exist, explode them and compile the return value 
  2163. if ( !empty( $terms ) ) { 
  2164. $terms = implode( $r['sep'], $terms ); 
  2165. $retval = $r['before'] . $terms . $r['after']; 
  2166.  
  2167. // No terms so return emty string 
  2168. } else { 
  2169. $retval = ''; 
  2170.  
  2171. // Topic is not spam so display a clickable term list 
  2172. } else { 
  2173. $retval = get_the_term_list( $topic_id, bbp_get_topic_tag_tax_id(), $r['before'], $r['sep'], $r['after'] ); 
  2174.  
  2175. return $retval; 
  2176.  
  2177. /** 
  2178. * Output the row class of a topic 
  2179. * 
  2180. * @since bbPress (r2667) 
  2181. * 
  2182. * @param int $topic_id Optional. Topic id 
  2183. * @param array Extra classes you can pass when calling this function 
  2184. * @uses bbp_get_topic_class() To get the topic class 
  2185. */ 
  2186. function bbp_topic_class( $topic_id = 0, $classes = array() ) { 
  2187. echo bbp_get_topic_class( $topic_id, $classes ); 
  2188. /** 
  2189. * Return the row class of a topic 
  2190. * 
  2191. * @since bbPress (r2667) 
  2192. * 
  2193. * @param int $topic_id Optional. Topic id 
  2194. * @param array Extra classes you can pass when calling this function 
  2195. * @uses bbp_is_topic_sticky() To check if the topic is a sticky 
  2196. * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky 
  2197. * @uses bbp_get_topic_forum_id() To get the topic forum id 
  2198. * @uses get_post_class() To get the topic classes 
  2199. * @uses apply_filters() Calls 'bbp_get_topic_class' with the classes 
  2200. * and topic id 
  2201. * @return string Row class of a topic 
  2202. */ 
  2203. function bbp_get_topic_class( $topic_id = 0, $classes = array() ) { 
  2204. $bbp = bbpress(); 
  2205. $topic_id = bbp_get_topic_id( $topic_id ); 
  2206. $count = isset( $bbp->topic_query->current_post ) ? $bbp->topic_query->current_post : 1; 
  2207. $classes = (array) $classes; 
  2208. $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd'; 
  2209. $classes[] = bbp_is_topic_sticky( $topic_id, false ) ? 'sticky' : ''; 
  2210. $classes[] = bbp_is_topic_super_sticky( $topic_id ) ? 'super-sticky' : ''; 
  2211. $classes[] = 'bbp-parent-forum-' . bbp_get_topic_forum_id( $topic_id ); 
  2212. $classes[] = 'user-id-' . bbp_get_topic_author_id( $topic_id ); 
  2213. $classes = array_filter( $classes ); 
  2214. $classes = get_post_class( $classes, $topic_id ); 
  2215. $classes = apply_filters( 'bbp_get_topic_class', $classes, $topic_id ); 
  2216. $retval = 'class="' . implode( ' ', $classes ) . '"'; 
  2217.  
  2218. return $retval; 
  2219.  
  2220. /** Topic Admin Links *********************************************************/ 
  2221.  
  2222. /** 
  2223. * Output admin links for topic 
  2224. * 
  2225. * @param array $args See {@link bbp_get_topic_admin_links()} 
  2226. * @uses bbp_get_topic_admin_links() To get the topic admin links 
  2227. */ 
  2228. function bbp_topic_admin_links( $args = array() ) { 
  2229. echo bbp_get_topic_admin_links( $args ); 
  2230. /** 
  2231. * Return admin links for topic. 
  2232. * 
  2233. * Move topic functionality is handled by the edit topic page. 
  2234. * 
  2235. * @param array $args This function supports these arguments: 
  2236. * - id: Optional. Topic id 
  2237. * - before: Before the links 
  2238. * - after: After the links 
  2239. * - sep: Links separator 
  2240. * - links: Topic admin links array 
  2241. * @uses current_user_can() To check if the current user can edit/delete 
  2242. * the topic 
  2243. * @uses bbp_get_topic_edit_link() To get the topic edit link 
  2244. * @uses bbp_get_topic_trash_link() To get the topic trash link 
  2245. * @uses bbp_get_topic_close_link() To get the topic close link 
  2246. * @uses bbp_get_topic_spam_link() To get the topic spam link 
  2247. * @uses bbp_get_topic_stick_link() To get the topic stick link 
  2248. * @uses bbp_get_topic_merge_link() To get the topic merge link 
  2249. * @uses bbp_get_topic_status() To get the topic status 
  2250. * @uses apply_filters() Calls 'bbp_get_topic_admin_links' with the 
  2251. * topic admin links and args 
  2252. * @return string Topic admin links 
  2253. */ 
  2254. function bbp_get_topic_admin_links( $args = array() ) { 
  2255.  
  2256. // Parse arguments against default values 
  2257. $r = bbp_parse_args( $args, array ( 
  2258. 'id' => bbp_get_topic_id(),  
  2259. 'before' => '<span class="bbp-admin-links">',  
  2260. 'after' => '</span>',  
  2261. 'sep' => ' | ',  
  2262. 'links' => array() 
  2263. ), 'get_topic_admin_links' ); 
  2264.  
  2265. if ( empty( $r['links'] ) ) { 
  2266. $r['links'] = apply_filters( 'bbp_topic_admin_links', array( 
  2267. 'edit' => bbp_get_topic_edit_link ( $r ),  
  2268. 'close' => bbp_get_topic_close_link( $r ),  
  2269. 'stick' => bbp_get_topic_stick_link( $r ),  
  2270. 'merge' => bbp_get_topic_merge_link( $r ),  
  2271. 'trash' => bbp_get_topic_trash_link( $r ),  
  2272. 'spam' => bbp_get_topic_spam_link ( $r ),  
  2273. 'reply' => bbp_get_topic_reply_link( $r ) 
  2274. ), $r['id'] ); 
  2275.  
  2276. // See if links need to be unset 
  2277. $topic_status = bbp_get_topic_status( $r['id'] ); 
  2278. if ( in_array( $topic_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) { 
  2279.  
  2280. // Close link shouldn't be visible on trashed/spammed topics 
  2281. unset( $r['links']['close'] ); 
  2282.  
  2283. // Spam link shouldn't be visible on trashed topics 
  2284. if ( bbp_get_trash_status_id() === $topic_status ) { 
  2285. unset( $r['links']['spam'] ); 
  2286.  
  2287. // Trash link shouldn't be visible on spam topics 
  2288. } elseif ( bbp_get_spam_status_id() === $topic_status ) { 
  2289. unset( $r['links']['trash'] ); 
  2290.  
  2291. // Process the admin links 
  2292. $links = implode( $r['sep'], array_filter( $r['links'] ) ); 
  2293. $retval = $r['before'] . $links . $r['after']; 
  2294.  
  2295. return apply_filters( 'bbp_get_topic_admin_links', $retval, $r, $args ); 
  2296.  
  2297. /** 
  2298. * Output the edit link of the topic 
  2299. * 
  2300. * @since bbPress (r2727) 
  2301. * 
  2302. * @param mixed $args See {@link bbp_get_topic_edit_link()} 
  2303. * @uses bbp_get_topic_edit_link() To get the topic edit link 
  2304. */ 
  2305. function bbp_topic_edit_link( $args = '' ) { 
  2306. echo bbp_get_topic_edit_link( $args ); 
  2307.  
  2308. /** 
  2309. * Return the edit link of the topic 
  2310. * 
  2311. * @since bbPress (r2727) 
  2312. * 
  2313. * @param mixed $args This function supports these args: 
  2314. * - id: Optional. Topic id 
  2315. * - link_before: Before the link 
  2316. * - link_after: After the link 
  2317. * - edit_text: Edit text 
  2318. * @uses bbp_get_topic_id() To get the topic id 
  2319. * @uses bbp_get_topic() To get the topic 
  2320. * @uses current_user_can() To check if the current user can edit the 
  2321. * topic 
  2322. * @uses bbp_get_topic_edit_url() To get the topic edit url 
  2323. * @uses apply_filters() Calls 'bbp_get_topic_edit_link' with the link 
  2324. * and args 
  2325. * @return string Topic edit link 
  2326. */ 
  2327. function bbp_get_topic_edit_link( $args = '' ) { 
  2328.  
  2329. // Parse arguments against default values 
  2330. $r = bbp_parse_args( $args, array( 
  2331. 'id' => 0,  
  2332. 'link_before' => '',  
  2333. 'link_after' => '',  
  2334. 'edit_text' => esc_html__( 'Edit', 'bbpress' ) 
  2335. ), 'get_topic_edit_link' ); 
  2336.  
  2337. $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); 
  2338.  
  2339. // Bypass check if user has caps 
  2340. if ( !current_user_can( 'edit_others_topics' ) ) { 
  2341.  
  2342. // User cannot edit or it is past the lock time 
  2343. if ( empty( $topic ) || !current_user_can( 'edit_topic', $topic->ID ) || bbp_past_edit_lock( $topic->post_date_gmt ) ) { 
  2344. return; 
  2345.  
  2346. // Get uri 
  2347. $uri = bbp_get_topic_edit_url( $r['id'] ); 
  2348.  
  2349. // Bail if no uri 
  2350. if ( empty( $uri ) ) 
  2351. return; 
  2352.  
  2353. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-topic-edit-link">' . $r['edit_text'] . '</a>' . $r['link_after']; 
  2354.  
  2355. return apply_filters( 'bbp_get_topic_edit_link', $retval, $r ); 
  2356.  
  2357. /** 
  2358. * Output URL to the topic edit page 
  2359. * 
  2360. * @since bbPress (r2753) 
  2361. * 
  2362. * @param int $topic_id Optional. Topic id 
  2363. * @uses bbp_get_topic_edit_url() To get the topic edit url 
  2364. */ 
  2365. function bbp_topic_edit_url( $topic_id = 0 ) { 
  2366. echo esc_url( bbp_get_topic_edit_url( $topic_id ) ); 
  2367. /** 
  2368. * Return URL to the topic edit page 
  2369. * 
  2370. * @since bbPress (r2753) 
  2371. * 
  2372. * @param int $topic_id Optional. Topic id 
  2373. * @uses bbp_get_topic_id() To get the topic id 
  2374. * @uses bbp_get_topic() To get the topic 
  2375. * @uses add_query_arg() To add custom args to the url 
  2376. * @uses apply_filters() Calls 'bbp_get_topic_edit_url' with the edit 
  2377. * url and topic id 
  2378. * @return string Topic edit url 
  2379. */ 
  2380. function bbp_get_topic_edit_url( $topic_id = 0 ) { 
  2381. global $wp_rewrite; 
  2382.  
  2383. $bbp = bbpress(); 
  2384.  
  2385. $topic = bbp_get_topic( bbp_get_topic_id( $topic_id ) ); 
  2386. if ( empty( $topic ) ) 
  2387. return; 
  2388.  
  2389. // Remove view=all link from edit 
  2390. $topic_link = bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) ); 
  2391.  
  2392. // Pretty permalinks 
  2393. if ( $wp_rewrite->using_permalinks() ) { 
  2394. $url = trailingslashit( $topic_link ) . $bbp->edit_id; 
  2395. $url = trailingslashit( $url ); 
  2396.  
  2397. // Unpretty permalinks 
  2398. } else { 
  2399. $url = add_query_arg( array( bbp_get_topic_post_type() => $topic->post_name, $bbp->edit_id => '1' ), $topic_link ); 
  2400.  
  2401. // Maybe add view=all 
  2402. $url = bbp_add_view_all( $url ); 
  2403.  
  2404. return apply_filters( 'bbp_get_topic_edit_url', $url, $topic_id ); 
  2405.  
  2406. /** 
  2407. * Output the trash link of the topic 
  2408. * 
  2409. * @since bbPress (r2727) 
  2410. * 
  2411. * @param mixed $args See {@link bbp_get_topic_trash_link()} 
  2412. * @uses bbp_get_topic_trash_link() To get the topic trash link 
  2413. */ 
  2414. function bbp_topic_trash_link( $args = '' ) { 
  2415. echo bbp_get_topic_trash_link( $args ); 
  2416.  
  2417. /** 
  2418. * Return the trash link of the topic 
  2419. * 
  2420. * @since bbPress (r2727) 
  2421. * 
  2422. * @param mixed $args This function supports these args: 
  2423. * - id: Optional. Topic id 
  2424. * - link_before: Before the link 
  2425. * - link_after: After the link 
  2426. * - sep: Links separator 
  2427. * - trash_text: Trash text 
  2428. * - restore_text: Restore text 
  2429. * - delete_text: Delete text 
  2430. * @uses bbp_get_topic_id() To get the topic id 
  2431. * @uses bbp_get_topic() To get the topic 
  2432. * @uses current_user_can() To check if the current user can delete the 
  2433. * topic 
  2434. * @uses bbp_is_topic_trash() To check if the topic is trashed 
  2435. * @uses bbp_get_topic_status() To get the topic status 
  2436. * @uses add_query_arg() To add custom args to the url 
  2437. * @uses wp_nonce_url() To nonce the url 
  2438. * @uses esc_url() To escape the url 
  2439. * @uses apply_filters() Calls 'bbp_get_topic_trash_link' with the link 
  2440. * and args 
  2441. * @return string Topic trash link 
  2442. */ 
  2443. function bbp_get_topic_trash_link( $args = '' ) { 
  2444.  
  2445. // Parse arguments against default values 
  2446. $r = bbp_parse_args( $args, array( 
  2447. 'id' => 0,  
  2448. 'link_before' => '',  
  2449. 'link_after' => '',  
  2450. 'sep' => ' | ',  
  2451. 'trash_text' => esc_html__( 'Trash', 'bbpress' ),  
  2452. 'restore_text' => esc_html__( 'Restore', 'bbpress' ),  
  2453. 'delete_text' => esc_html__( 'Delete', 'bbpress' ) 
  2454. ), 'get_topic_trash_link' ); 
  2455.  
  2456. $actions = array(); 
  2457. $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); 
  2458.  
  2459. if ( empty( $topic ) || !current_user_can( 'delete_topic', $topic->ID ) ) { 
  2460. return; 
  2461.  
  2462. if ( bbp_is_topic_trash( $topic->ID ) ) { 
  2463. $actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'untrash', 'topic_id' => $topic->ID ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) ) . '" class="bbp-topic-restore-link">' . $r['restore_text'] . '</a>'; 
  2464. } elseif ( EMPTY_TRASH_DAYS ) { 
  2465. $actions['trash'] = '<a title="' . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'trash', 'topic_id' => $topic->ID ) ), 'trash-' . $topic->post_type . '_' . $topic->ID ) ) . '" class="bbp-topic-trash-link">' . $r['trash_text'] . '</a>'; 
  2466.  
  2467. if ( bbp_is_topic_trash( $topic->ID ) || !EMPTY_TRASH_DAYS ) { 
  2468. $actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'delete', 'topic_id' => $topic->ID ) ), 'delete-' . $topic->post_type . '_' . $topic->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-topic-delete-link">' . $r['delete_text'] . '</a>'; 
  2469.  
  2470. // Process the admin links 
  2471. $retval = $r['link_before'] . implode( $r['sep'], $actions ) . $r['link_after']; 
  2472.  
  2473. return apply_filters( 'bbp_get_topic_trash_link', $retval, $r ); 
  2474.  
  2475. /** 
  2476. * Output the close link of the topic 
  2477. * 
  2478. * @since bbPress (r2727) 
  2479. * 
  2480. * @param mixed $args See {@link bbp_get_topic_close_link()} 
  2481. * @uses bbp_get_topic_close_link() To get the topic close link 
  2482. */ 
  2483. function bbp_topic_close_link( $args = '' ) { 
  2484. echo bbp_get_topic_close_link( $args ); 
  2485.  
  2486. /** 
  2487. * Return the close link of the topic 
  2488. * 
  2489. * @since bbPress (r2727) 
  2490. * 
  2491. * @param mixed $args This function supports these args: 
  2492. * - id: Optional. Topic id 
  2493. * - link_before: Before the link 
  2494. * - link_after: After the link 
  2495. * - close_text: Close text 
  2496. * - open_text: Open text 
  2497. * @uses bbp_get_topic_id() To get the topic id 
  2498. * @uses bbp_get_topic() To get the topic 
  2499. * @uses current_user_can() To check if the current user can edit the topic 
  2500. * @uses bbp_is_topic_open() To check if the topic is open 
  2501. * @uses add_query_arg() To add custom args to the url 
  2502. * @uses wp_nonce_url() To nonce the url 
  2503. * @uses esc_url() To escape the url 
  2504. * @uses apply_filters() Calls 'bbp_get_topic_close_link' with the link 
  2505. * and args 
  2506. * @return string Topic close link 
  2507. */ 
  2508. function bbp_get_topic_close_link( $args = '' ) { 
  2509.  
  2510. // Parse arguments against default values 
  2511. $r = bbp_parse_args( $args, array( 
  2512. 'id' => 0,  
  2513. 'link_before' => '',  
  2514. 'link_after' => '',  
  2515. 'sep' => ' | ',  
  2516. 'close_text' => _x( 'Close', 'Topic Status', 'bbpress' ),  
  2517. 'open_text' => _x( 'Open', 'Topic Status', 'bbpress' ) 
  2518. ), 'get_topic_close_link' ); 
  2519.  
  2520. $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); 
  2521.  
  2522. if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) ) 
  2523. return; 
  2524.  
  2525. $display = bbp_is_topic_open( $topic->ID ) ? $r['close_text'] : $r['open_text']; 
  2526. $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_close', 'topic_id' => $topic->ID ) ); 
  2527. $uri = wp_nonce_url( $uri, 'close-topic_' . $topic->ID ); 
  2528. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-topic-close-link">' . $display . '</a>' . $r['link_after']; 
  2529.  
  2530. return apply_filters( 'bbp_get_topic_close_link', $retval, $r ); 
  2531.  
  2532. /** 
  2533. * Output the stick link of the topic 
  2534. * 
  2535. * @since bbPress (r2754) 
  2536. * 
  2537. * @param mixed $args See {@link bbp_get_topic_stick_link()} 
  2538. * @uses bbp_get_topic_stick_link() To get the topic stick link 
  2539. */ 
  2540. function bbp_topic_stick_link( $args = '' ) { 
  2541. echo bbp_get_topic_stick_link( $args ); 
  2542.  
  2543. /** 
  2544. * Return the stick link of the topic 
  2545. * 
  2546. * @since bbPress (r2754) 
  2547. * 
  2548. * @param mixed $args This function supports these args: 
  2549. * - id: Optional. Topic id 
  2550. * - link_before: Before the link 
  2551. * - link_after: After the link 
  2552. * - stick_text: Stick text 
  2553. * - unstick_text: Unstick text 
  2554. * - super_text: Stick to front text 
  2555. * @uses bbp_get_topic_id() To get the topic id 
  2556. * @uses bbp_get_topic() To get the topic 
  2557. * @uses current_user_can() To check if the current user can edit the 
  2558. * topic 
  2559. * @uses bbp_is_topic_sticky() To check if the topic is a sticky 
  2560. * @uses add_query_arg() To add custom args to the url 
  2561. * @uses wp_nonce_url() To nonce the url 
  2562. * @uses esc_url() To escape the url 
  2563. * @uses apply_filters() Calls 'bbp_get_topic_stick_link' with the link 
  2564. * and args 
  2565. * @return string Topic stick link 
  2566. */ 
  2567. function bbp_get_topic_stick_link( $args = '' ) { 
  2568.  
  2569. // Parse arguments against default values 
  2570. $r = bbp_parse_args( $args, array( 
  2571. 'id' => 0,  
  2572. 'link_before' => '',  
  2573. 'link_after' => '',  
  2574. 'stick_text' => esc_html__( 'Stick', 'bbpress' ),  
  2575. 'unstick_text' => esc_html__( 'Unstick', 'bbpress' ),  
  2576. 'super_text' => esc_html__( '(to front)', 'bbpress' ),  
  2577. ), 'get_topic_stick_link' ); 
  2578.  
  2579. $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); 
  2580.  
  2581. if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) ) 
  2582. return; 
  2583.  
  2584. $is_sticky = bbp_is_topic_sticky( $topic->ID ); 
  2585.  
  2586. $stick_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID ) ); 
  2587. $stick_uri = wp_nonce_url( $stick_uri, 'stick-topic_' . $topic->ID ); 
  2588.  
  2589. $stick_display = ( true === $is_sticky ) ? $r['unstick_text'] : $r['stick_text']; 
  2590. $stick_display = '<a href="' . esc_url( $stick_uri ) . '" class="bbp-topic-sticky-link">' . $stick_display . '</a>'; 
  2591.  
  2592. if ( empty( $is_sticky ) ) { 
  2593. $super_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID, 'super' => 1 ) ); 
  2594. $super_uri = wp_nonce_url( $super_uri, 'stick-topic_' . $topic->ID ); 
  2595.  
  2596. $super_display = ' <a href="' . esc_url( $super_uri ) . '" class="bbp-topic-super-sticky-link">' . $r['super_text'] . '</a>'; 
  2597. } else { 
  2598. $super_display = ''; 
  2599.  
  2600. // Combine the HTML into 1 string 
  2601. $retval = $r['link_before'] . $stick_display . $super_display . $r['link_after']; 
  2602.  
  2603. return apply_filters( 'bbp_get_topic_stick_link', $retval, $r ); 
  2604.  
  2605. /** 
  2606. * Output the merge link of the topic 
  2607. * 
  2608. * @since bbPress (r2756) 
  2609. * 
  2610. * @param mixed $args 
  2611. * @uses bbp_get_topic_merge_link() To get the topic merge link 
  2612. */ 
  2613. function bbp_topic_merge_link( $args = '' ) { 
  2614. echo bbp_get_topic_merge_link( $args ); 
  2615.  
  2616. /** 
  2617. * Return the merge link of the topic 
  2618. * 
  2619. * @since bbPress (r2756) 
  2620. * 
  2621. * @param mixed $args This function supports these args: 
  2622. * - id: Optional. Topic id 
  2623. * - link_before: Before the link 
  2624. * - link_after: After the link 
  2625. * - merge_text: Merge text 
  2626. * @uses bbp_get_topic_id() To get the topic id 
  2627. * @uses bbp_get_topic() To get the topic 
  2628. * @uses bbp_get_topic_edit_url() To get the topic edit url 
  2629. * @uses add_query_arg() To add custom args to the url 
  2630. * @uses esc_url() To escape the url 
  2631. * @uses apply_filters() Calls 'bbp_get_topic_merge_link' with the link 
  2632. * and args 
  2633. * @return string Topic merge link 
  2634. */ 
  2635. function bbp_get_topic_merge_link( $args = '' ) { 
  2636.  
  2637. // Parse arguments against default values 
  2638. $r = bbp_parse_args( $args, array( 
  2639. 'id' => 0,  
  2640. 'link_before' => '',  
  2641. 'link_after' => '',  
  2642. 'merge_text' => esc_html__( 'Merge', 'bbpress' ),  
  2643. ), 'get_topic_merge_link' ); 
  2644.  
  2645. $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); 
  2646.  
  2647. if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) ) 
  2648. return; 
  2649.  
  2650. $uri = add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->ID ) ); 
  2651. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-topic-merge-link">' . $r['merge_text'] . '</a>' . $r['link_after']; 
  2652.  
  2653. return apply_filters( 'bbp_get_topic_merge_link', $retval, $args ); 
  2654.  
  2655. /** 
  2656. * Output the spam link of the topic 
  2657. * 
  2658. * @since bbPress (r2727) 
  2659. * 
  2660. * @param mixed $args See {@link bbp_get_topic_spam_link()} 
  2661. * @uses bbp_get_topic_spam_link() Topic spam link 
  2662. */ 
  2663. function bbp_topic_spam_link( $args = '' ) { 
  2664. echo bbp_get_topic_spam_link( $args ); 
  2665.  
  2666. /** 
  2667. * Return the spam link of the topic 
  2668. * 
  2669. * @since bbPress (r2727) 
  2670. * 
  2671. * @param mixed $args This function supports these args: 
  2672. * - id: Optional. Topic id 
  2673. * - link_before: Before the link 
  2674. * - link_after: After the link 
  2675. * - spam_text: Spam text 
  2676. * - unspam_text: Unspam text 
  2677. * @uses bbp_get_topic_id() To get the topic id 
  2678. * @uses bbp_get_topic() To get the topic 
  2679. * @uses current_user_can() To check if the current user can edit the topic 
  2680. * @uses bbp_is_topic_spam() To check if the topic is marked as spam 
  2681. * @uses add_query_arg() To add custom args to the url 
  2682. * @uses wp_nonce_url() To nonce the url 
  2683. * @uses esc_url() To escape the url 
  2684. * @uses apply_filters() Calls 'bbp_get_topic_spam_link' with the link 
  2685. * and args 
  2686. * @return string Topic spam link 
  2687. */ 
  2688. function bbp_get_topic_spam_link( $args = '' ) { 
  2689.  
  2690. // Parse arguments against default values 
  2691. $r = bbp_parse_args( $args, array( 
  2692. 'id' => 0,  
  2693. 'link_before' => '',  
  2694. 'link_after' => '',  
  2695. 'sep' => ' | ',  
  2696. 'spam_text' => esc_html__( 'Spam', 'bbpress' ),  
  2697. 'unspam_text' => esc_html__( 'Unspam', 'bbpress' ) 
  2698. ), 'get_topic_spam_link' ); 
  2699.  
  2700. $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); 
  2701.  
  2702. if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) ) 
  2703. return; 
  2704.  
  2705. $display = bbp_is_topic_spam( $topic->ID ) ? $r['unspam_text'] : $r['spam_text']; 
  2706. $uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_spam', 'topic_id' => $topic->ID ) ); 
  2707. $uri = wp_nonce_url( $uri, 'spam-topic_' . $topic->ID ); 
  2708. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-topic-spam-link">' . $display . '</a>' . $r['link_after']; 
  2709.  
  2710. return apply_filters( 'bbp_get_topic_spam_link', $retval, $r ); 
  2711.  
  2712. /** 
  2713. * Output the link to go directly to the reply form 
  2714. * 
  2715. * @since bbPress (r4966) 
  2716. * 
  2717. * @param array $args 
  2718. * @uses bbp_get_reply_to_link() To get the reply to link 
  2719. */ 
  2720. function bbp_topic_reply_link( $args = array() ) { 
  2721. echo bbp_get_topic_reply_link( $args ); 
  2722.  
  2723. /** 
  2724. * Return the link to go directly to the reply form 
  2725. * 
  2726. * @since bbPress (r4966) 
  2727. * 
  2728. * @param array $args Arguments 
  2729. * @uses bbp_current_user_can_access_create_reply_form() To check permissions 
  2730. * @uses bbp_get_topic_id() To validate the topic id 
  2731. * @uses bbp_get_topic() To get the topic 
  2732. * @uses apply_filters() Calls 'bbp_get_topic_reply_link' with the formatted link,  
  2733. * the arguments array, and the topic 
  2734. * @return string Link for a reply to a topic 
  2735. */ 
  2736. function bbp_get_topic_reply_link( $args = array() ) { 
  2737.  
  2738. // Parse arguments against default values 
  2739. $r = bbp_parse_args( $args, array( 
  2740. 'id' => 0,  
  2741. 'link_before' => '',  
  2742. 'link_after' => '',  
  2743. 'reply_text' => esc_html__( 'Reply', 'bbpress' ),  
  2744. ), 'get_topic_reply_link' ); 
  2745.  
  2746. // Get the reply to use it's ID and post_parent 
  2747. $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) ); 
  2748.  
  2749. // Bail if no reply or user cannot reply 
  2750. if ( empty( $topic ) || ! bbp_current_user_can_access_create_reply_form() ) 
  2751. return; 
  2752.  
  2753. $uri = '#new-post'; 
  2754.  
  2755. // Add $uri to the array, to be passed through the filter 
  2756. $r['uri'] = $uri; 
  2757. $retval = $r['link_before'] . '<a href="' . esc_url( $r['uri'] ) . '" class="bbp-topic-reply-link">' . $r['reply_text'] . '</a>' . $r['link_after']; 
  2758.  
  2759. return apply_filters( 'bbp_get_topic_reply_link', $retval, $r, $args ); 
  2760.  
  2761. /** Topic Pagination **********************************************************/ 
  2762.  
  2763. /** 
  2764. * Output the pagination count 
  2765. * 
  2766. * @since bbPress (r2519) 
  2767. * 
  2768. * @uses bbp_get_forum_pagination_count() To get the forum pagination count 
  2769. */ 
  2770. function bbp_forum_pagination_count() { 
  2771. echo bbp_get_forum_pagination_count(); 
  2772. /** 
  2773. * Return the pagination count 
  2774. * 
  2775. * @since bbPress (r2519) 
  2776. * 
  2777. * @uses bbp_number_format() To format the number value 
  2778. * @uses apply_filters() Calls 'bbp_get_forum_pagination_count' with the 
  2779. * pagination count 
  2780. * @return string Forum Pagintion count 
  2781. */ 
  2782. function bbp_get_forum_pagination_count() { 
  2783. $bbp = bbpress(); 
  2784.  
  2785. if ( empty( $bbp->topic_query ) ) 
  2786. return false; 
  2787.  
  2788. // Set pagination values 
  2789. $start_num = intval( ( $bbp->topic_query->paged - 1 ) * $bbp->topic_query->posts_per_page ) + 1; 
  2790. $from_num = bbp_number_format( $start_num ); 
  2791. $to_num = bbp_number_format( ( $start_num + ( $bbp->topic_query->posts_per_page - 1 ) > $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $start_num + ( $bbp->topic_query->posts_per_page - 1 ) ); 
  2792. $total_int = (int) !empty( $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $bbp->topic_query->post_count; 
  2793. $total = bbp_number_format( $total_int ); 
  2794.  
  2795. // Several topics in a forum with a single page 
  2796. if ( empty( $to_num ) ) { 
  2797. $retstr = sprintf( _n( 'Viewing %1$s topic', 'Viewing %1$s topics', $total_int, 'bbpress' ), $total ); 
  2798.  
  2799. // Several topics in a forum with several pages 
  2800. } else { 
  2801. $retstr = sprintf( _n( 'Viewing topic %2$s (of %4$s total)', 'Viewing %1$s topics - %2$s through %3$s (of %4$s total)', $total_int, 'bbpress' ), $bbp->topic_query->post_count, $from_num, $to_num, $total ); 
  2802.  
  2803. // Filter and return 
  2804. return apply_filters( 'bbp_get_forum_pagination_count', esc_html( $retstr ) ); 
  2805.  
  2806. /** 
  2807. * Output pagination links 
  2808. * 
  2809. * @since bbPress (r2519) 
  2810. * 
  2811. * @uses bbp_get_forum_pagination_links() To get the pagination links 
  2812. */ 
  2813. function bbp_forum_pagination_links() { 
  2814. echo bbp_get_forum_pagination_links(); 
  2815. /** 
  2816. * Return pagination links 
  2817. * 
  2818. * @since bbPress (r2519) 
  2819. * 
  2820. * @uses bbPress::topic_query::pagination_links To get the links 
  2821. * @return string Pagination links 
  2822. */ 
  2823. function bbp_get_forum_pagination_links() { 
  2824. $bbp = bbpress(); 
  2825.  
  2826. if ( empty( $bbp->topic_query ) ) 
  2827. return false; 
  2828.  
  2829. return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links ); 
  2830.  
  2831. /** 
  2832. * Displays topic notices 
  2833. * 
  2834. * @since bbPress (r2744) 
  2835. * 
  2836. * @uses bbp_is_single_topic() To check if it's a topic page 
  2837. * @uses bbp_get_topic_status() To get the topic status 
  2838. * @uses bbp_get_topic_id() To get the topic id 
  2839. * @uses apply_filters() Calls 'bbp_topic_notices' with the notice text, topic 
  2840. * status and topic id 
  2841. * @uses bbp_add_error() To add an error message 
  2842. */ 
  2843. function bbp_topic_notices() { 
  2844.  
  2845. // Bail if not viewing a topic 
  2846. if ( !bbp_is_single_topic() ) 
  2847. return; 
  2848.  
  2849. // Get the topic_status 
  2850. $topic_status = bbp_get_topic_status(); 
  2851.  
  2852. // Get the topic status 
  2853. switch ( $topic_status ) { 
  2854.  
  2855. // Spam notice 
  2856. case bbp_get_spam_status_id() : 
  2857. $notice_text = __( 'This topic is marked as spam.', 'bbpress' ); 
  2858. break; 
  2859.  
  2860. // Trashed notice 
  2861. case bbp_get_trash_status_id() : 
  2862. $notice_text = __( 'This topic is in the trash.', 'bbpress' ); 
  2863. break; 
  2864.  
  2865. // Standard status 
  2866. default : 
  2867. $notice_text = ''; 
  2868. break; 
  2869.  
  2870. // Filter notice text and bail if empty 
  2871. $notice_text = apply_filters( 'bbp_topic_notices', $notice_text, $topic_status, bbp_get_topic_id() ); 
  2872. if ( empty( $notice_text ) ) 
  2873. return; 
  2874.  
  2875. bbp_add_error( 'topic_notice', $notice_text, 'message' ); 
  2876.  
  2877. /** 
  2878. * Displays topic type select box (normal/sticky/super sticky) 
  2879. * 
  2880. * @since bbPress (r5059) 
  2881. * @deprecated since bbPress (r5059) 
  2882. * 
  2883. * @param $args This function supports these arguments: 
  2884. * - select_id: Select id. Defaults to bbp_stick_topic 
  2885. * - tab: Tabindex 
  2886. * - topic_id: Topic id 
  2887. * - selected: Override the selected option 
  2888. */ 
  2889. function bbp_topic_type_select( $args = '' ) { 
  2890. echo bbp_get_form_topic_type_dropdown( $args ); 
  2891.  
  2892. /** 
  2893. * Displays topic type select box (normal/sticky/super sticky) 
  2894. * 
  2895. * @since bbPress (r5059) 
  2896. * 
  2897. * @param $args This function supports these arguments: 
  2898. * - select_id: Select id. Defaults to bbp_stick_topic 
  2899. * - tab: Tabindex 
  2900. * - topic_id: Topic id 
  2901. * - selected: Override the selected option 
  2902. */ 
  2903. function bbp_form_topic_type_dropdown( $args = '' ) { 
  2904. echo bbp_get_form_topic_type_dropdown( $args ); 
  2905. /** 
  2906. * Returns topic type select box (normal/sticky/super sticky) 
  2907. * 
  2908. * @since bbPress (r5059) 
  2909. * 
  2910. * @param $args This function supports these arguments: 
  2911. * - select_id: Select id. Defaults to bbp_stick_topic 
  2912. * - tab: Tabindex 
  2913. * - topic_id: Topic id 
  2914. * - selected: Override the selected option 
  2915. * @uses bbp_get_topic_id() To get the topic id 
  2916. * @uses bbp_is_single_topic() To check if we're viewing a single topic 
  2917. * @uses bbp_is_topic_edit() To check if it is the topic edit page 
  2918. * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky 
  2919. * @uses bbp_is_topic_sticky() To check if the topic is a sticky 
  2920. */ 
  2921. function bbp_get_form_topic_type_dropdown( $args = '' ) { 
  2922.  
  2923. // Parse arguments against default values 
  2924. $r = bbp_parse_args( $args, array( 
  2925. 'select_id' => 'bbp_stick_topic',  
  2926. 'tab' => bbp_get_tab_index(),  
  2927. 'topic_id' => 0,  
  2928. 'selected' => false 
  2929. ), 'topic_type_select' ); 
  2930.  
  2931. // No specific selected value passed 
  2932. if ( empty( $r['selected'] ) ) { 
  2933.  
  2934. // Post value is passed 
  2935. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 
  2936. $r['selected'] = $_POST[ $r['select_id'] ]; 
  2937.  
  2938. // No Post value passed 
  2939. } else { 
  2940.  
  2941. // Edit topic 
  2942. if ( bbp_is_single_topic() || bbp_is_topic_edit() ) { 
  2943.  
  2944. // Get current topic id 
  2945. $topic_id = bbp_get_topic_id( $r['topic_id'] ); 
  2946.  
  2947. // Topic is super sticky 
  2948. if ( bbp_is_topic_super_sticky( $topic_id ) ) { 
  2949. $r['selected'] = 'super'; 
  2950.  
  2951. // Topic is sticky or normal 
  2952. } else { 
  2953. $r['selected'] = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick'; 
  2954.  
  2955. // Used variables 
  2956. $tab = !empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; 
  2957.  
  2958. // Start an output buffer, we'll finish it after the select loop 
  2959. ob_start(); ?> 
  2960.  
  2961. <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select"<?php echo $tab; ?>> 
  2962.  
  2963. <?php foreach ( bbp_get_topic_types() as $key => $label ) : ?> 
  2964.  
  2965. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 
  2966.  
  2967. <?php endforeach; ?> 
  2968.  
  2969. </select> 
  2970.  
  2971. <?php 
  2972.  
  2973. // Return the results 
  2974. return apply_filters( 'bbp_get_form_topic_type_dropdown', ob_get_clean(), $r ); 
  2975.  
  2976. /** 
  2977. * Output value topic status dropdown 
  2978. * 
  2979. * @since bbPress (r5059) 
  2980. * 
  2981. * @param int $topic_id The topic id to use 
  2982. */ 
  2983. function bbp_form_topic_status_dropdown( $args = '' ) { 
  2984. echo bbp_get_form_topic_status_dropdown( $args ); 
  2985. /** 
  2986. * Returns topic status downdown 
  2987. * 
  2988. * This dropdown is only intended to be seen by users with the 'moderate' 
  2989. * capability. Because of this, no additional capablitiy checks are performed 
  2990. * within this function to check available topic statuses. 
  2991. * 
  2992. * @since bbPress (r5059) 
  2993. * 
  2994. * @param $args This function supports these arguments: 
  2995. * - select_id: Select id. Defaults to bbp_open_close_topic 
  2996. * - tab: Tabindex 
  2997. * - topic_id: Topic id 
  2998. * - selected: Override the selected option 
  2999. */ 
  3000. function bbp_get_form_topic_status_dropdown( $args = '' ) { 
  3001.  
  3002. // Parse arguments against default values 
  3003. $r = bbp_parse_args( $args, array( 
  3004. 'select_id' => 'bbp_topic_status',  
  3005. 'tab' => bbp_get_tab_index(),  
  3006. 'topic_id' => 0,  
  3007. 'selected' => false 
  3008. ), 'topic_open_close_select' ); 
  3009.  
  3010. // No specific selected value passed 
  3011. if ( empty( $r['selected'] ) ) { 
  3012.  
  3013. // Post value is passed 
  3014. if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 
  3015. $r['selected'] = $_POST[ $r['select_id'] ]; 
  3016.  
  3017. // No Post value was passed 
  3018. } else { 
  3019.  
  3020. // Edit topic 
  3021. if ( bbp_is_topic_edit() ) { 
  3022. $r['topic_id'] = bbp_get_topic_id( $r['topic_id'] ); 
  3023. $r['selected'] = bbp_get_topic_status( $r['topic_id'] ); 
  3024.  
  3025. // New topic 
  3026. } else { 
  3027. $r['selected'] = bbp_get_public_status_id(); 
  3028.  
  3029. // Used variables 
  3030. $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; 
  3031.  
  3032. // Start an output buffer, we'll finish it after the select loop 
  3033. ob_start(); ?> 
  3034.  
  3035. <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select"<?php echo $tab; ?>> 
  3036.  
  3037. <?php foreach ( bbp_get_topic_statuses( $r['topic_id'] ) as $key => $label ) : ?> 
  3038.  
  3039. <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 
  3040.  
  3041. <?php endforeach; ?> 
  3042.  
  3043. </select> 
  3044.  
  3045. <?php 
  3046.  
  3047. // Return the results 
  3048. return apply_filters( 'bbp_get_form_topic_status_dropdown', ob_get_clean(), $r ); 
  3049.  
  3050. /** Single Topic **************************************************************/ 
  3051.  
  3052. /** 
  3053. * Output a fancy description of the current topic, including total topics,  
  3054. * total replies, and last activity. 
  3055. * 
  3056. * @since bbPress (r2860) 
  3057. * 
  3058. * @param array $args See {@link bbp_get_single_topic_description()} 
  3059. * @uses bbp_get_single_topic_description() Return the eventual output 
  3060. */ 
  3061. function bbp_single_topic_description( $args = '' ) { 
  3062. echo bbp_get_single_topic_description( $args ); 
  3063. /** 
  3064. * Return a fancy description of the current topic, including total topics,  
  3065. * total replies, and last activity. 
  3066. * 
  3067. * @since bbPress (r2860) 
  3068. * 
  3069. * @param mixed $args This function supports these arguments: 
  3070. * - topic_id: Topic id 
  3071. * - before: Before the text 
  3072. * - after: After the text 
  3073. * - size: Size of the avatar 
  3074. * @uses bbp_get_topic_id() To get the topic id 
  3075. * @uses bbp_get_topic_voice_count() To get the topic voice count 
  3076. * @uses bbp_get_topic_reply_count() To get the topic reply count 
  3077. * @uses bbp_get_topic_freshness_link() To get the topic freshness link 
  3078. * @uses bbp_get_topic_last_active_id() To get the topic last active id 
  3079. * @uses bbp_get_reply_author_link() To get the reply author link 
  3080. * @uses apply_filters() Calls 'bbp_get_single_topic_description' with 
  3081. * the description and args 
  3082. * @return string Filtered topic description 
  3083. */ 
  3084. function bbp_get_single_topic_description( $args = '' ) { 
  3085.  
  3086. // Parse arguments against default values 
  3087. $r = bbp_parse_args( $args, array( 
  3088. 'topic_id' => 0,  
  3089. 'before' => '<div class="bbp-template-notice info"><p class="bbp-topic-description">',  
  3090. 'after' => '</p></div>',  
  3091. 'size' => 14 
  3092. ), 'get_single_topic_description' ); 
  3093.  
  3094. // Validate topic_id 
  3095. $topic_id = bbp_get_topic_id( $r['topic_id'] ); 
  3096.  
  3097. // Unhook the 'view all' query var adder 
  3098. remove_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' ); 
  3099.  
  3100. // Build the topic description 
  3101. $vc_int = bbp_get_topic_voice_count ( $topic_id, true ); 
  3102. $voice_count = bbp_get_topic_voice_count ( $topic_id, false ); 
  3103. $reply_count = bbp_get_topic_replies_link ( $topic_id ); 
  3104. $time_since = bbp_get_topic_freshness_link( $topic_id ); 
  3105.  
  3106. // Singular/Plural 
  3107. $voice_count = sprintf( _n( '%s voice', '%s voices', $vc_int, 'bbpress' ), $voice_count ); 
  3108.  
  3109. // Topic has replies 
  3110. $last_reply = bbp_get_topic_last_reply_id( $topic_id ); 
  3111. if ( !empty( $last_reply ) ) { 
  3112. $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $r['size'] ) ); 
  3113. $retstr = sprintf( esc_html__( 'This topic contains %1$s, has %2$s, and was last updated by %3$s %4$s.', 'bbpress' ), $reply_count, $voice_count, $last_updated_by, $time_since ); 
  3114.  
  3115. // Topic has no replies 
  3116. } elseif ( ! empty( $voice_count ) && ! empty( $reply_count ) ) { 
  3117. $retstr = sprintf( esc_html__( 'This topic contains %1$s and has %2$s.', 'bbpress' ), $voice_count, $reply_count ); 
  3118.  
  3119. // Topic has no replies and no voices 
  3120. } elseif ( empty( $voice_count ) && empty( $reply_count ) ) { 
  3121. $retstr = sprintf( esc_html__( 'This topic has no replies.', 'bbpress' ), $voice_count, $reply_count ); 
  3122.  
  3123. // Add the 'view all' filter back 
  3124. add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' ); 
  3125.  
  3126. // Combine the elements together 
  3127. $retstr = $r['before'] . $retstr . $r['after']; 
  3128.  
  3129. // Return filtered result 
  3130. return apply_filters( 'bbp_get_single_topic_description', $retstr, $r ); 
  3131.  
  3132. /** Topic Tags ****************************************************************/ 
  3133.  
  3134. /** 
  3135. * Output the unique id of the topic tag taxonomy 
  3136. * 
  3137. * @since bbPress (r3348) 
  3138. * 
  3139. * @uses bbp_get_topic_post_type() To get the topic post type 
  3140. */ 
  3141. function bbp_topic_tag_tax_id() { 
  3142. echo bbp_get_topic_tag_tax_id(); 
  3143. /** 
  3144. * Return the unique id of the topic tag taxonomy 
  3145. * 
  3146. * @since bbPress (r3348) 
  3147. * 
  3148. * @uses apply_filters() Calls 'bbp_get_topic_tag_tax_id' with the topic tax id 
  3149. * @return string The unique topic tag taxonomy 
  3150. */ 
  3151. function bbp_get_topic_tag_tax_id() { 
  3152. return apply_filters( 'bbp_get_topic_tag_tax_id', bbpress()->topic_tag_tax_id ); 
  3153.  
  3154. /** 
  3155. * Return array of labels used by the topic-tag taxonomy 
  3156. * 
  3157. * @since bbPress (r5129) 
  3158. * 
  3159. * @return array 
  3160. */ 
  3161. function bbp_get_topic_tag_tax_labels() { 
  3162. return apply_filters( 'bbp_get_topic_tag_tax_labels', array( 
  3163. 'name' => __( 'Topic Tags', 'bbpress' ),  
  3164. 'singular_name' => __( 'Topic Tag', 'bbpress' ),  
  3165. 'search_items' => __( 'Search Tags', 'bbpress' ),  
  3166. 'popular_items' => __( 'Popular Tags', 'bbpress' ),  
  3167. 'all_items' => __( 'All Tags', 'bbpress' ),  
  3168. 'edit_item' => __( 'Edit Tag', 'bbpress' ),  
  3169. 'update_item' => __( 'Update Tag', 'bbpress' ),  
  3170. 'add_new_item' => __( 'Add New Tag', 'bbpress' ),  
  3171. 'new_item_name' => __( 'New Tag Name', 'bbpress' ),  
  3172. 'view_item' => __( 'View Topic Tag', 'bbpress' ) 
  3173. ) ); 
  3174.  
  3175. /** 
  3176. * Return an array of topic-tag taxonomy rewrite settings 
  3177. * 
  3178. * @since bbPress (r5129) 
  3179. * 
  3180. * @return array 
  3181. */ 
  3182. function bbp_get_topic_tag_tax_rewrite() { 
  3183. return apply_filters( 'bbp_get_topic_tag_tax_rewrite', array( 
  3184. 'slug' => bbp_get_topic_tag_tax_slug(),  
  3185. 'with_front' => false 
  3186. ) ); 
  3187.  
  3188. /** 
  3189. * Output the id of the current tag 
  3190. * 
  3191. * @since bbPress (r3109) 
  3192. * 
  3193. * @uses bbp_get_topic_tag_id() 
  3194. */ 
  3195. function bbp_topic_tag_id( $tag = '' ) { 
  3196. echo bbp_get_topic_tag_id( $tag ); 
  3197. /** 
  3198. * Return the id of the current tag 
  3199. * 
  3200. * @since bbPress (r3109) 
  3201. * 
  3202. * @uses get_term_by() 
  3203. * @uses get_queried_object() 
  3204. * @uses get_query_var() 
  3205. * @uses apply_filters() 
  3206. * 
  3207. * @return string Term Name 
  3208. */ 
  3209. function bbp_get_topic_tag_id( $tag = '' ) { 
  3210.  
  3211. // Get the term 
  3212. if ( ! empty( $tag ) ) { 
  3213. $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() ); 
  3214. } else { 
  3215. $tag = get_query_var( 'term' ); 
  3216. $term = get_queried_object(); 
  3217.  
  3218. // Add before and after if description exists 
  3219. if ( !empty( $term->term_id ) ) { 
  3220. $retval = $term->term_id; 
  3221.  
  3222. // No id 
  3223. } else { 
  3224. $retval = ''; 
  3225.  
  3226. return (int) apply_filters( 'bbp_get_topic_tag_id', (int) $retval, $tag ); 
  3227.  
  3228. /** 
  3229. * Output the name of the current tag 
  3230. * 
  3231. * @since bbPress (r3109) 
  3232. * 
  3233. * @uses bbp_get_topic_tag_name() 
  3234. */ 
  3235. function bbp_topic_tag_name( $tag = '' ) { 
  3236. echo bbp_get_topic_tag_name( $tag ); 
  3237. /** 
  3238. * Return the name of the current tag 
  3239. * 
  3240. * @since bbPress (r3109) 
  3241. * 
  3242. * @uses get_term_by() 
  3243. * @uses get_queried_object() 
  3244. * @uses get_query_var() 
  3245. * @uses apply_filters() 
  3246. * 
  3247. * @return string Term Name 
  3248. */ 
  3249. function bbp_get_topic_tag_name( $tag = '' ) { 
  3250.  
  3251. // Get the term 
  3252. if ( ! empty( $tag ) ) { 
  3253. $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() ); 
  3254. } else { 
  3255. $tag = get_query_var( 'term' ); 
  3256. $term = get_queried_object(); 
  3257.  
  3258. // Add before and after if description exists 
  3259. if ( !empty( $term->name ) ) { 
  3260. $retval = $term->name; 
  3261.  
  3262. // No name 
  3263. } else { 
  3264. $retval = ''; 
  3265.  
  3266. return apply_filters( 'bbp_get_topic_tag_name', $retval ); 
  3267.  
  3268. /** 
  3269. * Output the slug of the current tag 
  3270. * 
  3271. * @since bbPress (r3109) 
  3272. * 
  3273. * @uses bbp_get_topic_tag_slug() 
  3274. */ 
  3275. function bbp_topic_tag_slug( $tag = '' ) { 
  3276. echo bbp_get_topic_tag_slug( $tag ); 
  3277. /** 
  3278. * Return the slug of the current tag 
  3279. * 
  3280. * @since bbPress (r3109) 
  3281. * 
  3282. * @uses get_term_by() 
  3283. * @uses get_queried_object() 
  3284. * @uses get_query_var() 
  3285. * @uses apply_filters() 
  3286. * 
  3287. * @return string Term Name 
  3288. */ 
  3289. function bbp_get_topic_tag_slug( $tag = '' ) { 
  3290.  
  3291. // Get the term 
  3292. if ( ! empty( $tag ) ) { 
  3293. $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() ); 
  3294. } else { 
  3295. $tag = get_query_var( 'term' ); 
  3296. $term = get_queried_object(); 
  3297.  
  3298. // Add before and after if description exists 
  3299. if ( !empty( $term->slug ) ) { 
  3300. $retval = $term->slug; 
  3301.  
  3302. // No slug 
  3303. } else { 
  3304. $retval = ''; 
  3305.  
  3306. return apply_filters( 'bbp_get_topic_tag_slug', $retval ); 
  3307.  
  3308. /** 
  3309. * Output the link of the current tag 
  3310. * 
  3311. * @since bbPress (r3348) 
  3312. * 
  3313. * @uses bbp_get_topic_tag_link() 
  3314. */ 
  3315. function bbp_topic_tag_link( $tag = '' ) { 
  3316. echo esc_url( bbp_get_topic_tag_link( $tag ) ); 
  3317. /** 
  3318. * Return the link of the current tag 
  3319. * 
  3320. * @since bbPress (r3348) 
  3321. * 
  3322. * @uses get_term_by() 
  3323. * @uses get_queried_object() 
  3324. * @uses get_query_var() 
  3325. * @uses apply_filters() 
  3326. * 
  3327. * @return string Term Name 
  3328. */ 
  3329. function bbp_get_topic_tag_link( $tag = '' ) { 
  3330.  
  3331. // Get the term 
  3332. if ( ! empty( $tag ) ) { 
  3333. $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() ); 
  3334. } else { 
  3335. $tag = get_query_var( 'term' ); 
  3336. $term = get_queried_object(); 
  3337.  
  3338. // Add before and after if description exists 
  3339. if ( !empty( $term->term_id ) ) { 
  3340. $retval = get_term_link( $term, bbp_get_topic_tag_tax_id() ); 
  3341.  
  3342. // No link 
  3343. } else { 
  3344. $retval = ''; 
  3345.  
  3346. return apply_filters( 'bbp_get_topic_tag_link', $retval, $tag ); 
  3347.  
  3348. /** 
  3349. * Output the link of the current tag 
  3350. * 
  3351. * @since bbPress (r3348) 
  3352. * 
  3353. * @uses bbp_get_topic_tag_edit_link() 
  3354. */ 
  3355. function bbp_topic_tag_edit_link( $tag = '' ) { 
  3356. echo esc_url( bbp_get_topic_tag_edit_link( $tag ) ); 
  3357. /** 
  3358. * Return the link of the current tag 
  3359. * 
  3360. * @since bbPress (r3348) 
  3361. * 
  3362. * @uses get_term_by() 
  3363. * @uses get_queried_object() 
  3364. * @uses get_query_var() 
  3365. * @uses apply_filters() 
  3366. * 
  3367. * @return string Term Name 
  3368. */ 
  3369. function bbp_get_topic_tag_edit_link( $tag = '' ) { 
  3370. global $wp_rewrite; 
  3371.  
  3372. // Get the term 
  3373. if ( ! empty( $tag ) ) { 
  3374. $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() ); 
  3375. } else { 
  3376. $tag = get_query_var( 'term' ); 
  3377. $term = get_queried_object(); 
  3378.  
  3379. // Add before and after if description exists 
  3380. if ( !empty( $term->term_id ) ) { 
  3381.  
  3382. $bbp = bbpress(); 
  3383.  
  3384. // Pretty 
  3385. if ( $wp_rewrite->using_permalinks() ) { 
  3386. $retval = user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . $bbp->edit_id ); 
  3387.  
  3388. // Ugly 
  3389. } else { 
  3390. $retval = add_query_arg( array( $bbp->edit_id => '1' ), bbp_get_topic_tag_link() ); 
  3391.  
  3392. // No link 
  3393. } else { 
  3394. $retval = ''; 
  3395.  
  3396. return apply_filters( 'bbp_get_topic_tag_edit_link', $retval, $tag ); 
  3397.  
  3398. /** 
  3399. * Output the description of the current tag 
  3400. * 
  3401. * @since bbPress (r3109) 
  3402. * 
  3403. * @uses bbp_get_topic_tag_description() 
  3404. */ 
  3405. function bbp_topic_tag_description( $args = array() ) { 
  3406. echo bbp_get_topic_tag_description( $args ); 
  3407. /** 
  3408. * Return the description of the current tag 
  3409. * 
  3410. * @since bbPress (r3109) 
  3411. * 
  3412. * @uses get_term_by() 
  3413. * @uses get_queried_object() 
  3414. * @uses get_query_var() 
  3415. * @uses apply_filters() 
  3416. * @param array $args before|after|tag 
  3417. * 
  3418. * @return string Term Name 
  3419. */ 
  3420. function bbp_get_topic_tag_description( $args = array() ) { 
  3421.  
  3422. // Parse arguments against default values 
  3423. $r = bbp_parse_args( $args, array( 
  3424. 'before' => '<div class="bbp-topic-tag-description"><p>',  
  3425. 'after' => '</p></div>',  
  3426. 'tag' => '' 
  3427. ), 'get_topic_tag_description' ); 
  3428.  
  3429. // Get the term 
  3430. if ( ! empty( $r['tag'] ) ) { 
  3431. $term = get_term_by( 'slug', $r['tag'], bbp_get_topic_tag_tax_id() ); 
  3432. } else { 
  3433. $tag = get_query_var( 'term' ); 
  3434. $r['tag'] = $tag; 
  3435. $term = get_queried_object(); 
  3436.  
  3437. // Add before and after if description exists 
  3438. if ( !empty( $term->description ) ) { 
  3439. $retval = $r['before'] . $term->description . $r['after']; 
  3440.  
  3441. // No description, no HTML 
  3442. } else { 
  3443. $retval = ''; 
  3444.  
  3445. return apply_filters( 'bbp_get_topic_tag_description', $retval, $r ); 
  3446.  
  3447. /** Forms *********************************************************************/ 
  3448.  
  3449. /** 
  3450. * Output the value of topic title field 
  3451. * 
  3452. * @since bbPress (r2976) 
  3453. * 
  3454. * @uses bbp_get_form_topic_title() To get the value of topic title field 
  3455. */ 
  3456. function bbp_form_topic_title() { 
  3457. echo bbp_get_form_topic_title(); 
  3458. /** 
  3459. * Return the value of topic title field 
  3460. * 
  3461. * @since bbPress (r2976) 
  3462. * 
  3463. * @uses bbp_is_topic_edit() To check if it's topic edit page 
  3464. * @uses apply_filters() Calls 'bbp_get_form_topic_title' with the title 
  3465. * @return string Value of topic title field 
  3466. */ 
  3467. function bbp_get_form_topic_title() { 
  3468.  
  3469. // Get _POST data 
  3470. if ( bbp_is_post_request() && isset( $_POST['bbp_topic_title'] ) ) { 
  3471. $topic_title = $_POST['bbp_topic_title']; 
  3472.  
  3473. // Get edit data 
  3474. } elseif ( bbp_is_topic_edit() ) { 
  3475. $topic_title = bbp_get_global_post_field( 'post_title', 'raw' ); 
  3476.  
  3477. // No data 
  3478. } else { 
  3479. $topic_title = ''; 
  3480.  
  3481. return apply_filters( 'bbp_get_form_topic_title', esc_attr( $topic_title ) ); 
  3482.  
  3483. /** 
  3484. * Output the value of topic content field 
  3485. * 
  3486. * @since bbPress (r2976) 
  3487. * 
  3488. * @uses bbp_get_form_topic_content() To get value of topic content field 
  3489. */ 
  3490. function bbp_form_topic_content() { 
  3491. echo bbp_get_form_topic_content(); 
  3492. /** 
  3493. * Return the value of topic content field 
  3494. * 
  3495. * @since bbPress (r2976) 
  3496. * 
  3497. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  3498. * @uses apply_filters() Calls 'bbp_get_form_topic_content' with the content 
  3499. * @return string Value of topic content field 
  3500. */ 
  3501. function bbp_get_form_topic_content() { 
  3502.  
  3503. // Get _POST data 
  3504. if ( bbp_is_post_request() && isset( $_POST['bbp_topic_content'] ) ) { 
  3505. $topic_content = stripslashes( $_POST['bbp_topic_content'] ); 
  3506.  
  3507. // Get edit data 
  3508. } elseif ( bbp_is_topic_edit() ) { 
  3509. $topic_content = bbp_get_global_post_field( 'post_content', 'raw' ); 
  3510.  
  3511. // No data 
  3512. } else { 
  3513. $topic_content = ''; 
  3514.  
  3515. return apply_filters( 'bbp_get_form_topic_content', $topic_content ); 
  3516.  
  3517. /** 
  3518. * Allow topic rows to have adminstrative actions 
  3519. * 
  3520. * @since bbPress (r3653) 
  3521. * @uses do_action() 
  3522. * @todo Links and filter 
  3523. */ 
  3524. function bbp_topic_row_actions() { 
  3525. do_action( 'bbp_topic_row_actions' ); 
  3526.  
  3527. /** 
  3528. * Output value of topic tags field 
  3529. * 
  3530. * @since bbPress (r2976) 
  3531. * @uses bbp_get_form_topic_tags() To get the value of topic tags field 
  3532. */ 
  3533. function bbp_form_topic_tags() { 
  3534. echo bbp_get_form_topic_tags(); 
  3535. /** 
  3536. * Return value of topic tags field 
  3537. * 
  3538. * @since bbPress (r2976) 
  3539. * 
  3540. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  3541. * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags 
  3542. * @return string Value of topic tags field 
  3543. */ 
  3544. function bbp_get_form_topic_tags() { 
  3545.  
  3546. // Get _POST data 
  3547. if ( bbp_is_post_request() && isset( $_POST['bbp_topic_tags'] ) ) { 
  3548. $topic_tags = $_POST['bbp_topic_tags']; 
  3549.  
  3550. // Get edit data 
  3551. } elseif ( bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit() ) { 
  3552.  
  3553. // Determine the topic id based on the post type 
  3554. switch ( get_post_type() ) { 
  3555.  
  3556. // Post is a topic 
  3557. case bbp_get_topic_post_type() : 
  3558. $topic_id = get_the_ID(); 
  3559. break; 
  3560.  
  3561. // Post is a reply 
  3562. case bbp_get_reply_post_type() : 
  3563. $topic_id = bbp_get_reply_topic_id( get_the_ID() ); 
  3564. break; 
  3565.  
  3566. // Topic exists 
  3567. if ( !empty( $topic_id ) ) { 
  3568.  
  3569. // Topic is spammed so display pre-spam terms 
  3570. if ( bbp_is_topic_spam( $topic_id ) ) { 
  3571.  
  3572. // Get pre-spam terms 
  3573. $new_terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true ); 
  3574.  
  3575. // If terms exist, explode them and compile the return value 
  3576. if ( empty( $new_terms ) ) { 
  3577. $new_terms = ''; 
  3578.  
  3579. // Topic is not spam so get real terms 
  3580. } else { 
  3581. $terms = array_filter( (array) get_the_terms( $topic_id, bbp_get_topic_tag_tax_id() ) ); 
  3582.  
  3583. // Loop through them 
  3584. foreach ( $terms as $term ) { 
  3585. $new_terms[] = $term->name; 
  3586.  
  3587. // Define local variable(s) 
  3588. } else { 
  3589. $new_terms = ''; 
  3590.  
  3591. // Set the return value 
  3592. $topic_tags = ( !empty( $new_terms ) ) ? implode( ', ', $new_terms ) : ''; 
  3593.  
  3594. // No data 
  3595. } else { 
  3596. $topic_tags = ''; 
  3597.  
  3598. return apply_filters( 'bbp_get_form_topic_tags', esc_attr( $topic_tags ) ); 
  3599.  
  3600. /** 
  3601. * Output value of topic forum 
  3602. * 
  3603. * @since bbPress (r2976) 
  3604. * 
  3605. * @uses bbp_get_form_topic_forum() To get the topic's forum id 
  3606. */ 
  3607. function bbp_form_topic_forum() { 
  3608. echo bbp_get_form_topic_forum(); 
  3609. /** 
  3610. * Return value of topic forum 
  3611. * 
  3612. * @since bbPress (r2976) 
  3613. * 
  3614. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  3615. * @uses bbp_get_topic_forum_id() To get the topic forum id 
  3616. * @uses apply_filters() Calls 'bbp_get_form_topic_forum' with the forum 
  3617. * @return string Value of topic content field 
  3618. */ 
  3619. function bbp_get_form_topic_forum() { 
  3620.  
  3621. // Get _POST data 
  3622. if ( bbp_is_post_request() && isset( $_POST['bbp_forum_id'] ) ) { 
  3623. $topic_forum = (int) $_POST['bbp_forum_id']; 
  3624.  
  3625. // Get edit data 
  3626. } elseif ( bbp_is_topic_edit() ) { 
  3627. $topic_forum = bbp_get_topic_forum_id(); 
  3628.  
  3629. // No data 
  3630. } else { 
  3631. $topic_forum = 0; 
  3632.  
  3633. return apply_filters( 'bbp_get_form_topic_forum', $topic_forum ); 
  3634.  
  3635. /** 
  3636. * Output checked value of topic subscription 
  3637. * 
  3638. * @since bbPress (r2976) 
  3639. * 
  3640. * @uses bbp_get_form_topic_subscribed() To get the subscribed checkbox value 
  3641. */ 
  3642. function bbp_form_topic_subscribed() { 
  3643. echo bbp_get_form_topic_subscribed(); 
  3644. /** 
  3645. * Return checked value of topic subscription 
  3646. * 
  3647. * @since bbPress (r2976) 
  3648. * 
  3649. * @uses bbp_is_topic_edit() To check if it's the topic edit page 
  3650. * @uses bbp_is_user_subscribed_to_topic() To check if the user is 
  3651. * subscribed to the topic 
  3652. * @uses apply_filters() Calls 'bbp_get_form_topic_subscribed' with the 
  3653. * option 
  3654. * @return string Checked value of topic subscription 
  3655. */ 
  3656. function bbp_get_form_topic_subscribed() { 
  3657.  
  3658. // Get _POST data 
  3659. if ( bbp_is_post_request() && isset( $_POST['bbp_topic_subscription'] ) ) { 
  3660. $topic_subscribed = (bool) $_POST['bbp_topic_subscription']; 
  3661.  
  3662. // Get edit data 
  3663. } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) { 
  3664.  
  3665. // Get current posts author 
  3666. $post_author = bbp_get_global_post_field( 'post_author', 'raw' ); 
  3667.  
  3668. // Post author is not the current user 
  3669. if ( bbp_get_current_user_id() !== $post_author ) { 
  3670. $topic_subscribed = bbp_is_user_subscribed_to_topic( $post_author ); 
  3671.  
  3672. // Post author is the current user 
  3673. } else { 
  3674. $topic_subscribed = bbp_is_user_subscribed_to_topic( bbp_get_current_user_id() ); 
  3675.  
  3676. // Get current status 
  3677. } elseif ( bbp_is_single_topic() ) { 
  3678. $topic_subscribed = bbp_is_user_subscribed_to_topic( bbp_get_current_user_id() ); 
  3679.  
  3680. // No data 
  3681. } else { 
  3682. $topic_subscribed = false; 
  3683.  
  3684. // Get checked output 
  3685. $checked = checked( $topic_subscribed, true, false ); 
  3686.  
  3687. return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed ); 
  3688.  
  3689. /** 
  3690. * Output checked value of topic log edit field 
  3691. * 
  3692. * @since bbPress (r2976) 
  3693. * 
  3694. * @uses bbp_get_form_topic_log_edit() To get the topic log edit value 
  3695. */ 
  3696. function bbp_form_topic_log_edit() { 
  3697. echo bbp_get_form_topic_log_edit(); 
  3698. /** 
  3699. * Return checked value of topic log edit field 
  3700. * 
  3701. * @since bbPress (r2976) 
  3702. * 
  3703. * @uses apply_filters() Calls 'bbp_get_form_topic_log_edit' with the 
  3704. * log edit value 
  3705. * @return string Topic log edit checked value 
  3706. */ 
  3707. function bbp_get_form_topic_log_edit() { 
  3708.  
  3709. // Get _POST data 
  3710. if ( bbp_is_post_request() && isset( $_POST['bbp_log_topic_edit'] ) ) { 
  3711. $topic_revision = (int) $_POST['bbp_log_topic_edit']; 
  3712.  
  3713. // No data 
  3714. } else { 
  3715. $topic_revision = 1; 
  3716.  
  3717. // Get checked output 
  3718. $checked = checked( $topic_revision, true, false ); 
  3719.  
  3720. return apply_filters( 'bbp_get_form_topic_log_edit', $checked, $topic_revision ); 
  3721.  
  3722. /** 
  3723. * Output the value of the topic edit reason 
  3724. * 
  3725. * @since bbPress (r2976) 
  3726. * 
  3727. * @uses bbp_get_form_topic_edit_reason() To get the topic edit reason value 
  3728. */ 
  3729. function bbp_form_topic_edit_reason() { 
  3730. echo bbp_get_form_topic_edit_reason(); 
  3731. /** 
  3732. * Return the value of the topic edit reason 
  3733. * 
  3734. * @since bbPress (r2976) 
  3735. * 
  3736. * @uses apply_filters() Calls 'bbp_get_form_topic_edit_reason' with the 
  3737. * topic edit reason value 
  3738. * @return string Topic edit reason value 
  3739. */ 
  3740. function bbp_get_form_topic_edit_reason() { 
  3741.  
  3742. // Get _POST data 
  3743. if ( bbp_is_post_request() && isset( $_POST['bbp_topic_edit_reason'] ) ) { 
  3744. $topic_edit_reason = $_POST['bbp_topic_edit_reason']; 
  3745.  
  3746. // No data 
  3747. } else { 
  3748. $topic_edit_reason = ''; 
  3749.  
  3750. return apply_filters( 'bbp_get_form_topic_edit_reason', esc_attr( $topic_edit_reason ) ); 
.