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

https://bitbucket.org/Thane2376/death-edge.ru · PHP · 2539 lines · 933 code · 326 blank · 1280 comment · 168 complexity · 493d29558111cfa5d81e2c07b2aa8037 MD5 · raw file

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