PageRenderTime 68ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full 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( '…

Large files files are truncated, but you can click here to view the full file