/includes/replies/template.php

  1. <?php 
  2.  
  3. /** 
  4. * bbPress Reply 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. * Return the unique id of the custom post type for replies 
  17. * 
  18. * @since bbPress (r2857) 
  19. * 
  20. * @uses bbp_get_reply_post_type() To get the reply post type 
  21. */ 
  22. function bbp_reply_post_type() { 
  23. echo bbp_get_reply_post_type(); 
  24. /** 
  25. * Return the unique id of the custom post type for replies 
  26. * 
  27. * @since bbPress (r2857) 
  28. * 
  29. * @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum 
  30. * post type id 
  31. * @return string The unique reply post type id 
  32. */ 
  33. function bbp_get_reply_post_type() { 
  34. return apply_filters( 'bbp_get_reply_post_type', bbpress()->reply_post_type ); 
  35.  
  36. /** 
  37. * Return array of labels used by the reply post type 
  38. * 
  39. * @since bbPress (r5129) 
  40. * 
  41. * @return array 
  42. */ 
  43. function bbp_get_reply_post_type_labels() { 
  44. return apply_filters( 'bbp_get_reply_post_type_labels', array( 
  45. 'name' => __( 'Replies', 'bbpress' ),  
  46. 'menu_name' => __( 'Replies', 'bbpress' ),  
  47. 'singular_name' => __( 'Reply', 'bbpress' ),  
  48. 'all_items' => __( 'All Replies', 'bbpress' ),  
  49. 'add_new' => __( 'New Reply', 'bbpress' ),  
  50. 'add_new_item' => __( 'Create New Reply', 'bbpress' ),  
  51. 'edit' => __( 'Edit', 'bbpress' ),  
  52. 'edit_item' => __( 'Edit Reply', 'bbpress' ),  
  53. 'new_item' => __( 'New Reply', 'bbpress' ),  
  54. 'view' => __( 'View Reply', 'bbpress' ),  
  55. 'view_item' => __( 'View Reply', 'bbpress' ),  
  56. 'search_items' => __( 'Search Replies', 'bbpress' ),  
  57. 'not_found' => __( 'No replies found', 'bbpress' ),  
  58. 'not_found_in_trash' => __( 'No replies found in Trash', 'bbpress' ),  
  59. 'parent_item_colon' => __( 'Topic:', 'bbpress' ) 
  60. ) ); 
  61.  
  62. /** 
  63. * Return array of reply post type rewrite settings 
  64. * 
  65. * @since bbPress (r5129) 
  66. * 
  67. * @return array 
  68. */ 
  69. function bbp_get_reply_post_type_rewrite() { 
  70. return apply_filters( 'bbp_get_reply_post_type_rewrite', array( 
  71. 'slug' => bbp_get_reply_slug(),  
  72. 'with_front' => false 
  73. ) ); 
  74.  
  75. /** 
  76. * Return array of features the reply post type supports 
  77. * 
  78. * @since bbPress (rx5129) 
  79. * 
  80. * @return array 
  81. */ 
  82. function bbp_get_reply_post_type_supports() { 
  83. return apply_filters( 'bbp_get_reply_post_type_supports', array( 
  84. 'title',  
  85. 'editor',  
  86. 'revisions' 
  87. ) ); 
  88.  
  89. /** Reply Loop Functions ******************************************************/ 
  90.  
  91. /** 
  92. * The main reply loop. WordPress makes this easy for us 
  93. * 
  94. * @since bbPress (r2553) 
  95. * 
  96. * @param mixed $args All the arguments supported by {@link WP_Query} 
  97. * @uses bbp_show_lead_topic() Are we showing the topic as a lead? 
  98. * @uses bbp_get_topic_id() To get the topic id 
  99. * @uses bbp_get_reply_post_type() To get the reply post type 
  100. * @uses bbp_get_topic_post_type() To get the topic post type 
  101. * @uses get_option() To get the replies per page option 
  102. * @uses bbp_get_paged() To get the current page value 
  103. * @uses current_user_can() To check if the current user is capable of editing 
  104. * others' replies 
  105. * @uses WP_Query To make query and get the replies 
  106. * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks 
  107. * @uses get_permalink() To get the permalink 
  108. * @uses add_query_arg() To add custom args to the url 
  109. * @uses apply_filters() Calls 'bbp_replies_pagination' with the pagination args 
  110. * @uses paginate_links() To paginate the links 
  111. * @uses apply_filters() Calls 'bbp_has_replies' with 
  112. * bbPres::reply_query::have_posts() 
  113. * and bbPres::reply_query 
  114. * @return object Multidimensional array of reply information 
  115. */ 
  116. function bbp_has_replies( $args = '' ) { 
  117. global $wp_rewrite; 
  118.  
  119. /** Defaults **************************************************************/ 
  120.  
  121. // Other defaults 
  122. $default_reply_search = !empty( $_REQUEST['rs'] ) ? $_REQUEST['rs'] : false; 
  123. $default_post_parent = ( bbp_is_single_topic() ) ? bbp_get_topic_id() : 'any'; 
  124. $default_post_type = ( bbp_is_single_topic() && bbp_show_lead_topic() ) ? bbp_get_reply_post_type() : array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ); 
  125. $default_thread_replies = (bool) ( bbp_is_single_topic() && bbp_thread_replies() ); 
  126.  
  127. // Default query args 
  128. $default = array( 
  129. 'post_type' => $default_post_type, // Only replies 
  130. 'post_parent' => $default_post_parent, // Of this topic 
  131. 'posts_per_page' => bbp_get_replies_per_page(), // This many 
  132. 'paged' => bbp_get_paged(), // On this page 
  133. 'orderby' => 'date', // Sorted by date 
  134. 'order' => 'ASC', // Oldest to newest 
  135. 'hierarchical' => $default_thread_replies, // Hierarchical replies 
  136. 'ignore_sticky_posts' => true, // Stickies not supported 
  137. 's' => $default_reply_search, // Maybe search 
  138. ); 
  139.  
  140. // What are the default allowed statuses (based on user caps) 
  141. if ( bbp_get_view_all() ) { 
  142.  
  143. // Default view=all statuses 
  144. $post_statuses = array( 
  145. bbp_get_public_status_id(),  
  146. bbp_get_closed_status_id(),  
  147. bbp_get_spam_status_id(),  
  148. bbp_get_trash_status_id() 
  149. ); 
  150.  
  151. // Add support for private status 
  152. if ( current_user_can( 'read_private_replies' ) ) { 
  153. $post_statuses[] = bbp_get_private_status_id(); 
  154.  
  155. // Join post statuses together 
  156. $default['post_status'] = implode( ', ', $post_statuses ); 
  157.  
  158. // Lean on the 'perm' query var value of 'readable' to provide statuses 
  159. } else { 
  160. $default['perm'] = 'readable'; 
  161.  
  162. /** Setup *****************************************************************/ 
  163.  
  164. // Parse arguments against default values 
  165. $r = bbp_parse_args( $args, $default, 'has_replies' ); 
  166.  
  167. // Set posts_per_page value if replies are threaded 
  168. $replies_per_page = $r['posts_per_page']; 
  169. if ( true === $r['hierarchical'] ) { 
  170. $r['posts_per_page'] = -1; 
  171.  
  172. // Get bbPress 
  173. $bbp = bbpress(); 
  174.  
  175. // Call the query 
  176. $bbp->reply_query = new WP_Query( $r ); 
  177.  
  178. // Add pagination values to query object 
  179. $bbp->reply_query->posts_per_page = $replies_per_page; 
  180. $bbp->reply_query->paged = $r['paged']; 
  181.  
  182. // Never home, regardless of what parse_query says 
  183. $bbp->reply_query->is_home = false; 
  184.  
  185. // Reset is_single if single topic 
  186. if ( bbp_is_single_topic() ) { 
  187. $bbp->reply_query->is_single = true; 
  188.  
  189. // Only add reply to if query returned results 
  190. if ( (int) $bbp->reply_query->found_posts ) { 
  191.  
  192. // Get reply to for each reply 
  193. foreach ( $bbp->reply_query->posts as &$post ) { 
  194.  
  195. // Check for reply post type 
  196. if ( bbp_get_reply_post_type() === $post->post_type ) { 
  197. $reply_to = bbp_get_reply_to( $post->ID ); 
  198.  
  199. // Make sure it's a reply to a reply 
  200. if ( empty( $reply_to ) || ( bbp_get_reply_topic_id( $post->ID ) === $reply_to ) ) { 
  201. $reply_to = 0; 
  202.  
  203. // Add reply_to to the post object so we can walk it later 
  204. $post->reply_to = $reply_to; 
  205.  
  206. // Only add pagination if query returned results 
  207. if ( (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) { 
  208.  
  209. // If pretty permalinks are enabled, make our pagination pretty 
  210. if ( $wp_rewrite->using_permalinks() ) { 
  211.  
  212. // User's replies 
  213. if ( bbp_is_single_user_replies() ) { 
  214. $base = bbp_get_user_replies_created_url( bbp_get_displayed_user_id() ); 
  215.  
  216. // Root profile page 
  217. } elseif ( bbp_is_single_user() ) { 
  218. $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() ); 
  219.  
  220. // Page or single post 
  221. } elseif ( is_page() || is_single() ) { 
  222. $base = get_permalink(); 
  223.  
  224. // Single topic 
  225. } else { 
  226. $base = get_permalink( bbp_get_topic_id() ); 
  227.  
  228. $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); 
  229.  
  230. // Unpretty permalinks 
  231. } else { 
  232. $base = add_query_arg( 'paged', '%#%' ); 
  233.  
  234. // Figure out total pages 
  235. if ( true === $r['hierarchical'] ) { 
  236. $walker = new BBP_Walker_Reply; 
  237. $total_pages = ceil( (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / (int) $replies_per_page ); 
  238. } else { 
  239. $total_pages = ceil( (int) $bbp->reply_query->found_posts / (int) $replies_per_page ); 
  240.  
  241. // Add pagination to query object 
  242. $bbp->reply_query->pagination_links = paginate_links( apply_filters( 'bbp_replies_pagination', array( 
  243. 'base' => $base,  
  244. 'format' => '',  
  245. 'total' => $total_pages,  
  246. 'current' => (int) $bbp->reply_query->paged,  
  247. 'prev_text' => is_rtl() ? '→' : '←',  
  248. 'next_text' => is_rtl() ? '←' : '→',  
  249. 'mid_size' => 1,  
  250. 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 
  251. ) ) ); 
  252.  
  253. // Remove first page from pagination 
  254. if ( $wp_rewrite->using_permalinks() ) { 
  255. $bbp->reply_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links ); 
  256. } else { 
  257. $bbp->reply_query->pagination_links = str_replace( '&paged=1', '', $bbp->reply_query->pagination_links ); 
  258.  
  259. // Return object 
  260. return apply_filters( 'bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query ); 
  261.  
  262. /** 
  263. * Whether there are more replies available in the loop 
  264. * 
  265. * @since bbPress (r2553) 
  266. * 
  267. * @uses WP_Query bbPress::reply_query::have_posts() To check if there are more 
  268. * replies available 
  269. * @return object Replies information 
  270. */ 
  271. function bbp_replies() { 
  272.  
  273. // Put into variable to check against next 
  274. $have_posts = bbpress()->reply_query->have_posts(); 
  275.  
  276. // Reset the post data when finished 
  277. if ( empty( $have_posts ) ) 
  278. wp_reset_postdata(); 
  279.  
  280. return $have_posts; 
  281.  
  282. /** 
  283. * Loads up the current reply in the loop 
  284. * 
  285. * @since bbPress (r2553) 
  286. * 
  287. * @uses WP_Query bbPress::reply_query::the_post() To get the current reply 
  288. * @return object Reply information 
  289. */ 
  290. function bbp_the_reply() { 
  291. return bbpress()->reply_query->the_post(); 
  292.  
  293. /** 
  294. * Output reply id 
  295. * 
  296. * @since bbPress (r2553) 
  297. * 
  298. * @param $reply_id Optional. Used to check emptiness 
  299. * @uses bbp_get_reply_id() To get the reply id 
  300. */ 
  301. function bbp_reply_id( $reply_id = 0 ) { 
  302. echo bbp_get_reply_id( $reply_id ); 
  303. /** 
  304. * Return the id of the reply in a replies loop 
  305. * 
  306. * @since bbPress (r2553) 
  307. * 
  308. * @param $reply_id Optional. Used to check emptiness 
  309. * @uses bbPress::reply_query::post::ID To get the reply id 
  310. * @uses bbp_is_reply() To check if the search result is a reply 
  311. * @uses bbp_is_single_reply() To check if it's a reply page 
  312. * @uses bbp_is_reply_edit() To check if it's a reply edit page 
  313. * @uses get_post_field() To get the post's post type 
  314. * @uses WP_Query::post::ID To get the reply id 
  315. * @uses bbp_get_reply_post_type() To get the reply post type 
  316. * @uses apply_filters() Calls 'bbp_get_reply_id' with the reply id and 
  317. * supplied reply id 
  318. * @return int The reply id 
  319. */ 
  320. function bbp_get_reply_id( $reply_id = 0 ) { 
  321. global $wp_query; 
  322.  
  323. $bbp = bbpress(); 
  324.  
  325. // Easy empty checking 
  326. if ( !empty( $reply_id ) && is_numeric( $reply_id ) ) { 
  327. $bbp_reply_id = $reply_id; 
  328.  
  329. // Currently inside a replies loop 
  330. } elseif ( !empty( $bbp->reply_query->in_the_loop ) && isset( $bbp->reply_query->post->ID ) ) { 
  331. $bbp_reply_id = $bbp->reply_query->post->ID; 
  332.  
  333. // Currently inside a search loop 
  334. } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_reply( $bbp->search_query->post->ID ) ) { 
  335. $bbp_reply_id = $bbp->search_query->post->ID; 
  336.  
  337. // Currently viewing a forum 
  338. } elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && !empty( $bbp->current_reply_id ) ) { 
  339. $bbp_reply_id = $bbp->current_reply_id; 
  340.  
  341. // Currently viewing a reply 
  342. } elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) ) { 
  343. $bbp_reply_id = $wp_query->post->ID; 
  344.  
  345. // Fallback 
  346. } else { 
  347. $bbp_reply_id = 0; 
  348.  
  349. return (int) apply_filters( 'bbp_get_reply_id', $bbp_reply_id, $reply_id ); 
  350.  
  351. /** 
  352. * Gets a reply 
  353. * 
  354. * @since bbPress (r2787) 
  355. * 
  356. * @param int|object $reply reply id or reply object 
  357. * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT 
  358. * @param string $filter Optional Sanitation filter. See {@link sanitize_post()} 
  359. * @uses get_post() To get the reply 
  360. * @uses bbp_get_reply_post_type() To get the reply post type 
  361. * @uses apply_filters() Calls 'bbp_get_reply' with the reply, output type and 
  362. * sanitation filter 
  363. * @return mixed Null if error or reply (in specified form) if success 
  364. */ 
  365. function bbp_get_reply( $reply, $output = OBJECT, $filter = 'raw' ) { 
  366. if ( empty( $reply ) || is_numeric( $reply ) ) 
  367. $reply = bbp_get_reply_id( $reply ); 
  368.  
  369. $reply = get_post( $reply, OBJECT, $filter ); 
  370. if ( empty( $reply ) ) 
  371. return $reply; 
  372.  
  373. if ( $reply->post_type !== bbp_get_reply_post_type() ) 
  374. return null; 
  375.  
  376. if ( $output === OBJECT ) { 
  377. return $reply; 
  378.  
  379. } elseif ( $output === ARRAY_A ) { 
  380. $_reply = get_object_vars( $reply ); 
  381. return $_reply; 
  382.  
  383. } elseif ( $output === ARRAY_N ) { 
  384. $_reply = array_values( get_object_vars( $reply ) ); 
  385. return $_reply; 
  386.  
  387.  
  388. return apply_filters( 'bbp_get_reply', $reply, $output, $filter ); 
  389.  
  390. /** 
  391. * Output the link to the reply in the reply loop 
  392. * 
  393. * @since bbPress (r2553) 
  394. * 
  395. * @param int $reply_id Optional. Reply id 
  396. * @uses bbp_get_reply_permalink() To get the reply permalink 
  397. */ 
  398. function bbp_reply_permalink( $reply_id = 0 ) { 
  399. echo esc_url( bbp_get_reply_permalink( $reply_id ) ); 
  400. /** 
  401. * Return the link to the reply 
  402. * 
  403. * @since bbPress (r2553) 
  404. * 
  405. * @param int $reply_id Optional. Reply id 
  406. * @uses bbp_get_reply_id() To get the reply id 
  407. * @uses get_permalink() To get the permalink of the reply 
  408. * @uses apply_filters() Calls 'bbp_get_reply_permalink' with the link 
  409. * and reply id 
  410. * @return string Permanent link to reply 
  411. */ 
  412. function bbp_get_reply_permalink( $reply_id = 0 ) { 
  413. $reply_id = bbp_get_reply_id( $reply_id ); 
  414.  
  415. return apply_filters( 'bbp_get_reply_permalink', get_permalink( $reply_id ), $reply_id ); 
  416. /** 
  417. * Output the paginated url to the reply in the reply loop 
  418. * 
  419. * @since bbPress (r2679) 
  420. * 
  421. * @param int $reply_id Optional. Reply id 
  422. * @uses bbp_get_reply_url() To get the reply url 
  423. */ 
  424. function bbp_reply_url( $reply_id = 0 ) { 
  425. echo esc_url( bbp_get_reply_url( $reply_id ) ); 
  426. /** 
  427. * Return the paginated url to the reply in the reply loop 
  428. * 
  429. * @since bbPress (r2679) 
  430. * 
  431. * @param int $reply_id Optional. Reply id 
  432. * @param string $redirect_to Optional. Pass a redirect value for use with 
  433. * shortcodes and other fun things. 
  434. * @uses bbp_get_reply_id() To get the reply id 
  435. * @uses bbp_get_reply_topic_id() To get the reply topic id 
  436. * @uses bbp_get_topic_permalink() To get the topic permalink 
  437. * @uses bbp_get_reply_position() To get the reply position 
  438. * @uses get_option() To get the replies per page option 
  439. * @uses WP_Rewrite::using_permalinks() To check if the blog uses 
  440. * permalinks 
  441. * @uses add_query_arg() To add custom args to the url 
  442. * @uses apply_filters() Calls 'bbp_get_reply_url' with the reply url,  
  443. * reply id and bool count hidden 
  444. * @return string Link to reply relative to paginated topic 
  445. */ 
  446. function bbp_get_reply_url( $reply_id = 0, $redirect_to = '' ) { 
  447.  
  448. // Set needed variables 
  449. $reply_id = bbp_get_reply_id ( $reply_id ); 
  450. $topic_id = bbp_get_reply_topic_id( $reply_id ); 
  451.  
  452. // Hierarchical reply page 
  453. if ( bbp_thread_replies() ) { 
  454. $reply_page = 1; 
  455.  
  456. // Standard reply page 
  457. } else { 
  458. $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() ); 
  459.  
  460. $reply_hash = '#post-' . $reply_id; 
  461. $topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to ); 
  462. $topic_url = remove_query_arg( 'view', $topic_link ); 
  463.  
  464. // Don't include pagination if on first page 
  465. if ( 1 >= $reply_page ) { 
  466. $url = trailingslashit( $topic_url ) . $reply_hash; 
  467.  
  468. // Include pagination 
  469. } else { 
  470. global $wp_rewrite; 
  471.  
  472. // Pretty permalinks 
  473. if ( $wp_rewrite->using_permalinks() ) { 
  474. $url = trailingslashit( $topic_url ) . trailingslashit( $wp_rewrite->pagination_base ) . trailingslashit( $reply_page ) . $reply_hash; 
  475.  
  476. // Yucky links 
  477. } else { 
  478. $url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash; 
  479.  
  480. // Add topic view query arg back to end if it is set 
  481. if ( bbp_get_view_all() ) 
  482. $url = bbp_add_view_all( $url ); 
  483.  
  484. return apply_filters( 'bbp_get_reply_url', $url, $reply_id, $redirect_to ); 
  485.  
  486. /** 
  487. * Output the title of the reply 
  488. * 
  489. * @since bbPress (r2553) 
  490. * 
  491. * @param int $reply_id Optional. Reply id 
  492. * @uses bbp_get_reply_title() To get the reply title 
  493. */ 
  494. function bbp_reply_title( $reply_id = 0 ) { 
  495. echo bbp_get_reply_title( $reply_id ); 
  496.  
  497. /** 
  498. * Return the title of the reply 
  499. * 
  500. * @since bbPress (r2553) 
  501. * 
  502. * @param int $reply_id Optional. Reply id 
  503. * @uses bbp_get_reply_id() To get the reply id 
  504. * @uses get_the_title() To get the reply title 
  505. * @uses apply_filters() Calls 'bbp_get_reply_title' with the title and 
  506. * reply id 
  507. * @return string Title of reply 
  508. */ 
  509. function bbp_get_reply_title( $reply_id = 0 ) { 
  510. $reply_id = bbp_get_reply_id( $reply_id ); 
  511.  
  512. return apply_filters( 'bbp_get_reply_title', get_the_title( $reply_id ), $reply_id ); 
  513.  
  514. /** 
  515. * Get empty reply title fallback. 
  516. * 
  517. * @since bbPress (r5177) 
  518. * 
  519. * @param string $reply_title Required. Reply Title 
  520. * @param int $reply_id Required. Reply ID 
  521. * @uses bbp_get_reply_topic_title() To get the reply topic title 
  522. * @uses apply_filters() Calls 'bbp_get_reply_title_fallback' with the title and reply ID 
  523. * @return string Title of reply 
  524. */ 
  525. function bbp_get_reply_title_fallback( $post_title = '', $post_id = 0 ) { 
  526.  
  527. // Bail if title not empty, or post is not a reply 
  528. if ( ! empty( $post_title ) || ! bbp_is_reply( $post_id ) ) { 
  529. return $post_title; 
  530.  
  531. // Get reply topic title. 
  532. $topic_title = bbp_get_reply_topic_title( $post_id ); 
  533.  
  534. // Get empty reply title fallback. 
  535. $reply_title = sprintf( __( 'Reply To: %s', 'bbpress' ), $topic_title ); 
  536.  
  537. return apply_filters( 'bbp_get_reply_title_fallback', $reply_title, $post_id, $topic_title ); 
  538.  
  539. /** 
  540. * Output the content of the reply 
  541. * 
  542. * @since bbPress (r2553) 
  543. * 
  544. * @param int $reply_id Optional. reply id 
  545. * @uses bbp_get_reply_content() To get the reply content 
  546. */ 
  547. function bbp_reply_content( $reply_id = 0 ) { 
  548. echo bbp_get_reply_content( $reply_id ); 
  549. /** 
  550. * Return the content of the reply 
  551. * 
  552. * @since bbPress (r2780) 
  553. * 
  554. * @param int $reply_id Optional. reply id 
  555. * @uses bbp_get_reply_id() To get the reply id 
  556. * @uses post_password_required() To check if the reply requires pass 
  557. * @uses get_the_password_form() To get the password form 
  558. * @uses get_post_field() To get the content post field 
  559. * @uses apply_filters() Calls 'bbp_get_reply_content' with the content 
  560. * and reply id 
  561. * @return string Content of the reply 
  562. */ 
  563. function bbp_get_reply_content( $reply_id = 0 ) { 
  564. $reply_id = bbp_get_reply_id( $reply_id ); 
  565.  
  566. // Check if password is required 
  567. if ( post_password_required( $reply_id ) ) 
  568. return get_the_password_form(); 
  569.  
  570. $content = get_post_field( 'post_content', $reply_id ); 
  571.  
  572. return apply_filters( 'bbp_get_reply_content', $content, $reply_id ); 
  573.  
  574. /** 
  575. * Output the excerpt of the reply 
  576. * 
  577. * @since bbPress (r2751) 
  578. * 
  579. * @param int $reply_id Optional. Reply id 
  580. * @param int $length Optional. Length of the excerpt. Defaults to 100 letters 
  581. * @uses bbp_get_reply_excerpt() To get the reply excerpt 
  582. */ 
  583. function bbp_reply_excerpt( $reply_id = 0, $length = 100 ) { 
  584. echo bbp_get_reply_excerpt( $reply_id, $length ); 
  585. /** 
  586. * Return the excerpt of the reply 
  587. * 
  588. * @since bbPress (r2751) 
  589. * 
  590. * @param int $reply_id Optional. Reply id 
  591. * @param int $length Optional. Length of the excerpt. Defaults to 100 
  592. * letters 
  593. * @uses bbp_get_reply_id() To get the reply id 
  594. * @uses get_post_field() To get the excerpt 
  595. * @uses bbp_get_reply_content() To get the reply content 
  596. * @uses apply_filters() Calls 'bbp_get_reply_excerpt' with the excerpt,  
  597. * reply id and length 
  598. * @return string Reply Excerpt 
  599. */ 
  600. function bbp_get_reply_excerpt( $reply_id = 0, $length = 100 ) { 
  601. $reply_id = bbp_get_reply_id( $reply_id ); 
  602. $length = (int) $length; 
  603. $excerpt = get_post_field( 'post_excerpt', $reply_id ); 
  604.  
  605. if ( empty( $excerpt ) ) { 
  606. $excerpt = bbp_get_reply_content( $reply_id ); 
  607.  
  608. $excerpt = trim ( strip_tags( $excerpt ) ); 
  609.  
  610. // Multibyte support 
  611. if ( function_exists( 'mb_strlen' ) ) { 
  612. $excerpt_length = mb_strlen( $excerpt ); 
  613. } else { 
  614. $excerpt_length = strlen( $excerpt ); 
  615.  
  616. if ( !empty( $length ) && ( $excerpt_length > $length ) ) { 
  617. $excerpt = substr( $excerpt, 0, $length - 1 ); 
  618. $excerpt .= '…'; 
  619.  
  620. return apply_filters( 'bbp_get_reply_excerpt', $excerpt, $reply_id, $length ); 
  621.  
  622. /** 
  623. * Output the post date and time of a reply 
  624. * 
  625. * @since bbPress (r4155) 
  626. * 
  627. * @param int $reply_id Optional. Reply id. 
  628. * @param bool $humanize Optional. Humanize output using time_since 
  629. * @param bool $gmt Optional. Use GMT 
  630. * @uses bbp_get_reply_post_date() to get the output 
  631. */ 
  632. function bbp_reply_post_date( $reply_id = 0, $humanize = false, $gmt = false ) { 
  633. echo bbp_get_reply_post_date( $reply_id, $humanize, $gmt ); 
  634. /** 
  635. * Return the post date and time of a reply 
  636. * 
  637. * @since bbPress (r4155) 
  638. * 
  639. * @param int $reply_id Optional. Reply id. 
  640. * @param bool $humanize Optional. Humanize output using time_since 
  641. * @param bool $gmt Optional. Use GMT 
  642. * @uses bbp_get_reply_id() To get the reply id 
  643. * @uses get_post_time() to get the reply post time 
  644. * @uses bbp_get_time_since() to maybe humanize the reply post time 
  645. * @return string 
  646. */ 
  647. function bbp_get_reply_post_date( $reply_id = 0, $humanize = false, $gmt = false ) { 
  648. $reply_id = bbp_get_reply_id( $reply_id ); 
  649.  
  650. // 4 days, 4 hours ago 
  651. if ( !empty( $humanize ) ) { 
  652. $gmt_s = !empty( $gmt ) ? 'G' : 'U'; 
  653. $date = get_post_time( $gmt_s, $gmt, $reply_id ); 
  654. $time = false; // For filter below 
  655. $result = bbp_get_time_since( $date ); 
  656.  
  657. // August 4, 2012 at 2:37 pm 
  658. } else { 
  659. $date = get_post_time( get_option( 'date_format' ), $gmt, $reply_id, true ); 
  660. $time = get_post_time( get_option( 'time_format' ), $gmt, $reply_id, true ); 
  661. $result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time ); 
  662.  
  663. return apply_filters( 'bbp_get_reply_post_date', $result, $reply_id, $humanize, $gmt, $date, $time ); 
  664.  
  665. /** 
  666. * Append revisions to the reply content 
  667. * 
  668. * @since bbPress (r2782) 
  669. * 
  670. * @param string $content Optional. Content to which we need to append the revisions to 
  671. * @param int $reply_id Optional. Reply id 
  672. * @uses bbp_get_reply_revision_log() To get the reply revision log 
  673. * @uses apply_filters() Calls 'bbp_reply_append_revisions' with the processed 
  674. * content, original content and reply id 
  675. * @return string Content with the revisions appended 
  676. */ 
  677. function bbp_reply_content_append_revisions( $content = '', $reply_id = 0 ) { 
  678.  
  679. // Bail if in admin or feed 
  680. if ( is_admin() || is_feed() ) 
  681. return $content; 
  682.  
  683. // Validate the ID 
  684. $reply_id = bbp_get_reply_id( $reply_id ); 
  685.  
  686. return apply_filters( 'bbp_reply_append_revisions', $content . bbp_get_reply_revision_log( $reply_id ), $content, $reply_id ); 
  687.  
  688. /** 
  689. * Output the revision log of the reply 
  690. * 
  691. * @since bbPress (r2782) 
  692. * 
  693. * @param int $reply_id Optional. Reply id 
  694. * @uses bbp_get_reply_revision_log() To get the reply revision log 
  695. */ 
  696. function bbp_reply_revision_log( $reply_id = 0 ) { 
  697. echo bbp_get_reply_revision_log( $reply_id ); 
  698. /** 
  699. * Return the formatted revision log of the reply 
  700. * 
  701. * @since bbPress (r2782) 
  702. * 
  703. * @param int $reply_id Optional. Reply id 
  704. * @uses bbp_get_reply_id() To get the reply id 
  705. * @uses bbp_get_reply_revisions() To get the reply revisions 
  706. * @uses bbp_get_reply_raw_revision_log() To get the raw revision log 
  707. * @uses bbp_get_reply_author_display_name() To get the reply author 
  708. * @uses bbp_get_reply_author_link() To get the reply author link 
  709. * @uses bbp_convert_date() To convert the date 
  710. * @uses bbp_get_time_since() To get the time in since format 
  711. * @uses apply_filters() Calls 'bbp_get_reply_revision_log' with the 
  712. * log and reply id 
  713. * @return string Revision log of the reply 
  714. */ 
  715. function bbp_get_reply_revision_log( $reply_id = 0 ) { 
  716.  
  717. // Create necessary variables 
  718. $reply_id = bbp_get_reply_id( $reply_id ); 
  719.  
  720. // Show the topic reply log if this is a topic in a reply loop 
  721. if ( bbp_is_topic( $reply_id ) ) { 
  722. return bbp_get_topic_revision_log( $reply_id ); 
  723.  
  724. // Get the reply revision log (out of post meta 
  725. $revision_log = bbp_get_reply_raw_revision_log( $reply_id ); 
  726.  
  727. // Check reply and revision log exist 
  728. if ( empty( $reply_id ) || empty( $revision_log ) || !is_array( $revision_log ) ) 
  729. return false; 
  730.  
  731. // Get the actual revisions 
  732. $revisions = bbp_get_reply_revisions( $reply_id ); 
  733. if ( empty( $revisions ) ) 
  734. return false; 
  735.  
  736. $r = "\n\n" . '<ul id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '" class="bbp-reply-revision-log">' . "\n\n"; 
  737.  
  738. // Loop through revisions 
  739. foreach ( (array) $revisions as $revision ) { 
  740.  
  741. if ( empty( $revision_log[$revision->ID] ) ) { 
  742. $author_id = $revision->post_author; 
  743. $reason = ''; 
  744. } else { 
  745. $author_id = $revision_log[$revision->ID]['author']; 
  746. $reason = $revision_log[$revision->ID]['reason']; 
  747.  
  748. $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_reply_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); 
  749. $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); 
  750.  
  751. $r .= "\t" . '<li id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-reply-revision-log-item">' . "\n"; 
  752. if ( !empty( $reason ) ) { 
  753. $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; 
  754. } else { 
  755. $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; 
  756. $r .= "\t" . '</li>' . "\n"; 
  757.  
  758.  
  759. $r .= "\n" . '</ul>' . "\n\n"; 
  760.  
  761. return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id ); 
  762. /** 
  763. * Return the raw revision log of the reply 
  764. * 
  765. * @since bbPress (r2782) 
  766. * 
  767. * @param int $reply_id Optional. Reply id 
  768. * @uses bbp_get_reply_id() To get the reply id 
  769. * @uses get_post_meta() To get the revision log meta 
  770. * @uses apply_filters() Calls 'bbp_get_reply_raw_revision_log' 
  771. * with the log and reply id 
  772. * @return string Raw revision log of the reply 
  773. */ 
  774. function bbp_get_reply_raw_revision_log( $reply_id = 0 ) { 
  775. $reply_id = bbp_get_reply_id( $reply_id ); 
  776. $revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true ); 
  777. $revision_log = empty( $revision_log ) ? array() : $revision_log; 
  778.  
  779. return apply_filters( 'bbp_get_reply_raw_revision_log', $revision_log, $reply_id ); 
  780.  
  781. /** 
  782. * Return the revisions of the reply 
  783. * 
  784. * @since bbPress (r2782) 
  785. * 
  786. * @param int $reply_id Optional. Reply id 
  787. * @uses bbp_get_reply_id() To get the reply id 
  788. * @uses wp_get_post_revisions() To get the reply revisions 
  789. * @uses apply_filters() Calls 'bbp_get_reply_revisions' 
  790. * with the revisions and reply id 
  791. * @return string reply revisions 
  792. */ 
  793. function bbp_get_reply_revisions( $reply_id = 0 ) { 
  794. $reply_id = bbp_get_reply_id( $reply_id ); 
  795. $revisions = wp_get_post_revisions( $reply_id, array( 'order' => 'ASC' ) ); 
  796.  
  797. return apply_filters( 'bbp_get_reply_revisions', $revisions, $reply_id ); 
  798.  
  799. /** 
  800. * Return the revision count of the reply 
  801. * 
  802. * @since bbPress (r2782) 
  803. * 
  804. * @param int $reply_id Optional. Reply id 
  805. * @param boolean $integer Optional. Whether or not to format the result 
  806. * @uses bbp_get_reply_revisions() To get the reply revisions 
  807. * @uses apply_filters() Calls 'bbp_get_reply_revision_count' 
  808. * with the revision count and reply id 
  809. * @return string reply revision count 
  810. */ 
  811. function bbp_get_reply_revision_count( $reply_id = 0, $integer = false ) { 
  812. $count = (int) count( bbp_get_reply_revisions( $reply_id ) ); 
  813. $filter = ( true === $integer ) ? 'bbp_get_reply_revision_count_int' : 'bbp_get_reply_revision_count'; 
  814.  
  815. return apply_filters( $filter, $count, $reply_id ); 
  816.  
  817. /** 
  818. * Output the status of the reply 
  819. * 
  820. * @since bbPress (r2667) 
  821. * 
  822. * @param int $reply_id Optional. Reply id 
  823. * @uses bbp_get_reply_status() To get the reply status 
  824. */ 
  825. function bbp_reply_status( $reply_id = 0 ) { 
  826. echo bbp_get_reply_status( $reply_id ); 
  827. /** 
  828. * Return the status of the reply 
  829. * 
  830. * @since bbPress (r2667) 
  831. * 
  832. * @param int $reply_id Optional. Reply id 
  833. * @uses bbp_get_reply_id() To get the reply id 
  834. * @uses get_post_status() To get the reply status 
  835. * @uses apply_filters() Calls 'bbp_get_reply_status' with the reply id 
  836. * @return string Status of reply 
  837. */ 
  838. function bbp_get_reply_status( $reply_id = 0 ) { 
  839. $reply_id = bbp_get_reply_id( $reply_id ); 
  840. return apply_filters( 'bbp_get_reply_status', get_post_status( $reply_id ), $reply_id ); 
  841.  
  842. /** 
  843. * Is the reply not spam or deleted? 
  844. * 
  845. * @since bbPress (r3496) 
  846. * 
  847. * @param int $reply_id Optional. Topic id 
  848. * @uses bbp_get_reply_id() To get the reply id 
  849. * @uses bbp_get_reply_status() To get the reply status 
  850. * @return bool True if published, false if not. 
  851. */ 
  852. function bbp_is_reply_published( $reply_id = 0 ) { 
  853. $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_public_status_id(); 
  854. return (bool) apply_filters( 'bbp_is_reply_published', (bool) $reply_status, $reply_id ); 
  855.  
  856. /** 
  857. * Is the reply marked as spam? 
  858. * 
  859. * @since bbPress (r2740) 
  860. * 
  861. * @param int $reply_id Optional. Reply id 
  862. * @uses bbp_get_reply_id() To get the reply id 
  863. * @uses bbp_get_reply_status() To get the reply status 
  864. * @return bool True if spam, false if not. 
  865. */ 
  866. function bbp_is_reply_spam( $reply_id = 0 ) { 
  867. $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_spam_status_id(); 
  868. return (bool) apply_filters( 'bbp_is_reply_spam', (bool) $reply_status, $reply_id ); 
  869.  
  870. /** 
  871. * Is the reply trashed? 
  872. * 
  873. * @since bbPress (r2884) 
  874. * 
  875. * @param int $reply_id Optional. Topic id 
  876. * @uses bbp_get_reply_id() To get the reply id 
  877. * @uses bbp_get_reply_status() To get the reply status 
  878. * @return bool True if spam, false if not. 
  879. */ 
  880. function bbp_is_reply_trash( $reply_id = 0 ) { 
  881. $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_trash_status_id(); 
  882. return (bool) apply_filters( 'bbp_is_reply_trash', (bool) $reply_status, $reply_id ); 
  883.  
  884. /** 
  885. * Is the reply by an anonymous user? 
  886. * 
  887. * @since bbPress (r2753) 
  888. * 
  889. * @param int $reply_id Optional. Reply id 
  890. * @uses bbp_get_reply_id() To get the reply id 
  891. * @uses bbp_get_reply_author_id() To get the reply author id 
  892. * @uses get_post_meta() To get the anonymous name and email metas 
  893. * @return bool True if the post is by an anonymous user, false if not. 
  894. */ 
  895. function bbp_is_reply_anonymous( $reply_id = 0 ) { 
  896. $reply_id = bbp_get_reply_id( $reply_id ); 
  897. $retval = false; 
  898.  
  899. if ( !bbp_get_reply_author_id( $reply_id ) ) 
  900. $retval = true; 
  901.  
  902. elseif ( get_post_meta( $reply_id, '_bbp_anonymous_name', true ) ) 
  903. $retval = true; 
  904.  
  905. elseif ( get_post_meta( $reply_id, '_bbp_anonymous_email', true ) ) 
  906. $retval = true; 
  907.  
  908. return (bool) apply_filters( 'bbp_is_reply_anonymous', $retval, $reply_id ); 
  909.  
  910. /** 
  911. * Deprecated. Use bbp_reply_author_display_name() instead. 
  912. * 
  913. * Output the author of the reply 
  914. * 
  915. * @since bbPress (r2667) 
  916. * @deprecated bbPress (r5119) 
  917. * 
  918. * @param int $reply_id Optional. Reply id 
  919. * @uses bbp_get_reply_author() To get the reply author 
  920. */ 
  921. function bbp_reply_author( $reply_id = 0 ) { 
  922. echo bbp_get_reply_author( $reply_id ); 
  923. /** 
  924. * Deprecated. Use bbp_get_reply_author_display_name() instead. 
  925. * 
  926. * Return the author of the reply 
  927. * 
  928. * @since bbPress (r2667) 
  929. * @deprecated bbPress (r5119) 
  930. * 
  931. * @param int $reply_id Optional. Reply id 
  932. * @uses bbp_get_reply_id() To get the reply id 
  933. * @uses bbp_is_reply_anonymous() To check if the reply is by an 
  934. * anonymous user 
  935. * @uses get_the_author_meta() To get the reply author display name 
  936. * @uses get_post_meta() To get the anonymous poster name 
  937. * @uses apply_filters() Calls 'bbp_get_reply_author' with the reply 
  938. * author and reply id 
  939. * @return string Author of reply 
  940. */ 
  941. function bbp_get_reply_author( $reply_id = 0 ) { 
  942. $reply_id = bbp_get_reply_id( $reply_id ); 
  943.  
  944. if ( !bbp_is_reply_anonymous( $reply_id ) ) { 
  945. $author = get_the_author_meta( 'display_name', bbp_get_reply_author_id( $reply_id ) ); 
  946. } else { 
  947. $author = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); 
  948.  
  949. return apply_filters( 'bbp_get_reply_author', $author, $reply_id ); 
  950.  
  951. /** 
  952. * Output the author ID of the reply 
  953. * 
  954. * @since bbPress (r2667) 
  955. * 
  956. * @param int $reply_id Optional. Reply id 
  957. * @uses bbp_get_reply_author_id() To get the reply author id 
  958. */ 
  959. function bbp_reply_author_id( $reply_id = 0 ) { 
  960. echo bbp_get_reply_author_id( $reply_id ); 
  961. /** 
  962. * Return the author ID of the reply 
  963. * 
  964. * @since bbPress (r2667) 
  965. * 
  966. * @param int $reply_id Optional. Reply id 
  967. * @uses bbp_get_reply_id() To get the reply id 
  968. * @uses get_post_field() To get the reply author id 
  969. * @uses apply_filters() Calls 'bbp_get_reply_author_id' with the author 
  970. * id and reply id 
  971. * @return string Author id of reply 
  972. */ 
  973. function bbp_get_reply_author_id( $reply_id = 0 ) { 
  974. $reply_id = bbp_get_reply_id( $reply_id ); 
  975. $author_id = get_post_field( 'post_author', $reply_id ); 
  976.  
  977. return (int) apply_filters( 'bbp_get_reply_author_id', $author_id, $reply_id ); 
  978.  
  979. /** 
  980. * Output the author display_name of the reply 
  981. * 
  982. * @since bbPress (r2667) 
  983. * 
  984. * @param int $reply_id Optional. Reply id 
  985. * @uses bbp_get_reply_author_display_name() 
  986. */ 
  987. function bbp_reply_author_display_name( $reply_id = 0 ) { 
  988. echo bbp_get_reply_author_display_name( $reply_id ); 
  989. /** 
  990. * Return the author display_name of the reply 
  991. * 
  992. * @since bbPress (r2667) 
  993. * 
  994. * @param int $reply_id Optional. Reply id 
  995. * @uses bbp_get_reply_id() To get the reply id 
  996. * @uses bbp_is_reply_anonymous() To check if the reply is by an 
  997. * anonymous user 
  998. * @uses bbp_get_reply_author_id() To get the reply author id 
  999. * @uses get_the_author_meta() To get the reply author's display name 
  1000. * @uses get_post_meta() To get the anonymous poster's name 
  1001. * @uses apply_filters() Calls 'bbp_get_reply_author_display_name' with 
  1002. * the author display name and reply id 
  1003. * @return string Reply's author's display name 
  1004. */ 
  1005. function bbp_get_reply_author_display_name( $reply_id = 0 ) { 
  1006. $reply_id = bbp_get_reply_id( $reply_id ); 
  1007.  
  1008. // User is not a guest 
  1009. if ( !bbp_is_reply_anonymous( $reply_id ) ) { 
  1010.  
  1011. // Get the author ID 
  1012. $author_id = bbp_get_reply_author_id( $reply_id ); 
  1013.  
  1014. // Try to get a display name 
  1015. $author_name = get_the_author_meta( 'display_name', $author_id ); 
  1016.  
  1017. // Fall back to user login 
  1018. if ( empty( $author_name ) ) { 
  1019. $author_name = get_the_author_meta( 'user_login', $author_id ); 
  1020.  
  1021. // User does not have an account 
  1022. } else { 
  1023. $author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); 
  1024.  
  1025. // If nothing could be found anywhere, use Anonymous 
  1026. if ( empty( $author_name ) ) 
  1027. $author_name = __( 'Anonymous', 'bbpress' ); 
  1028.  
  1029. // Encode possible UTF8 display names 
  1030. if ( seems_utf8( $author_name ) === false ) 
  1031. $author_name = utf8_encode( $author_name ); 
  1032.  
  1033. return apply_filters( 'bbp_get_reply_author_display_name', $author_name, $reply_id ); 
  1034.  
  1035. /** 
  1036. * Output the author avatar of the reply 
  1037. * 
  1038. * @since bbPress (r2667) 
  1039. * 
  1040. * @param int $reply_id Optional. Reply id 
  1041. * @param int $size Optional. Size of the avatar. Defaults to 40 
  1042. * @uses bbp_get_reply_author_avatar() To get the reply author id 
  1043. */ 
  1044. function bbp_reply_author_avatar( $reply_id = 0, $size = 40 ) { 
  1045. echo bbp_get_reply_author_avatar( $reply_id, $size ); 
  1046. /** 
  1047. * Return the author avatar of the reply 
  1048. * 
  1049. * @since bbPress (r2667) 
  1050. * 
  1051. * @param int $reply_id Optional. Reply id 
  1052. * @param int $size Optional. Size of the avatar. Defaults to 40 
  1053. * @uses bbp_get_reply_id() To get the reply id 
  1054. * @uses bbp_is_reply_anonymous() To check if the reply is by an 
  1055. * anonymous user 
  1056. * @uses bbp_get_reply_author_id() To get the reply author id 
  1057. * @uses get_post_meta() To get the anonymous poster's email id 
  1058. * @uses get_avatar() To get the avatar 
  1059. * @uses apply_filters() Calls 'bbp_get_reply_author_avatar' with the 
  1060. * author avatar, reply id and size 
  1061. * @return string Avatar of author of the reply 
  1062. */ 
  1063. function bbp_get_reply_author_avatar( $reply_id = 0, $size = 40 ) { 
  1064. $reply_id = bbp_get_reply_id( $reply_id ); 
  1065. if ( !empty( $reply_id ) ) { 
  1066. // Check for anonymous user 
  1067. if ( !bbp_is_reply_anonymous( $reply_id ) ) { 
  1068. $author_avatar = get_avatar( bbp_get_reply_author_id( $reply_id ), $size ); 
  1069. } else { 
  1070. $author_avatar = get_avatar( get_post_meta( $reply_id, '_bbp_anonymous_email', true ), $size ); 
  1071. } else { 
  1072. $author_avatar = ''; 
  1073.  
  1074. return apply_filters( 'bbp_get_reply_author_avatar', $author_avatar, $reply_id, $size ); 
  1075.  
  1076. /** 
  1077. * Output the author link of the reply 
  1078. * 
  1079. * @since bbPress (r2717) 
  1080. * 
  1081. * @param mixed $args Optional. If it is an integer, it is used as reply id. 
  1082. * @uses bbp_get_reply_author_link() To get the reply author link 
  1083. */ 
  1084. function bbp_reply_author_link( $args = '' ) { 
  1085. echo bbp_get_reply_author_link( $args ); 
  1086. /** 
  1087. * Return the author link of the reply 
  1088. * 
  1089. * @since bbPress (r2717) 
  1090. * 
  1091. * @param mixed $args Optional. If an integer, it is used as reply id. 
  1092. * @uses bbp_get_reply_id() To get the reply id 
  1093. * @uses bbp_is_reply_anonymous() To check if the reply is by an 
  1094. * anonymous user 
  1095. * @uses bbp_get_reply_author_url() To get the reply author url 
  1096. * @uses bbp_get_reply_author_avatar() To get the reply author avatar 
  1097. * @uses bbp_get_reply_author_display_name() To get the reply author display 
  1098. * name 
  1099. * @uses bbp_get_user_display_role() To get the reply author display role 
  1100. * @uses bbp_get_reply_author_id() To get the reply author id 
  1101. * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the 
  1102. * author link and args 
  1103. * @return string Author link of reply 
  1104. */ 
  1105. function bbp_get_reply_author_link( $args = '' ) { 
  1106.  
  1107. // Parse arguments against default values 
  1108. $r = bbp_parse_args( $args, array( 
  1109. 'post_id' => 0,  
  1110. 'link_title' => '',  
  1111. 'type' => 'both',  
  1112. 'size' => 80,  
  1113. 'sep' => ' ',  
  1114. 'show_role' => false 
  1115. ), 'get_reply_author_link' ); 
  1116.  
  1117. // Used as reply_id 
  1118. if ( is_numeric( $args ) ) { 
  1119. $reply_id = bbp_get_reply_id( $args ); 
  1120. } else { 
  1121. $reply_id = bbp_get_reply_id( $r['post_id'] ); 
  1122.  
  1123. // Reply ID is good 
  1124. if ( !empty( $reply_id ) ) { 
  1125.  
  1126. // Get some useful reply information 
  1127. $author_url = bbp_get_reply_author_url( $reply_id ); 
  1128. $anonymous = bbp_is_reply_anonymous( $reply_id ); 
  1129.  
  1130. // Tweak link title if empty 
  1131. if ( empty( $r['link_title'] ) ) { 
  1132. $link_title = sprintf( empty( $anonymous ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_reply_author_display_name( $reply_id ) ); 
  1133.  
  1134. // Use what was passed if not 
  1135. } else { 
  1136. $link_title = $r['link_title']; 
  1137.  
  1138. // Setup title and author_links array 
  1139. $link_title = !empty( $link_title ) ? ' title="' . esc_attr( $link_title ) . '"' : ''; 
  1140. $author_links = array(); 
  1141.  
  1142. // Get avatar 
  1143. if ( 'avatar' === $r['type'] || 'both' === $r['type'] ) { 
  1144. $author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $r['size'] ); 
  1145.  
  1146. // Get display name 
  1147. if ( 'name' === $r['type'] || 'both' === $r['type'] ) { 
  1148. $author_links['name'] = bbp_get_reply_author_display_name( $reply_id ); 
  1149.  
  1150. // Link class 
  1151. $link_class = ' class="bbp-author-' . esc_attr( $r['type'] ) . '"'; 
  1152.  
  1153. // Add links if not anonymous and existing user 
  1154. if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) { 
  1155.  
  1156. // Assemble the links 
  1157. foreach ( $author_links as $link => $link_text ) { 
  1158. $link_class = ' class="bbp-author-' . $link . '"'; 
  1159. $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text ); 
  1160.  
  1161. if ( true === $r['show_role'] ) { 
  1162. $author_link[] = bbp_get_reply_author_role( array( 'reply_id' => $reply_id ) ); 
  1163.  
  1164. $author_link = implode( $r['sep'], $author_link ); 
  1165.  
  1166. // No links if anonymous 
  1167. } else { 
  1168. $author_link = implode( $r['sep'], $author_links ); 
  1169.  
  1170. // No replies so link is empty 
  1171. } else { 
  1172. $author_link = ''; 
  1173.  
  1174. return apply_filters( 'bbp_get_reply_author_link', $author_link, $r ); 
  1175.  
  1176. /** 
  1177. * Output the author url of the reply 
  1178. * 
  1179. * @since bbPress (r2667) 
  1180. * 
  1181. * @param int $reply_id Optional. Reply id 
  1182. * @uses bbp_get_reply_author_url() To get the reply author url 
  1183. */ 
  1184. function bbp_reply_author_url( $reply_id = 0 ) { 
  1185. echo esc_url( bbp_get_reply_author_url( $reply_id ) ); 
  1186. /** 
  1187. * Return the author url of the reply 
  1188. * 
  1189. * @since bbPress (r2667) 
  1190. * 
  1191. * @param int $reply_id Optional. Reply id 
  1192. * @uses bbp_get_reply_id() To get the reply id 
  1193. * @uses bbp_is_reply_anonymous() To check if the reply is by an anonymous 
  1194. * user 
  1195. * @uses bbp_user_has_profile() To check if the user has a profile 
  1196. * @uses bbp_get_reply_author_id() To get the reply author id 
  1197. * @uses bbp_get_user_profile_url() To get the user profile url 
  1198. * @uses get_post_meta() To get the anonymous poster's website url 
  1199. * @uses apply_filters() Calls bbp_get_reply_author_url with the author 
  1200. * url & reply id 
  1201. * @return string Author URL of the reply 
  1202. */ 
  1203. function bbp_get_reply_author_url( $reply_id = 0 ) { 
  1204. $reply_id = bbp_get_reply_id( $reply_id ); 
  1205.  
  1206. // Check for anonymous user or non-existant user 
  1207. if ( !bbp_is_reply_anonymous( $reply_id ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) { 
  1208. $author_url = bbp_get_user_profile_url( bbp_get_reply_author_id( $reply_id ) ); 
  1209. } else { 
  1210. $author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true ); 
  1211. if ( empty( $author_url ) ) { 
  1212. $author_url = ''; 
  1213.  
  1214. return apply_filters( 'bbp_get_reply_author_url', $author_url, $reply_id ); 
  1215.  
  1216. /** 
  1217. * Output the reply author email address 
  1218. * 
  1219. * @since bbPress (r3445) 
  1220. * 
  1221. * @param int $reply_id Optional. Reply id 
  1222. * @uses bbp_get_reply_author_email() To get the reply author email 
  1223. */ 
  1224. function bbp_reply_author_email( $reply_id = 0 ) { 
  1225. echo bbp_get_reply_author_email( $reply_id ); 
  1226. /** 
  1227. * Return the reply author email address 
  1228. * 
  1229. * @since bbPress (r3445) 
  1230. * 
  1231. * @param int $reply_id Optional. Reply id 
  1232. * @uses bbp_get_reply_id() To get the reply id 
  1233. * @uses bbp_is_reply_anonymous() To check if the reply is by an anonymous 
  1234. * user 
  1235. * @uses bbp_get_reply_author_id() To get the reply author id 
  1236. * @uses get_userdata() To get the user data 
  1237. * @uses get_post_meta() To get the anonymous poster's website email 
  1238. * @uses apply_filters() Calls bbp_get_reply_author_email with the author 
  1239. * email & reply id 
  1240. * @return string Reply author email address 
  1241. */ 
  1242. function bbp_get_reply_author_email( $reply_id = 0 ) { 
  1243. $reply_id = bbp_get_reply_id( $reply_id ); 
  1244.  
  1245. // Not anonymous 
  1246. if ( !bbp_is_reply_anonymous( $reply_id ) ) { 
  1247.  
  1248. // Use reply author email address 
  1249. $user_id = bbp_get_reply_author_id( $reply_id ); 
  1250. $user = get_userdata( $user_id ); 
  1251. $author_email = !empty( $user->user_email ) ? $user->user_email : ''; 
  1252.  
  1253. // Anonymous 
  1254. } else { 
  1255.  
  1256. // Get email from post meta 
  1257. $author_email = get_post_meta( $reply_id, '_bbp_anonymous_email', true ); 
  1258.  
  1259. // Sanity check for missing email address 
  1260. if ( empty( $author_email ) ) { 
  1261. $author_email = ''; 
  1262.  
  1263. return apply_filters( 'bbp_get_reply_author_email', $author_email, $reply_id ); 
  1264.  
  1265. /** 
  1266. * Output the reply author role 
  1267. * 
  1268. * @since bbPress (r3860) 
  1269. * 
  1270. * @param array $args Optional. 
  1271. * @uses bbp_get_reply_author_role() To get the reply author role 
  1272. */ 
  1273. function bbp_reply_author_role( $args = array() ) { 
  1274. echo bbp_get_reply_author_role( $args ); 
  1275. /** 
  1276. * Return the reply author role 
  1277. * 
  1278. * @since bbPress (r3860) 
  1279. * 
  1280. * @param array $args Optional. 
  1281. * @uses bbp_get_reply_id() To get the reply id 
  1282. * @uses bbp_get_user_display_role() To get the user display role 
  1283. * @uses bbp_get_reply_author_id() To get the reply author id 
  1284. * @uses apply_filters() Calls bbp_get_reply_author_role with the author 
  1285. * role & args 
  1286. * @return string Reply author role 
  1287. */ 
  1288. function bbp_get_reply_author_role( $args = array() ) { 
  1289.  
  1290. // Parse arguments against default values 
  1291. $r = bbp_parse_args( $args, array( 
  1292. 'reply_id' => 0,  
  1293. 'class' => 'bbp-author-role',  
  1294. 'before' => '',  
  1295. 'after' => '' 
  1296. ), 'get_reply_author_role' ); 
  1297.  
  1298. $reply_id = bbp_get_reply_id( $r['reply_id'] ); 
  1299. $role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) ); 
  1300. $author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], esc_attr( $r['class'] ), esc_html( $role ), $r['after'] ); 
  1301.  
  1302. return apply_filters( 'bbp_get_reply_author_role', $author_role, $r ); 
  1303.  
  1304. /** 
  1305. * Output the topic title a reply belongs to 
  1306. * 
  1307. * @since bbPress (r2553) 
  1308. * 
  1309. * @param int $reply_id Optional. Reply id 
  1310. * @uses bbp_get_reply_topic_title() To get the reply topic title 
  1311. */ 
  1312. function bbp_reply_topic_title( $reply_id = 0 ) { 
  1313. echo bbp_get_reply_topic_title( $reply_id ); 
  1314. /** 
  1315. * Return the topic title a reply belongs to 
  1316. * 
  1317. * @since bbPress (r2553) 
  1318. * 
  1319. * @param int $reply_id Optional. Reply id 
  1320. * @uses bbp_get_reply_id() To get the reply id 
  1321. * @uses bbp_get_reply_topic_id() To get the reply topic id 
  1322. * @uses bbp_get_topic_title() To get the reply topic title 
  1323. * @uses apply_filters() Calls 'bbp_get_reply_topic_title' with the 
  1324. * topic title and reply id 
  1325. * @return string Reply's topic's title 
  1326. */ 
  1327. function bbp_get_reply_topic_title( $reply_id = 0 ) { 
  1328. $reply_id = bbp_get_reply_id( $reply_id ); 
  1329. $topic_id = bbp_get_reply_topic_id( $reply_id ); 
  1330.  
  1331. return apply_filters( 'bbp_get_reply_topic_title', bbp_get_topic_title( $topic_id ), $reply_id ); 
  1332.  
  1333. /** 
  1334. * Output the topic id a reply belongs to 
  1335. * 
  1336. * @since bbPress (r2553) 
  1337. * 
  1338. * @param int $reply_id Optional. Reply id 
  1339. * @uses bbp_get_reply_topic_id() To get the reply topic id 
  1340. */ 
  1341. function bbp_reply_topic_id( $reply_id = 0 ) { 
  1342. echo bbp_get_reply_topic_id( $reply_id ); 
  1343. /** 
  1344. * Return the topic id a reply belongs to 
  1345. * 
  1346. * @since bbPress (r2553) 
  1347. * 
  1348. * @param int $reply_id Optional. Reply id 
  1349. * @uses bbp_get_reply_id() To get the reply id 
  1350. * @uses get_post_meta() To get the reply topic id from meta 
  1351. * @uses bbp_get_topic_id() To get the topic id 
  1352. * @uses apply_filters() Calls 'bbp_get_reply_topic_id' with the topic 
  1353. * id and reply id 
  1354. * @return int Reply's topic id 
  1355. */ 
  1356. function bbp_get_reply_topic_id( $reply_id = 0 ) { 
  1357.  
  1358. // Assume there is no topic id 
  1359. $topic_id = 0; 
  1360.  
  1361. // Check that reply_id is valid 
  1362. if ( $reply_id = bbp_get_reply_id( $reply_id ) ) 
  1363.  
  1364. // Get topic_id from reply 
  1365. if ( $topic_id = get_post_meta( $reply_id, '_bbp_topic_id', true ) ) 
  1366.  
  1367. // Validate the topic_id 
  1368. $topic_id = bbp_get_topic_id( $topic_id ); 
  1369.  
  1370. return (int) apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id ); 
  1371.  
  1372. /** 
  1373. * Output the forum id a reply belongs to 
  1374. * 
  1375. * @since bbPress (r2679) 
  1376. * 
  1377. * @param int $reply_id Optional. Reply id 
  1378. * @uses bbp_get_reply_forum_id() To get the reply forum id 
  1379. */ 
  1380. function bbp_reply_forum_id( $reply_id = 0 ) { 
  1381. echo bbp_get_reply_forum_id( $reply_id ); 
  1382. /** 
  1383. * Return the forum id a reply belongs to 
  1384. * 
  1385. * @since bbPress (r2679) 
  1386. * 
  1387. * @param int $reply_id Optional. Reply id 
  1388. * @uses bbp_get_reply_id() To get the reply id 
  1389. * @uses get_post_meta() To get the reply forum id 
  1390. * @uses apply_filters() Calls 'bbp_get_reply_forum_id' with the forum 
  1391. * id and reply id 
  1392. * @return int Reply's forum id 
  1393. */ 
  1394. function bbp_get_reply_forum_id( $reply_id = 0 ) { 
  1395.  
  1396. // Assume there is no forum 
  1397. $forum_id = 0; 
  1398.  
  1399. // Check that reply_id is valid 
  1400. if ( $reply_id = bbp_get_reply_id( $reply_id ) ) 
  1401.  
  1402. // Get forum_id from reply 
  1403. if ( $forum_id = get_post_meta( $reply_id, '_bbp_forum_id', true ) ) 
  1404.  
  1405. // Validate the forum_id 
  1406. $forum_id = bbp_get_forum_id( $forum_id ); 
  1407.  
  1408. return (int) apply_filters( 'bbp_get_reply_forum_id', $forum_id, $reply_id ); 
  1409.  
  1410. /** 
  1411. * Output the reply's ancestor reply id 
  1412. * 
  1413. * @since bbPress (r4944) 
  1414. * 
  1415. * @param int $reply_id Optional. Reply id 
  1416. * @uses bbp_get_reply_ancestor_id() To get the reply's ancestor id 
  1417. */ 
  1418. function bbp_reply_ancestor_id( $reply_id = 0 ) { 
  1419. echo bbp_get_reply_ancestor_id( $reply_id ); 
  1420. /** 
  1421. * Return the reply's ancestor reply id 
  1422. * 
  1423. * @since bbPress (r4944) 
  1424. * 
  1425. * @param in $reply_id Reply id 
  1426. * @uses bbp_get_reply_id() To get the reply id 
  1427. */ 
  1428. function bbp_get_reply_ancestor_id( $reply_id = 0 ) { 
  1429.  
  1430. // Validation 
  1431. $reply_id = bbp_get_reply_id( $reply_id ); 
  1432. if ( empty( $reply_id ) ) 
  1433. return false; 
  1434.  
  1435. // Find highest reply ancestor 
  1436. $ancestor_id = $reply_id; 
  1437. while ( $parent_id = bbp_get_reply_to( $ancestor_id ) ) { 
  1438. if ( empty( $parent_id ) || ( $parent_id === $ancestor_id ) || ( bbp_get_reply_topic_id( $reply_id ) === $parent_id ) || ( $parent_id === $reply_id ) ) { 
  1439. break; 
  1440. $ancestor_id = $parent_id; 
  1441.  
  1442. return (int) $ancestor_id; 
  1443.  
  1444. /** 
  1445. * Output the reply to id of a reply 
  1446. * 
  1447. * @since bbPress (r4944) 
  1448. * 
  1449. * @param int $reply_id Optional. Reply id 
  1450. * @uses bbp_get_reply_to() To get the reply to id 
  1451. */ 
  1452. function bbp_reply_to( $reply_id = 0 ) { 
  1453. echo bbp_get_reply_to( $reply_id ); 
  1454. /** 
  1455. * Return the reply to id of a reply 
  1456. * 
  1457. * @since bbPress (r4944) 
  1458. * 
  1459. * @param int $reply_id Optional. Reply id 
  1460. * @uses bbp_get_reply_id() To get the reply id 
  1461. * @uses get_post_meta() To get the reply to id 
  1462. * @uses apply_filters() Calls 'bbp_get_reply_to' with the reply to id and 
  1463. * reply id 
  1464. * @return int Reply's reply to id 
  1465. */ 
  1466. function bbp_get_reply_to( $reply_id = 0 ) { 
  1467.  
  1468. // Assume there is no reply_to set 
  1469. $reply_to = 0; 
  1470.  
  1471. // Check that reply_id is valid 
  1472. $reply_id = bbp_get_reply_id( $reply_id ); 
  1473.  
  1474. // Get reply_to value 
  1475. if ( !empty( $reply_id ) ) { 
  1476. $reply_to = (int) get_post_meta( $reply_id, '_bbp_reply_to', true ); 
  1477.  
  1478. return (int) apply_filters( 'bbp_get_reply_to', $reply_to, $reply_id ); 
  1479.  
  1480. /** 
  1481. * Output the link for the reply to 
  1482. * 
  1483. * @since bbPress (r4944) 
  1484. * 
  1485. * @param array $args 
  1486. * @uses bbp_get_reply_to_link() To get the reply to link 
  1487. */ 
  1488. function bbp_reply_to_link( $args = array() ) { 
  1489. echo bbp_get_reply_to_link( $args ); 
  1490.  
  1491. /** 
  1492. * Return the link for a reply to a reply 
  1493. * 
  1494. * @since bbPress (r4944) 
  1495. * 
  1496. * @param array $args Arguments 
  1497. * @uses bbp_current_user_can_access_create_reply_form() To check permissions 
  1498. * @uses bbp_get_reply_id() To validate the reply id 
  1499. * @uses bbp_get_reply() To get the reply 
  1500. * @uses apply_filters() Calls 'bbp_get_reply_to_link' with the formatted link,  
  1501. * the arguments array, and the reply 
  1502. * @return string Link for a reply to a reply 
  1503. */ 
  1504. function bbp_get_reply_to_link( $args = array() ) { 
  1505.  
  1506. // Parse arguments against default values 
  1507. $r = bbp_parse_args( $args, array( 
  1508. 'id' => 0,  
  1509. 'link_before' => '',  
  1510. 'link_after' => '',  
  1511. 'reply_text' => __( 'Reply', 'bbpress' ),  
  1512. 'depth' => 0,  
  1513. 'add_below' => 'post',  
  1514. 'respond_id' => 'new-reply-' . bbp_get_topic_id(),  
  1515. ), 'get_reply_to_link' ); 
  1516.  
  1517. // Get the reply to use it's ID and post_parent 
  1518. $reply = bbp_get_reply( bbp_get_reply_id( (int) $r['id'] ) ); 
  1519.  
  1520. // Bail if no reply or user cannot reply 
  1521. if ( empty( $reply ) || ! bbp_current_user_can_access_create_reply_form() ) 
  1522. return; 
  1523.  
  1524. // Build the URI and return value 
  1525. $uri = remove_query_arg( array( 'bbp_reply_to' ) ); 
  1526. $uri = add_query_arg( array( 'bbp_reply_to' => $reply->ID ) ); 
  1527. $uri = wp_nonce_url( $uri, 'respond_id_' . $reply->ID ); 
  1528. $uri = $uri . '#new-post'; 
  1529.  
  1530. // Only add onclick if replies are threaded 
  1531. if ( bbp_thread_replies() ) { 
  1532.  
  1533. // Array of classes to pass to moveForm 
  1534. $move_form = array( 
  1535. $r['add_below'] . '-' . $reply->ID,  
  1536. $reply->ID,  
  1537. $r['respond_id'],  
  1538. $reply->post_parent 
  1539. ); 
  1540.  
  1541. // Build the onclick 
  1542. $onclick = ' onclick="return addReply.moveForm(\'' . implode( "', '", $move_form ) . '\');"'; 
  1543.  
  1544. // No onclick if replies are not threaded 
  1545. } else { 
  1546. $onclick = ''; 
  1547.  
  1548. // Add $uri to the array, to be passed through the filter 
  1549. $r['uri'] = $uri; 
  1550. $retval = $r['link_before'] . '<a href="' . esc_url( $r['uri'] ) . '" class="bbp-reply-to-link"' . $onclick . '>' . esc_html( $r['reply_text'] ) . '</a>' . $r['link_after']; 
  1551.  
  1552. return apply_filters( 'bbp_get_reply_to_link', $retval, $r, $args ); 
  1553.  
  1554. /** 
  1555. * Output the reply to a reply cancellation link 
  1556. * 
  1557. * @since bbPress (r4944) 
  1558. * 
  1559. * @uses bbp_get_cancel_reply_to_link() To get the reply cancellation link 
  1560. */ 
  1561. function bbp_cancel_reply_to_link( $text = '' ) { 
  1562. echo bbp_get_cancel_reply_to_link( $text ); 
  1563. /** 
  1564. * Return the cancellation link for a reply to a reply 
  1565. * 
  1566. * @since bbPress (r4944) 
  1567. * 
  1568. * @param string $text The cancel text 
  1569. * @uses apply_filters() Calls 'bbp_get_cancel_reply_to_link' with the cancellation 
  1570. * link and the cancel text 
  1571. * @return string The cancellation link 
  1572. */ 
  1573. function bbp_get_cancel_reply_to_link( $text = '' ) { 
  1574.  
  1575. // Bail if not hierarchical or editing a reply 
  1576. if ( ! bbp_thread_replies() || bbp_is_reply_edit() ) { 
  1577. return; 
  1578.  
  1579. // Set default text 
  1580. if ( empty( $text ) ) { 
  1581. $text = __( 'Cancel', 'bbpress' ); 
  1582.  
  1583. $reply_to = isset( $_GET['bbp_reply_to'] ) ? (int) $_GET['bbp_reply_to'] : 0; 
  1584.  
  1585. // Set visibility 
  1586. $style = !empty( $reply_to ) ? '' : ' style="display:none;"'; 
  1587. $link = remove_query_arg( array( 'bbp_reply_to', '_wpnonce' ) ) . '#post-' . $reply_to; 
  1588. $retval = '<a rel="nofollow" id="bbp-cancel-reply-to-link" href="' . esc_url( $link ) . '"' . $style . '>' . esc_html( $text ) . '</a>'; 
  1589.  
  1590. return apply_filters( 'bbp_get_cancel_reply_to_link', $retval, $link, $text ); 
  1591.  
  1592. /** 
  1593. * Output the numeric position of a reply within a topic 
  1594. * 
  1595. * @since bbPress (r2984) 
  1596. * 
  1597. * @param int $reply_id Optional. Reply id 
  1598. * @param int $topic_id Optional. Topic id 
  1599. * @uses bbp_get_reply_position() To get the reply position 
  1600. */ 
  1601. function bbp_reply_position( $reply_id = 0, $topic_id = 0 ) { 
  1602. echo bbp_get_reply_position( $reply_id, $topic_id ); 
  1603. /** 
  1604. * Return the numeric position of a reply within a topic 
  1605. * 
  1606. * @since bbPress (r2984) 
  1607. * 
  1608. * @param int $reply_id Optional. Reply id 
  1609. * @param int $topic_id Optional. Topic id 
  1610. * @uses bbp_get_reply_id() To get the reply id 
  1611. * @uses bbp_get_reply_topic_id() Get the topic id of the reply id 
  1612. * @uses bbp_get_topic_reply_count() To get the topic reply count 
  1613. * @uses bbp_get_reply_post_type() To get the reply post type 
  1614. * @uses bbp_get_reply_position_raw() To get calculate the reply position 
  1615. * @uses bbp_update_reply_position() To update the reply position 
  1616. * @uses bbp_show_lead_topic() Bump the count if lead topic is included 
  1617. * @uses apply_filters() Calls 'bbp_get_reply_position' with the reply 
  1618. * position, reply id and topic id 
  1619. * @return int Reply position 
  1620. */ 
  1621. function bbp_get_reply_position( $reply_id = 0, $topic_id = 0 ) { 
  1622.  
  1623. // Get required data 
  1624. $reply_id = bbp_get_reply_id( $reply_id ); 
  1625. $reply_position = get_post_field( 'menu_order', $reply_id ); 
  1626.  
  1627. // Reply doesn't have a position so get the raw value 
  1628. if ( empty( $reply_position ) ) { 
  1629. $topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id ); 
  1630.  
  1631. // Post is not the topic 
  1632. if ( $reply_id !== $topic_id ) { 
  1633. $reply_position = bbp_get_reply_position_raw( $reply_id, $topic_id ); 
  1634.  
  1635. // Update the reply position in the posts table so we'll never have 
  1636. // to hit the DB again. 
  1637. if ( !empty( $reply_position ) ) { 
  1638. bbp_update_reply_position( $reply_id, $reply_position ); 
  1639.  
  1640. // Topic's position is always 0 
  1641. } else { 
  1642. $reply_position = 0; 
  1643.  
  1644. // Bump the position by one if the lead topic is in the replies loop 
  1645. if ( ! bbp_show_lead_topic() ) 
  1646. $reply_position++; 
  1647.  
  1648. return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id ); 
  1649.  
  1650. /** Reply Admin Links *********************************************************/ 
  1651.  
  1652. /** 
  1653. * Output admin links for reply 
  1654. * 
  1655. * @since bbPress (r2667) 
  1656. * 
  1657. * @param array $args See {@link bbp_get_reply_admin_links()} 
  1658. * @uses bbp_get_reply_admin_links() To get the reply admin links 
  1659. */ 
  1660. function bbp_reply_admin_links( $args = array() ) { 
  1661. echo bbp_get_reply_admin_links( $args ); 
  1662. /** 
  1663. * Return admin links for reply 
  1664. * 
  1665. * @since bbPress (r2667) 
  1666. * 
  1667. * @param array $args This function supports these arguments: 
  1668. * - id: Optional. Reply id 
  1669. * - before: HTML before the links. Defaults to 
  1670. * '<span class="bbp-admin-links">' 
  1671. * - after: HTML after the links. Defaults to '</span>' 
  1672. * - sep: Separator. Defaults to ' | ' 
  1673. * - links: Array of the links to display. By default, edit, trash,  
  1674. * spam, reply move, and topic split links are displayed 
  1675. * @uses bbp_is_topic() To check if it's the topic page 
  1676. * @uses bbp_is_reply() To check if it's the reply page 
  1677. * @uses bbp_get_reply_id() To get the reply id 
  1678. * @uses bbp_get_reply_edit_link() To get the reply edit link 
  1679. * @uses bbp_get_reply_trash_link() To get the reply trash link 
  1680. * @uses bbp_get_reply_spam_link() To get the reply spam link 
  1681. * @uses bbp_get_reply_move_link() To get the reply move link 
  1682. * @uses bbp_get_topic_split_link() To get the topic split link 
  1683. * @uses current_user_can() To check if the current user can edit or 
  1684. * delete the reply 
  1685. * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the 
  1686. * reply admin links and args 
  1687. * @return string Reply admin links 
  1688. */ 
  1689. function bbp_get_reply_admin_links( $args = array() ) { 
  1690.  
  1691. // Parse arguments against default values 
  1692. $r = bbp_parse_args( $args, array( 
  1693. 'id' => 0,  
  1694. 'before' => '<span class="bbp-admin-links">',  
  1695. 'after' => '</span>',  
  1696. 'sep' => ' | ',  
  1697. 'links' => array() 
  1698. ), 'get_reply_admin_links' ); 
  1699.  
  1700. $r['id'] = bbp_get_reply_id( (int) $r['id'] ); 
  1701.  
  1702. // If post is a topic, return the topic admin links instead 
  1703. if ( bbp_is_topic( $r['id'] ) ) { 
  1704. return bbp_get_topic_admin_links( $args ); 
  1705.  
  1706. // If post is not a reply, return 
  1707. if ( !bbp_is_reply( $r['id'] ) ) { 
  1708. return; 
  1709.  
  1710. // If topic is trashed, do not show admin links 
  1711. if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) ) { 
  1712. return; 
  1713.  
  1714. // If no links were passed, default to the standard 
  1715. if ( empty( $r['links'] ) ) { 
  1716. $r['links'] = apply_filters( 'bbp_reply_admin_links', array( 
  1717. 'edit' => bbp_get_reply_edit_link ( $r ),  
  1718. 'move' => bbp_get_reply_move_link ( $r ),  
  1719. 'split' => bbp_get_topic_split_link( $r ),  
  1720. 'trash' => bbp_get_reply_trash_link( $r ),  
  1721. 'spam' => bbp_get_reply_spam_link ( $r ),  
  1722. 'reply' => bbp_get_reply_to_link ( $r ) 
  1723. ), $r['id'] ); 
  1724.  
  1725. // See if links need to be unset 
  1726. $reply_status = bbp_get_reply_status( $r['id'] ); 
  1727. if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) { 
  1728.  
  1729. // Spam link shouldn't be visible on trashed topics 
  1730. if ( bbp_get_trash_status_id() === $reply_status ) { 
  1731. unset( $r['links']['spam'] ); 
  1732.  
  1733. // Trash link shouldn't be visible on spam topics 
  1734. } elseif ( bbp_get_spam_status_id() === $reply_status ) { 
  1735. unset( $r['links']['trash'] ); 
  1736.  
  1737. // Process the admin links 
  1738. $links = implode( $r['sep'], array_filter( $r['links'] ) ); 
  1739. $retval = $r['before'] . $links . $r['after']; 
  1740.  
  1741. return apply_filters( 'bbp_get_reply_admin_links', $retval, $r, $args ); 
  1742.  
  1743. /** 
  1744. * Output the edit link of the reply 
  1745. * 
  1746. * @since bbPress (r2740) 
  1747. * 
  1748. * @param mixed $args See {@link bbp_get_reply_edit_link()} 
  1749. * @uses bbp_get_reply_edit_link() To get the reply edit link 
  1750. */ 
  1751. function bbp_reply_edit_link( $args = '' ) { 
  1752. echo bbp_get_reply_edit_link( $args ); 
  1753.  
  1754. /** 
  1755. * Return the edit link of the reply 
  1756. * 
  1757. * @since bbPress (r2740) 
  1758. * 
  1759. * @param mixed $args This function supports these arguments: 
  1760. * - id: Reply id 
  1761. * - link_before: HTML before the link 
  1762. * - link_after: HTML after the link 
  1763. * - edit_text: Edit text. Defaults to 'Edit' 
  1764. * @uses bbp_get_reply_id() To get the reply id 
  1765. * @uses bbp_get_reply() To get the reply 
  1766. * @uses current_user_can() To check if the current user can edit the 
  1767. * reply 
  1768. * @uses bbp_get_reply_edit_url() To get the reply edit url 
  1769. * @uses apply_filters() Calls 'bbp_get_reply_edit_link' with the reply 
  1770. * edit link and args 
  1771. * @return string Reply edit link 
  1772. */ 
  1773. function bbp_get_reply_edit_link( $args = '' ) { 
  1774.  
  1775. // Parse arguments against default values 
  1776. $r = bbp_parse_args( $args, array( 
  1777. 'id' => 0,  
  1778. 'link_before' => '',  
  1779. 'link_after' => '',  
  1780. 'edit_text' => esc_html__( 'Edit', 'bbpress' ) 
  1781. ), 'get_reply_edit_link' ); 
  1782.  
  1783. $reply = bbp_get_reply( bbp_get_reply_id( (int) $r['id'] ) ); 
  1784.  
  1785. // Bypass check if user has caps 
  1786. if ( !current_user_can( 'edit_others_replies' ) ) { 
  1787.  
  1788. // User cannot edit or it is past the lock time 
  1789. if ( empty( $reply ) || !current_user_can( 'edit_reply', $reply->ID ) || bbp_past_edit_lock( $reply->post_date_gmt ) ) { 
  1790. return; 
  1791.  
  1792. // Get uri 
  1793. $uri = bbp_get_reply_edit_url( $r['id'] ); 
  1794.  
  1795. // Bail if no uri 
  1796. if ( empty( $uri ) ) 
  1797. return; 
  1798.  
  1799. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-edit-link">' . $r['edit_text'] . '</a>' . $r['link_after']; 
  1800.  
  1801. return apply_filters( 'bbp_get_reply_edit_link', $retval, $r ); 
  1802.  
  1803. /** 
  1804. * Output URL to the reply edit page 
  1805. * 
  1806. * @since bbPress (r2753) 
  1807. * 
  1808. * @param int $reply_id Optional. Reply id 
  1809. * @uses bbp_get_reply_edit_url() To get the reply edit url 
  1810. */ 
  1811. function bbp_reply_edit_url( $reply_id = 0 ) { 
  1812. echo esc_url( bbp_get_reply_edit_url( $reply_id ) ); 
  1813. /** 
  1814. * Return URL to the reply edit page 
  1815. * 
  1816. * @since bbPress (r2753) 
  1817. * 
  1818. * @param int $reply_id Optional. Reply id 
  1819. * @uses bbp_get_reply_id() To get the reply id 
  1820. * @uses bbp_get_reply() To get the reply 
  1821. * @uses bbp_get_reply_post_type() To get the reply post type 
  1822. * @uses add_query_arg() To add custom args to the url 
  1823. * @uses apply_filters() Calls 'bbp_get_reply_edit_url' with the edit 
  1824. * url and reply id 
  1825. * @return string Reply edit url 
  1826. */ 
  1827. function bbp_get_reply_edit_url( $reply_id = 0 ) { 
  1828. global $wp_rewrite; 
  1829.  
  1830. $bbp = bbpress(); 
  1831. $reply = bbp_get_reply( bbp_get_reply_id( $reply_id ) ); 
  1832. if ( empty( $reply ) ) 
  1833. return; 
  1834.  
  1835. $reply_link = bbp_remove_view_all( bbp_get_reply_permalink( $reply_id ) ); 
  1836.  
  1837. // Pretty permalinks 
  1838. if ( $wp_rewrite->using_permalinks() ) { 
  1839. $url = trailingslashit( $reply_link ) . $bbp->edit_id; 
  1840. $url = trailingslashit( $url ); 
  1841.  
  1842. // Unpretty permalinks 
  1843. } else { 
  1844. $url = add_query_arg( array( bbp_get_reply_post_type() => $reply->post_name, $bbp->edit_id => '1' ), $reply_link ); 
  1845.  
  1846. // Maybe add view all 
  1847. $url = bbp_add_view_all( $url ); 
  1848.  
  1849. return apply_filters( 'bbp_get_reply_edit_url', $url, $reply_id ); 
  1850.  
  1851. /** 
  1852. * Output the trash link of the reply 
  1853. * 
  1854. * @since bbPress (r2740) 
  1855. * 
  1856. * @param mixed $args See {@link bbp_get_reply_trash_link()} 
  1857. * @uses bbp_get_reply_trash_link() To get the reply trash link 
  1858. */ 
  1859. function bbp_reply_trash_link( $args = '' ) { 
  1860. echo bbp_get_reply_trash_link( $args ); 
  1861.  
  1862. /** 
  1863. * Return the trash link of the reply 
  1864. * 
  1865. * @since bbPress (r2740) 
  1866. * 
  1867. * @param mixed $args This function supports these arguments: 
  1868. * - id: Reply id 
  1869. * - link_before: HTML before the link 
  1870. * - link_after: HTML after the link 
  1871. * - sep: Separator 
  1872. * - trash_text: Trash text 
  1873. * - restore_text: Restore text 
  1874. * - delete_text: Delete text 
  1875. * @uses bbp_get_reply_id() To get the reply id 
  1876. * @uses bbp_get_reply() To get the reply 
  1877. * @uses current_user_can() To check if the current user can delete the 
  1878. * reply 
  1879. * @uses bbp_is_reply_trash() To check if the reply is trashed 
  1880. * @uses bbp_get_reply_status() To get the reply status 
  1881. * @uses add_query_arg() To add custom args to the url 
  1882. * @uses wp_nonce_url() To nonce the url 
  1883. * @uses esc_url() To escape the url 
  1884. * @uses bbp_get_reply_edit_url() To get the reply edit url 
  1885. * @uses apply_filters() Calls 'bbp_get_reply_trash_link' with the reply 
  1886. * trash link and args 
  1887. * @return string Reply trash link 
  1888. */ 
  1889. function bbp_get_reply_trash_link( $args = '' ) { 
  1890.  
  1891. // Parse arguments against default values 
  1892. $r = bbp_parse_args( $args, array( 
  1893. 'id' => 0,  
  1894. 'link_before' => '',  
  1895. 'link_after' => '',  
  1896. 'sep' => ' | ',  
  1897. 'trash_text' => esc_html__( 'Trash', 'bbpress' ),  
  1898. 'restore_text' => esc_html__( 'Restore', 'bbpress' ),  
  1899. 'delete_text' => esc_html__( 'Delete', 'bbpress' ) 
  1900. ), 'get_reply_trash_link' ); 
  1901.  
  1902. $actions = array(); 
  1903. $reply = bbp_get_reply( bbp_get_reply_id( (int) $r['id'] ) ); 
  1904.  
  1905. if ( empty( $reply ) || !current_user_can( 'delete_reply', $reply->ID ) ) { 
  1906. return; 
  1907.  
  1908. if ( bbp_is_reply_trash( $reply->ID ) ) { 
  1909. $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_reply_trash', 'sub_action' => 'untrash', 'reply_id' => $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-restore-link">' . $r['restore_text'] . '</a>'; 
  1910. } elseif ( EMPTY_TRASH_DAYS ) { 
  1911. $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_reply_trash', 'sub_action' => 'trash', 'reply_id' => $reply->ID ) ), 'trash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-trash-link">' . $r['trash_text'] . '</a>'; 
  1912.  
  1913. if ( bbp_is_reply_trash( $reply->ID ) || !EMPTY_TRASH_DAYS ) { 
  1914. $actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'delete', 'reply_id' => $reply->ID ) ), 'delete-' . $reply->post_type . '_' . $reply->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-reply-delete-link">' . $r['delete_text'] . '</a>'; 
  1915.  
  1916. // Process the admin links 
  1917. $retval = $r['link_before'] . implode( $r['sep'], $actions ) . $r['link_after']; 
  1918.  
  1919. return apply_filters( 'bbp_get_reply_trash_link', $retval, $r ); 
  1920.  
  1921. /** 
  1922. * Output the spam link of the reply 
  1923. * 
  1924. * @since bbPress (r2740) 
  1925. * 
  1926. * @param mixed $args See {@link bbp_get_reply_spam_link()} 
  1927. * @uses bbp_get_reply_spam_link() To get the reply spam link 
  1928. */ 
  1929. function bbp_reply_spam_link( $args = '' ) { 
  1930. echo bbp_get_reply_spam_link( $args ); 
  1931.  
  1932. /** 
  1933. * Return the spam link of the reply 
  1934. * 
  1935. * @since bbPress (r2740) 
  1936. * 
  1937. * @param mixed $args This function supports these arguments: 
  1938. * - id: Reply id 
  1939. * - link_before: HTML before the link 
  1940. * - link_after: HTML after the link 
  1941. * - spam_text: Spam text 
  1942. * - unspam_text: Unspam text 
  1943. * @uses bbp_get_reply_id() To get the reply id 
  1944. * @uses bbp_get_reply() To get the reply 
  1945. * @uses current_user_can() To check if the current user can edit the 
  1946. * reply 
  1947. * @uses bbp_is_reply_spam() To check if the reply is marked as spam 
  1948. * @uses add_query_arg() To add custom args to the url 
  1949. * @uses wp_nonce_url() To nonce the url 
  1950. * @uses esc_url() To escape the url 
  1951. * @uses bbp_get_reply_edit_url() To get the reply edit url 
  1952. * @uses apply_filters() Calls 'bbp_get_reply_spam_link' with the reply 
  1953. * spam link and args 
  1954. * @return string Reply spam link 
  1955. */ 
  1956. function bbp_get_reply_spam_link( $args = '' ) { 
  1957.  
  1958. // Parse arguments against default values 
  1959. $r = bbp_parse_args( $args, array( 
  1960. 'id' => 0,  
  1961. 'link_before' => '',  
  1962. 'link_after' => '',  
  1963. 'spam_text' => esc_html__( 'Spam', 'bbpress' ),  
  1964. 'unspam_text' => esc_html__( 'Unspam', 'bbpress' ) 
  1965. ), 'get_reply_spam_link' ); 
  1966.  
  1967. $reply = bbp_get_reply( bbp_get_reply_id( (int) $r['id'] ) ); 
  1968.  
  1969. if ( empty( $reply ) || !current_user_can( 'moderate', $reply->ID ) ) 
  1970. return; 
  1971.  
  1972. $display = bbp_is_reply_spam( $reply->ID ) ? $r['unspam_text'] : $r['spam_text']; 
  1973. $uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID ) ); 
  1974. $uri = wp_nonce_url( $uri, 'spam-reply_' . $reply->ID ); 
  1975. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-spam-link">' . $display . '</a>' . $r['link_after']; 
  1976.  
  1977. return apply_filters( 'bbp_get_reply_spam_link', $retval, $r ); 
  1978.  
  1979. /** 
  1980. * Move reply link 
  1981. * 
  1982. * Output the move link of the reply 
  1983. * 
  1984. * @since bbPress (r4521) 
  1985. * 
  1986. * @param mixed $args See {@link bbp_get_reply_move_link()} 
  1987. * @uses bbp_get_reply_move_link() To get the reply move link 
  1988. */ 
  1989. function bbp_reply_move_link( $args = '' ) { 
  1990. echo bbp_get_reply_move_link( $args ); 
  1991.  
  1992. /** 
  1993. * Get move reply link 
  1994. * 
  1995. * Return the move link of the reply 
  1996. * 
  1997. * @since bbPress (r4521) 
  1998. * 
  1999. * @param mixed $args This function supports these arguments: 
  2000. * - id: Reply id 
  2001. * - link_before: HTML before the link 
  2002. * - link_after: HTML after the link 
  2003. * - move_text: Move text 
  2004. * - move_title: Move title attribute 
  2005. * @uses bbp_get_reply_id() To get the reply id 
  2006. * @uses bbp_get_reply() To get the reply 
  2007. * @uses current_user_can() To check if the current user can edit the 
  2008. * topic 
  2009. * @uses bbp_get_reply_topic_id() To get the reply topic id 
  2010. * @uses bbp_get_reply_edit_url() To get the reply edit url 
  2011. * @uses add_query_arg() To add custom args to the url 
  2012. * @uses wp_nonce_url() To nonce the url 
  2013. * @uses esc_url() To escape the url 
  2014. * @uses apply_filters() Calls 'bbp_get_reply_move_link' with the reply 
  2015. * move link and args 
  2016. * @return string Reply move link 
  2017. */ 
  2018. function bbp_get_reply_move_link( $args = '' ) { 
  2019.  
  2020. // Parse arguments against default values 
  2021. $r = bbp_parse_args( $args, array( 
  2022. 'id' => 0,  
  2023. 'link_before' => '',  
  2024. 'link_after' => '',  
  2025. 'split_text' => esc_html__( 'Move', 'bbpress' ),  
  2026. 'split_title' => esc_attr__( 'Move this reply', 'bbpress' ) 
  2027. ), 'get_reply_move_link' ); 
  2028.  
  2029. $reply_id = bbp_get_reply_id( $r['id'] ); 
  2030. $topic_id = bbp_get_reply_topic_id( $reply_id ); 
  2031.  
  2032. if ( empty( $reply_id ) || !current_user_can( 'moderate', $topic_id ) ) 
  2033. return; 
  2034.  
  2035. $uri = add_query_arg( array( 
  2036. 'action' => 'move',  
  2037. 'reply_id' => $reply_id 
  2038. ), bbp_get_reply_edit_url( $reply_id ) ); 
  2039.  
  2040. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-reply-move-link">' . $r['split_text'] . '</a>' . $r['link_after']; 
  2041.  
  2042. return apply_filters( 'bbp_get_reply_move_link', $retval, $r ); 
  2043.  
  2044. /** 
  2045. * Split topic link 
  2046. * 
  2047. * Output the split link of the topic (but is bundled with each reply) 
  2048. * 
  2049. * @since bbPress (r2756) 
  2050. * 
  2051. * @param mixed $args See {@link bbp_get_topic_split_link()} 
  2052. * @uses bbp_get_topic_split_link() To get the topic split link 
  2053. */ 
  2054. function bbp_topic_split_link( $args = '' ) { 
  2055. echo bbp_get_topic_split_link( $args ); 
  2056.  
  2057. /** 
  2058. * Get split topic link 
  2059. * 
  2060. * Return the split link of the topic (but is bundled with each reply) 
  2061. * 
  2062. * @since bbPress (r2756) 
  2063. * 
  2064. * @param mixed $args This function supports these arguments: 
  2065. * - id: Reply id 
  2066. * - link_before: HTML before the link 
  2067. * - link_after: HTML after the link 
  2068. * - split_text: Split text 
  2069. * - split_title: Split title attribute 
  2070. * @uses bbp_get_reply_id() To get the reply id 
  2071. * @uses bbp_get_reply() To get the reply 
  2072. * @uses current_user_can() To check if the current user can edit the 
  2073. * topic 
  2074. * @uses bbp_get_reply_topic_id() To get the reply topic id 
  2075. * @uses bbp_get_topic_edit_url() To get the topic edit url 
  2076. * @uses add_query_arg() To add custom args to the url 
  2077. * @uses wp_nonce_url() To nonce the url 
  2078. * @uses esc_url() To escape the url 
  2079. * @uses apply_filters() Calls 'bbp_get_topic_split_link' with the topic 
  2080. * split link and args 
  2081. * @return string Topic split link 
  2082. */ 
  2083. function bbp_get_topic_split_link( $args = '' ) { 
  2084.  
  2085. // Parse arguments against default values 
  2086. $r = bbp_parse_args( $args, array( 
  2087. 'id' => 0,  
  2088. 'link_before' => '',  
  2089. 'link_after' => '',  
  2090. 'split_text' => esc_html__( 'Split', 'bbpress' ),  
  2091. 'split_title' => esc_attr__( 'Split the topic from this reply', 'bbpress' ) 
  2092. ), 'get_topic_split_link' ); 
  2093.  
  2094. $reply_id = bbp_get_reply_id( $r['id'] ); 
  2095. $topic_id = bbp_get_reply_topic_id( $reply_id ); 
  2096.  
  2097. if ( empty( $reply_id ) || !current_user_can( 'moderate', $topic_id ) ) 
  2098. return; 
  2099.  
  2100. $uri = add_query_arg( array( 
  2101. 'action' => 'split',  
  2102. 'reply_id' => $reply_id 
  2103. ), bbp_get_topic_edit_url( $topic_id ) ); 
  2104.  
  2105. $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-topic-split-link">' . $r['split_text'] . '</a>' . $r['link_after']; 
  2106.  
  2107. return apply_filters( 'bbp_get_topic_split_link', $retval, $r ); 
  2108.  
  2109. /** 
  2110. * Output the row class of a reply 
  2111. * 
  2112. * @since bbPress (r2678) 
  2113. * 
  2114. * @param int $reply_id Optional. Reply ID 
  2115. * @param array Extra classes you can pass when calling this function 
  2116. * @uses bbp_get_reply_class() To get the reply class 
  2117. */ 
  2118. function bbp_reply_class( $reply_id = 0, $classes = array() ) { 
  2119. echo bbp_get_reply_class( $reply_id, $classes ); 
  2120. /** 
  2121. * Return the row class of a reply 
  2122. * 
  2123. * @since bbPress (r2678) 
  2124. * 
  2125. * @param int $reply_id Optional. Reply ID 
  2126. * @param array Extra classes you can pass when calling this function 
  2127. * @uses bbp_get_reply_id() To validate the reply id 
  2128. * @uses bbp_get_reply_forum_id() To get the reply's forum id 
  2129. * @uses bbp_get_reply_topic_id() To get the reply's topic id 
  2130. * @uses get_post_class() To get all the classes including ours 
  2131. * @uses apply_filters() Calls 'bbp_get_reply_class' with the classes 
  2132. * @return string Row class of the reply 
  2133. */ 
  2134. function bbp_get_reply_class( $reply_id = 0, $classes = array() ) { 
  2135. $bbp = bbpress(); 
  2136. $reply_id = bbp_get_reply_id( $reply_id ); 
  2137. $count = isset( $bbp->reply_query->current_post ) ? $bbp->reply_query->current_post : 1; 
  2138. $classes = (array) $classes; 
  2139. $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd'; 
  2140. $classes[] = 'bbp-parent-forum-' . bbp_get_reply_forum_id( $reply_id ); 
  2141. $classes[] = 'bbp-parent-topic-' . bbp_get_reply_topic_id( $reply_id ); 
  2142. $classes[] = 'bbp-reply-position-' . bbp_get_reply_position( $reply_id ); 
  2143. $classes[] = 'user-id-' . bbp_get_reply_author_id( $reply_id ); 
  2144. $classes[] = ( bbp_get_reply_author_id( $reply_id ) === bbp_get_topic_author_id( bbp_get_reply_topic_id( $reply_id ) ) ? 'topic-author' : '' ); 
  2145. $classes = array_filter( $classes ); 
  2146. $classes = get_post_class( $classes, $reply_id ); 
  2147. $classes = apply_filters( 'bbp_get_reply_class', $classes, $reply_id ); 
  2148. $retval = 'class="' . implode( ' ', $classes ) . '"'; 
  2149.  
  2150. return $retval; 
  2151.  
  2152. /** 
  2153. * Output the topic pagination count 
  2154. * 
  2155. * @since bbPress (r2519) 
  2156. * 
  2157. * @uses bbp_get_topic_pagination_count() To get the topic pagination count 
  2158. */ 
  2159. function bbp_topic_pagination_count() { 
  2160. echo bbp_get_topic_pagination_count(); 
  2161. /** 
  2162. * Return the topic pagination count 
  2163. * 
  2164. * @since bbPress (r2519) 
  2165. * 
  2166. * @uses bbp_number_format() To format the number value 
  2167. * @uses bbp_show_lead_topic() Are we showing the topic as a lead? 
  2168. * @uses apply_filters() Calls 'bbp_get_topic_pagination_count' with the 
  2169. * pagination count 
  2170. * @return string Topic pagination count 
  2171. */ 
  2172. function bbp_get_topic_pagination_count() { 
  2173. $bbp = bbpress(); 
  2174.  
  2175. // Define local variable(s) 
  2176. $retstr = ''; 
  2177.  
  2178. // Set pagination values 
  2179. $start_num = intval( ( $bbp->reply_query->paged - 1 ) * $bbp->reply_query->posts_per_page ) + 1; 
  2180. $from_num = bbp_number_format( $start_num ); 
  2181. $to_num = bbp_number_format( ( $start_num + ( $bbp->reply_query->posts_per_page - 1 ) > $bbp->reply_query->found_posts ) ? $bbp->reply_query->found_posts : $start_num + ( $bbp->reply_query->posts_per_page - 1 ) ); 
  2182. $total_int = (int) $bbp->reply_query->found_posts; 
  2183. $total = bbp_number_format( $total_int ); 
  2184.  
  2185. // We are threading replies 
  2186. if ( bbp_thread_replies() && bbp_is_single_topic() ) { 
  2187. return; 
  2188. $walker = new BBP_Walker_Reply; 
  2189. $threads = (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ); 
  2190.  
  2191. // Adjust for topic 
  2192. $threads--; 
  2193. $retstr = sprintf( _n( 'Viewing %1$s reply thread', 'Viewing %1$s reply threads', $threads, 'bbbpress' ), bbp_number_format( $threads ) ); 
  2194.  
  2195. // We are not including the lead topic 
  2196. } elseif ( bbp_show_lead_topic() ) { 
  2197.  
  2198. // Several replies in a topic with a single page 
  2199. if ( empty( $to_num ) ) { 
  2200. $retstr = sprintf( _n( 'Viewing %1$s reply', 'Viewing %1$s replies', $total_int, 'bbpress' ), $total ); 
  2201.  
  2202. // Several replies in a topic with several pages 
  2203. } else { 
  2204. $retstr = sprintf( _n( 'Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total ); 
  2205.  
  2206. // We are including the lead topic 
  2207. } else { 
  2208.  
  2209. // Several posts in a topic with a single page 
  2210. if ( empty( $to_num ) ) { 
  2211. $retstr = sprintf( _n( 'Viewing %1$s post', 'Viewing %1$s posts', $total_int, 'bbpress' ), $total ); 
  2212.  
  2213. // Several posts in a topic with several pages 
  2214. } else { 
  2215. $retstr = sprintf( _n( 'Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total ); 
  2216.  
  2217. // Filter and return 
  2218. return apply_filters( 'bbp_get_topic_pagination_count', esc_html( $retstr ) ); 
  2219.  
  2220. /** 
  2221. * Output topic pagination links 
  2222. * 
  2223. * @since bbPress (r2519) 
  2224. * 
  2225. * @uses bbp_get_topic_pagination_links() To get the topic pagination links 
  2226. */ 
  2227. function bbp_topic_pagination_links() { 
  2228. echo bbp_get_topic_pagination_links(); 
  2229. /** 
  2230. * Return topic pagination links 
  2231. * 
  2232. * @since bbPress (r2519) 
  2233. * 
  2234. * @uses apply_filters() Calls 'bbp_get_topic_pagination_links' with the 
  2235. * pagination links 
  2236. * @return string Topic pagination links 
  2237. */ 
  2238. function bbp_get_topic_pagination_links() { 
  2239. $bbp = bbpress(); 
  2240.  
  2241. if ( !isset( $bbp->reply_query->pagination_links ) || empty( $bbp->reply_query->pagination_links ) ) 
  2242. return false; 
  2243.  
  2244. return apply_filters( 'bbp_get_topic_pagination_links', $bbp->reply_query->pagination_links ); 
  2245.  
  2246. /** Forms *********************************************************************/ 
  2247.  
  2248. /** 
  2249. * Output the value of reply content field 
  2250. * 
  2251. * @since bbPress (r31301) 
  2252. * 
  2253. * @uses bbp_get_form_reply_content() To get value of reply content field 
  2254. */ 
  2255. function bbp_form_reply_content() { 
  2256. echo bbp_get_form_reply_content(); 
  2257. /** 
  2258. * Return the value of reply content field 
  2259. * 
  2260. * @since bbPress (r31301) 
  2261. * 
  2262. * @uses bbp_is_reply_edit() To check if it's the reply edit page 
  2263. * @uses apply_filters() Calls 'bbp_get_form_reply_content' with the content 
  2264. * @return string Value of reply content field 
  2265. */ 
  2266. function bbp_get_form_reply_content() { 
  2267.  
  2268. // Get _POST data 
  2269. if ( bbp_is_post_request() && isset( $_POST['bbp_reply_content'] ) ) { 
  2270. $reply_content = stripslashes( $_POST['bbp_reply_content'] ); 
  2271.  
  2272. // Get edit data 
  2273. } elseif ( bbp_is_reply_edit() ) { 
  2274. $reply_content = bbp_get_global_post_field( 'post_content', 'raw' ); 
  2275.  
  2276. // No data 
  2277. } else { 
  2278. $reply_content = ''; 
  2279.  
  2280. return apply_filters( 'bbp_get_form_reply_content', $reply_content ); 
  2281.  
  2282. /** 
  2283. * Output the value of the reply to field 
  2284. * 
  2285. * @since bbPress (r4944) 
  2286. * 
  2287. * @uses bbp_get_form_reply_to() To get value of the reply to field 
  2288. */ 
  2289. function bbp_form_reply_to() { 
  2290. echo bbp_get_form_reply_to(); 
  2291.  
  2292. /** 
  2293. * Return the value of reply to field 
  2294. * 
  2295. * @since bbPress (r4944) 
  2296. * 
  2297. * @uses bbp_get_reply_id() To validate the reply to 
  2298. * @uses apply_filters() Calls 'bbp_get_form_reply_to' with the reply to 
  2299. * @return string Value of reply to field 
  2300. */ 
  2301. function bbp_get_form_reply_to() { 
  2302.  
  2303. // Set initial value 
  2304. $reply_to = 0; 
  2305.  
  2306. // Get $_REQUEST data 
  2307. if ( isset( $_REQUEST['bbp_reply_to'] ) ) { 
  2308. $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] ); 
  2309.  
  2310. // If empty, get from meta 
  2311. if ( empty( $reply_to ) ) { 
  2312. $reply_to = bbp_get_reply_to(); 
  2313.  
  2314. return (int) apply_filters( 'bbp_get_form_reply_to', $reply_to ); 
  2315.  
  2316. /** 
  2317. * Output checked value of reply log edit field 
  2318. * 
  2319. * @since bbPress (r31301) 
  2320. * 
  2321. * @uses bbp_get_form_reply_log_edit() To get the reply log edit value 
  2322. */ 
  2323. function bbp_form_reply_log_edit() { 
  2324. echo bbp_get_form_reply_log_edit(); 
  2325. /** 
  2326. * Return checked value of reply log edit field 
  2327. * 
  2328. * @since bbPress (r31301) 
  2329. * 
  2330. * @uses apply_filters() Calls 'bbp_get_form_reply_log_edit' with the 
  2331. * log edit value 
  2332. * @return string Reply log edit checked value 
  2333. */ 
  2334. function bbp_get_form_reply_log_edit() { 
  2335.  
  2336. // Get _POST data 
  2337. if ( bbp_is_post_request() && isset( $_POST['bbp_log_reply_edit'] ) ) { 
  2338. $reply_revision = $_POST['bbp_log_reply_edit']; 
  2339.  
  2340. // No data 
  2341. } else { 
  2342. $reply_revision = 1; 
  2343.  
  2344. return apply_filters( 'bbp_get_form_reply_log_edit', checked( $reply_revision, true, false ) ); 
  2345.  
  2346. /** 
  2347. * Output the value of the reply edit reason 
  2348. * 
  2349. * @since bbPress (r31301) 
  2350. * 
  2351. * @uses bbp_get_form_reply_edit_reason() To get the reply edit reason value 
  2352. */ 
  2353. function bbp_form_reply_edit_reason() { 
  2354. echo bbp_get_form_reply_edit_reason(); 
  2355. /** 
  2356. * Return the value of the reply edit reason 
  2357. * 
  2358. * @since bbPress (r31301) 
  2359. * 
  2360. * @uses apply_filters() Calls 'bbp_get_form_reply_edit_reason' with the 
  2361. * reply edit reason value 
  2362. * @return string Reply edit reason value 
  2363. */ 
  2364. function bbp_get_form_reply_edit_reason() { 
  2365.  
  2366. // Get _POST data 
  2367. if ( bbp_is_post_request() && isset( $_POST['bbp_reply_edit_reason'] ) ) { 
  2368. $reply_edit_reason = $_POST['bbp_reply_edit_reason']; 
  2369.  
  2370. // No data 
  2371. } else { 
  2372. $reply_edit_reason = ''; 
  2373.  
  2374. return apply_filters( 'bbp_get_form_reply_edit_reason', esc_attr( $reply_edit_reason ) ); 
.