PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 4005 lines | 1469 code | 528 blank | 2008 comment | 245 complexity | e050cd312edaf2a6e40171f4c0b4bf6f 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 Topic 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. * Output the unique id of the custom post type for topics
  13. *
  14. * @since bbPress (r2857)
  15. *
  16. * @uses bbp_get_topic_post_type() To get the topic post type
  17. */
  18. function bbp_topic_post_type() {
  19. echo bbp_get_topic_post_type();
  20. }
  21. /**
  22. * Return the unique id of the custom post type for topics
  23. *
  24. * @since bbPress (r2857)
  25. *
  26. * @uses apply_filters() Calls 'bbp_get_topic_post_type' with the topic
  27. * post type id
  28. * @return string The unique topic post type id
  29. */
  30. function bbp_get_topic_post_type() {
  31. return apply_filters( 'bbp_get_topic_post_type', bbpress()->topic_post_type );
  32. }
  33. /**
  34. * Return array of labels used by the topic post type
  35. *
  36. * @since bbPress (r5129)
  37. *
  38. * @return array
  39. */
  40. function bbp_get_topic_post_type_labels() {
  41. return apply_filters( 'bbp_get_topic_post_type_labels', array(
  42. 'name' => __( 'Topics', 'bbpress' ),
  43. 'menu_name' => __( 'Topics', 'bbpress' ),
  44. 'singular_name' => __( 'Topic', 'bbpress' ),
  45. 'all_items' => __( 'All Topics', 'bbpress' ),
  46. 'add_new' => __( 'New Topic', 'bbpress' ),
  47. 'add_new_item' => __( 'Create New Topic', 'bbpress' ),
  48. 'edit' => __( 'Edit', 'bbpress' ),
  49. 'edit_item' => __( 'Edit Topic', 'bbpress' ),
  50. 'new_item' => __( 'New Topic', 'bbpress' ),
  51. 'view' => __( 'View Topic', 'bbpress' ),
  52. 'view_item' => __( 'View Topic', 'bbpress' ),
  53. 'search_items' => __( 'Search Topics', 'bbpress' ),
  54. 'not_found' => __( 'No topics found', 'bbpress' ),
  55. 'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),
  56. 'parent_item_colon' => __( 'Forum:', 'bbpress' )
  57. ) );
  58. }
  59. /**
  60. * Return array of topic post type rewrite settings
  61. *
  62. * @since bbPress (r5129)
  63. *
  64. * @return array
  65. */
  66. function bbp_get_topic_post_type_rewrite() {
  67. return apply_filters( 'bbp_get_topic_post_type_rewrite', array(
  68. 'slug' => bbp_get_topic_slug(),
  69. 'with_front' => false
  70. ) );
  71. }
  72. /**
  73. * Return array of features the topic post type supports
  74. *
  75. * @since bbPress (r5129)
  76. *
  77. * @return array
  78. */
  79. function bbp_get_topic_post_type_supports() {
  80. return apply_filters( 'bbp_get_topic_post_type_supports', array(
  81. 'title',
  82. 'editor',
  83. 'revisions'
  84. ) );
  85. }
  86. /**
  87. * The plugin version of bbPress comes with two topic display options:
  88. * - Traditional: Topics are included in the reply loop (default)
  89. * - New Style: Topics appear as "lead" posts, ahead of replies
  90. *
  91. * @since bbPress (r2954)
  92. * @param $show_lead Optional. Default false
  93. * @return bool Yes if the topic appears as a lead, otherwise false
  94. */
  95. function bbp_show_lead_topic( $show_lead = false ) {
  96. // Never separate the lead topic in feeds
  97. if ( is_feed() )
  98. return false;
  99. return (bool) apply_filters( 'bbp_show_lead_topic', (bool) $show_lead );
  100. }
  101. /** Topic Loop ****************************************************************/
  102. /**
  103. * The main topic loop. WordPress makes this easy for us
  104. *
  105. * @since bbPress (r2485)
  106. *
  107. * @param mixed $args All the arguments supported by {@link WP_Query}
  108. * @uses current_user_can() To check if the current user can edit other's topics
  109. * @uses bbp_get_topic_post_type() To get the topic post type
  110. * @uses WP_Query To make query and get the topics
  111. * @uses is_page() To check if it's a page
  112. * @uses bbp_is_single_forum() To check if it's a forum
  113. * @uses bbp_get_forum_id() To get the forum id
  114. * @uses bbp_get_paged() To get the current page value
  115. * @uses bbp_get_super_stickies() To get the super stickies
  116. * @uses bbp_get_stickies() To get the forum stickies
  117. * @uses wpdb::get_results() To execute our query and get the results
  118. * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
  119. * @uses get_permalink() To get the permalink
  120. * @uses add_query_arg() To add custom args to the url
  121. * @uses apply_filters() Calls 'bbp_topics_pagination' with the pagination args
  122. * @uses paginate_links() To paginate the links
  123. * @uses apply_filters() Calls 'bbp_has_topics' with
  124. * bbPres::topic_query::have_posts()
  125. * and bbPres::topic_query
  126. * @return object Multidimensional array of topic information
  127. */
  128. function bbp_has_topics( $args = '' ) {
  129. global $wp_rewrite;
  130. /** Defaults **************************************************************/
  131. // Other defaults
  132. $default_topic_search = !empty( $_REQUEST['ts'] ) ? $_REQUEST['ts'] : false;
  133. $default_show_stickies = (bool) ( bbp_is_single_forum() || bbp_is_topic_archive() ) && ( false === $default_topic_search );
  134. $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
  135. // Default argument array
  136. $default = array(
  137. 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics
  138. 'post_parent' => $default_post_parent, // Forum ID
  139. 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time
  140. 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
  141. 'order' => 'DESC', // 'ASC', 'DESC'
  142. 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page
  143. 'paged' => bbp_get_paged(), // Page Number
  144. 's' => $default_topic_search, // Topic Search
  145. 'show_stickies' => $default_show_stickies, // Ignore sticky topics?
  146. 'max_num_pages' => false, // Maximum number of pages to show
  147. );
  148. // What are the default allowed statuses (based on user caps)
  149. if ( bbp_get_view_all() ) {
  150. // Default view=all statuses
  151. $post_statuses = array(
  152. bbp_get_public_status_id(),
  153. bbp_get_closed_status_id(),
  154. bbp_get_spam_status_id(),
  155. bbp_get_trash_status_id()
  156. );
  157. // Add support for private status
  158. if ( current_user_can( 'read_private_topics' ) ) {
  159. $post_statuses[] = bbp_get_private_status_id();
  160. }
  161. // Join post statuses together
  162. $default['post_status'] = implode( ',', $post_statuses );
  163. // Lean on the 'perm' query var value of 'readable' to provide statuses
  164. } else {
  165. $default['perm'] = 'readable';
  166. }
  167. // Maybe query for topic tags
  168. if ( bbp_is_topic_tag() ) {
  169. $default['term'] = bbp_get_topic_tag_slug();
  170. $default['taxonomy'] = bbp_get_topic_tag_tax_id();
  171. }
  172. /** Setup *****************************************************************/
  173. // Parse arguments against default values
  174. $r = bbp_parse_args( $args, $default, 'has_topics' );
  175. // Get bbPress
  176. $bbp = bbpress();
  177. // Call the query
  178. $bbp->topic_query = new WP_Query( $r );
  179. // Set post_parent back to 0 if originally set to 'any'
  180. if ( 'any' === $r['post_parent'] )
  181. $r['post_parent'] = 0;
  182. // Limited the number of pages shown
  183. if ( !empty( $r['max_num_pages'] ) )
  184. $bbp->topic_query->max_num_pages = $r['max_num_pages'];
  185. /** Stickies **************************************************************/
  186. // Put sticky posts at the top of the posts array
  187. if ( !empty( $r['show_stickies'] ) && $r['paged'] <= 1 ) {
  188. // Get super stickies and stickies in this forum
  189. $stickies = bbp_get_super_stickies();
  190. // Get stickies for current forum
  191. if ( !empty( $r['post_parent'] ) ) {
  192. $stickies = array_merge( $stickies, bbp_get_stickies( $r['post_parent'] ) );
  193. }
  194. // Remove any duplicate stickies
  195. $stickies = array_unique( $stickies );
  196. // We have stickies
  197. if ( is_array( $stickies ) && !empty( $stickies ) ) {
  198. // Start the offset at -1 so first sticky is at correct 0 offset
  199. $sticky_offset = -1;
  200. // Loop over topics and relocate stickies to the front.
  201. foreach ( $stickies as $sticky_index => $sticky_ID ) {
  202. // Get the post offset from the posts array
  203. $post_offsets = wp_filter_object_list( $bbp->topic_query->posts, array( 'ID' => $sticky_ID ), 'OR', 'ID' );
  204. // Continue if no post offsets
  205. if ( empty( $post_offsets ) ) {
  206. continue;
  207. }
  208. // Loop over posts in current query and splice them into position
  209. foreach ( array_keys( $post_offsets ) as $post_offset ) {
  210. $sticky_offset++;
  211. $sticky = $bbp->topic_query->posts[$post_offset];
  212. // Remove sticky from current position
  213. array_splice( $bbp->topic_query->posts, $post_offset, 1 );
  214. // Move to front, after other stickies
  215. array_splice( $bbp->topic_query->posts, $sticky_offset, 0, array( $sticky ) );
  216. // Cleanup
  217. unset( $stickies[$sticky_index] );
  218. unset( $sticky );
  219. }
  220. // Cleanup
  221. unset( $post_offsets );
  222. }
  223. // Cleanup
  224. unset( $sticky_offset );
  225. // If any posts have been excluded specifically, Ignore those that are sticky.
  226. if ( !empty( $stickies ) && !empty( $r['post__not_in'] ) ) {
  227. $stickies = array_diff( $stickies, $r['post__not_in'] );
  228. }
  229. // Fetch sticky posts that weren't in the query results
  230. if ( !empty( $stickies ) ) {
  231. // Query to use in get_posts to get sticky posts
  232. $sticky_query = array(
  233. 'post_type' => bbp_get_topic_post_type(),
  234. 'post_parent' => 'any',
  235. 'meta_key' => '_bbp_last_active_time',
  236. 'orderby' => 'meta_value',
  237. 'order' => 'DESC',
  238. 'include' => $stickies
  239. );
  240. // Cleanup
  241. unset( $stickies );
  242. // Conditionally exclude private/hidden forum ID's
  243. $exclude_forum_ids = bbp_exclude_forum_ids( 'array' );
  244. if ( ! empty( $exclude_forum_ids ) ) {
  245. $sticky_query['post_parent__not_in'] = $exclude_forum_ids;
  246. }
  247. // What are the default allowed statuses (based on user caps)
  248. if ( bbp_get_view_all() ) {
  249. $sticky_query['post_status'] = $r['post_status'];
  250. // Lean on the 'perm' query var value of 'readable' to provide statuses
  251. } else {
  252. $sticky_query['post_status'] = $r['perm'];
  253. }
  254. // Get all stickies
  255. $sticky_posts = get_posts( $sticky_query );
  256. if ( !empty( $sticky_posts ) ) {
  257. // Get a count of the visible stickies
  258. $sticky_count = count( $sticky_posts );
  259. // Merge the stickies topics with the query topics .
  260. $bbp->topic_query->posts = array_merge( $sticky_posts, $bbp->topic_query->posts );
  261. // Adjust loop and counts for new sticky positions
  262. $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count;
  263. $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count;
  264. // Cleanup
  265. unset( $sticky_posts );
  266. }
  267. }
  268. }
  269. }
  270. // If no limit to posts per page, set it to the current post_count
  271. if ( -1 === $r['posts_per_page'] )
  272. $r['posts_per_page'] = $bbp->topic_query->post_count;
  273. // Add pagination values to query object
  274. $bbp->topic_query->posts_per_page = $r['posts_per_page'];
  275. $bbp->topic_query->paged = $r['paged'];
  276. // Only add pagination if query returned results
  277. if ( ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page ) {
  278. // Limit the number of topics shown based on maximum allowed pages
  279. if ( ( !empty( $r['max_num_pages'] ) ) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count )
  280. $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count;
  281. // If pretty permalinks are enabled, make our pagination pretty
  282. if ( $wp_rewrite->using_permalinks() ) {
  283. // User's topics
  284. if ( bbp_is_single_user_topics() ) {
  285. $base = bbp_get_user_topics_created_url( bbp_get_displayed_user_id() );
  286. // User's favorites
  287. } elseif ( bbp_is_favorites() ) {
  288. $base = bbp_get_favorites_permalink( bbp_get_displayed_user_id() );
  289. // User's subscriptions
  290. } elseif ( bbp_is_subscriptions() ) {
  291. $base = bbp_get_subscriptions_permalink( bbp_get_displayed_user_id() );
  292. // Root profile page
  293. } elseif ( bbp_is_single_user() ) {
  294. $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() );
  295. // View
  296. } elseif ( bbp_is_single_view() ) {
  297. $base = bbp_get_view_url();
  298. // Topic tag
  299. } elseif ( bbp_is_topic_tag() ) {
  300. $base = bbp_get_topic_tag_link();
  301. // Page or single post
  302. } elseif ( is_page() || is_single() ) {
  303. $base = get_permalink();
  304. // Forum archive
  305. } elseif ( bbp_is_forum_archive() ) {
  306. $base = bbp_get_forums_url();
  307. // Topic archive
  308. } elseif ( bbp_is_topic_archive() ) {
  309. $base = bbp_get_topics_url();
  310. // Default
  311. } else {
  312. $base = get_permalink( (int) $r['post_parent'] );
  313. }
  314. // Use pagination base
  315. $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
  316. // Unpretty pagination
  317. } else {
  318. $base = add_query_arg( 'paged', '%#%' );
  319. }
  320. // Pagination settings with filter
  321. $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array (
  322. 'base' => $base,
  323. 'format' => '',
  324. 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil( (int) $bbp->topic_query->found_posts / (int) $r['posts_per_page'] ),
  325. 'current' => (int) $bbp->topic_query->paged,
  326. 'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
  327. 'next_text' => is_rtl() ? '&larr;' : '&rarr;',
  328. 'mid_size' => 1
  329. ) );
  330. // Add pagination to query object
  331. $bbp->topic_query->pagination_links = paginate_links( $bbp_topic_pagination );
  332. // Remove first page from pagination
  333. $bbp->topic_query->pagination_links = str_replace( $wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links );
  334. }
  335. // Return object
  336. return apply_filters( 'bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query );
  337. }
  338. /**
  339. * Whether there are more topics available in the loop
  340. *
  341. * @since bbPress (r2485)
  342. *
  343. * @uses WP_Query bbPress::topic_query::have_posts()
  344. * @return object Topic information
  345. */
  346. function bbp_topics() {
  347. // Put into variable to check against next
  348. $have_posts = bbpress()->topic_query->have_posts();
  349. // Reset the post data when finished
  350. if ( empty( $have_posts ) )
  351. wp_reset_postdata();
  352. return $have_posts;
  353. }
  354. /**
  355. * Loads up the current topic in the loop
  356. *
  357. * @since bbPress (r2485)
  358. *
  359. * @uses WP_Query bbPress::topic_query::the_post()
  360. * @return object Topic information
  361. */
  362. function bbp_the_topic() {
  363. return bbpress()->topic_query->the_post();
  364. }
  365. /**
  366. * Output the topic id
  367. *
  368. * @since bbPress (r2485)
  369. *
  370. * @uses bbp_get_topic_id() To get the topic id
  371. */
  372. function bbp_topic_id( $topic_id = 0) {
  373. echo bbp_get_topic_id( $topic_id );
  374. }
  375. /**
  376. * Return the topic id
  377. *
  378. * @since bbPress (r2485)
  379. *
  380. * @param $topic_id Optional. Used to check emptiness
  381. * @uses bbPress::topic_query::post::ID To get the topic id
  382. * @uses bbp_is_topic() To check if the search result is a topic
  383. * @uses bbp_is_single_topic() To check if it's a topic page
  384. * @uses bbp_is_topic_edit() To check if it's a topic edit page
  385. * @uses bbp_is_single_reply() To check if it it's a reply page
  386. * @uses bbp_is_reply_edit() To check if it's a reply edit page
  387. * @uses bbp_get_reply_topic_edit() To get the reply topic id
  388. * @uses get_post_field() To get the post's post type
  389. * @uses WP_Query::post::ID To get the topic id
  390. * @uses bbp_get_topic_post_type() To get the topic post type
  391. * @uses apply_filters() Calls 'bbp_get_topic_id' with the topic id and
  392. * supplied topic id
  393. * @return int The topic id
  394. */
  395. function bbp_get_topic_id( $topic_id = 0 ) {
  396. global $wp_query;
  397. $bbp = bbpress();
  398. // Easy empty checking
  399. if ( !empty( $topic_id ) && is_numeric( $topic_id ) ) {
  400. $bbp_topic_id = $topic_id;
  401. // Currently inside a topic loop
  402. } elseif ( !empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) ) {
  403. $bbp_topic_id = $bbp->topic_query->post->ID;
  404. // Currently inside a search loop
  405. } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) {
  406. $bbp_topic_id = $bbp->search_query->post->ID;
  407. // Currently viewing/editing a topic, likely alone
  408. } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && !empty( $bbp->current_topic_id ) ) {
  409. $bbp_topic_id = $bbp->current_topic_id;
  410. // Currently viewing/editing a topic, likely in a loop
  411. } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) {
  412. $bbp_topic_id = $wp_query->post->ID;
  413. // Currently viewing/editing a reply
  414. } elseif ( bbp_is_single_reply() || bbp_is_reply_edit() ) {
  415. $bbp_topic_id = bbp_get_reply_topic_id();
  416. // Fallback
  417. } else {
  418. $bbp_topic_id = 0;
  419. }
  420. return (int) apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id );
  421. }
  422. /**
  423. * Gets a topic
  424. *
  425. * @since bbPress (r2787)
  426. *
  427. * @param int|object $topic Topic id or topic object
  428. * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
  429. * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
  430. * @uses get_post() To get the topic
  431. * @uses apply_filters() Calls 'bbp_get_topic' with the topic, output type and
  432. * sanitation filter
  433. * @return mixed Null if error or topic (in specified form) if success
  434. */
  435. function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) {
  436. // Use topic ID
  437. if ( empty( $topic ) || is_numeric( $topic ) )
  438. $topic = bbp_get_topic_id( $topic );
  439. // Attempt to load the topic
  440. $topic = get_post( $topic, OBJECT, $filter );
  441. if ( empty( $topic ) )
  442. return $topic;
  443. // Bail if post_type is not a topic
  444. if ( $topic->post_type !== bbp_get_topic_post_type() )
  445. return null;
  446. // Tweak the data type to return
  447. if ( $output === OBJECT ) {
  448. return $topic;
  449. } elseif ( $output === ARRAY_A ) {
  450. $_topic = get_object_vars( $topic );
  451. return $_topic;
  452. } elseif ( $output === ARRAY_N ) {
  453. $_topic = array_values( get_object_vars( $topic ) );
  454. return $_topic;
  455. }
  456. return apply_filters( 'bbp_get_topic', $topic, $output, $filter );
  457. }
  458. /**
  459. * Output the link to the topic in the topic loop
  460. *
  461. * @since bbPress (r2485)
  462. *
  463. * @param int $topic_id Optional. Topic id
  464. * @param $string $redirect_to Optional. Pass a redirect value for use with
  465. * shortcodes and other fun things.
  466. * @uses bbp_get_topic_permalink() To get the topic permalink
  467. */
  468. function bbp_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
  469. echo esc_url( bbp_get_topic_permalink( $topic_id, $redirect_to ) );
  470. }
  471. /**
  472. * Return the link to the topic
  473. *
  474. * @since bbPress (r2485)
  475. *
  476. * @param int $topic_id Optional. Topic id
  477. * @param $string $redirect_to Optional. Pass a redirect value for use with
  478. * shortcodes and other fun things.
  479. * @uses bbp_get_topic_id() To get the topic id
  480. * @uses get_permalink() To get the topic permalink
  481. * @uses esc_url_raw() To clean the redirect_to url
  482. * @uses apply_filters() Calls 'bbp_get_topic_permalink' with the link
  483. * and topic id
  484. * @return string Permanent link to topic
  485. */
  486. function bbp_get_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
  487. $topic_id = bbp_get_topic_id( $topic_id );
  488. // Use the redirect address
  489. if ( !empty( $redirect_to ) ) {
  490. $topic_permalink = esc_url_raw( $redirect_to );
  491. // Use the topic permalink
  492. } else {
  493. $topic_permalink = get_permalink( $topic_id );
  494. }
  495. return apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $topic_id );
  496. }
  497. /**
  498. * Output the title of the topic
  499. *
  500. * @since bbPress (r2485)
  501. *
  502. * @param int $topic_id Optional. Topic id
  503. * @uses bbp_get_topic_title() To get the topic title
  504. */
  505. function bbp_topic_title( $topic_id = 0 ) {
  506. echo bbp_get_topic_title( $topic_id );
  507. }
  508. /**
  509. * Return the title of the topic
  510. *
  511. * @since bbPress (r2485)
  512. *
  513. * @param int $topic_id Optional. Topic id
  514. * @uses bbp_get_topic_id() To get the topic id
  515. * @uses get_the_title() To get the title
  516. * @uses apply_filters() Calls 'bbp_get_topic_title' with the title and
  517. * topic id
  518. * @return string Title of topic
  519. */
  520. function bbp_get_topic_title( $topic_id = 0 ) {
  521. $topic_id = bbp_get_topic_id( $topic_id );
  522. $title = get_the_title( $topic_id );
  523. return apply_filters( 'bbp_get_topic_title', $title, $topic_id );
  524. }
  525. /**
  526. * Output the topic archive title
  527. *
  528. * @since bbPress (r3249)
  529. *
  530. * @param string $title Default text to use as title
  531. */
  532. function bbp_topic_archive_title( $title = '' ) {
  533. echo bbp_get_topic_archive_title( $title );
  534. }
  535. /**
  536. * Return the topic archive title
  537. *
  538. * @since bbPress (r3249)
  539. *
  540. * @param string $title Default text to use as title
  541. *
  542. * @uses bbp_get_page_by_path() Check if page exists at root path
  543. * @uses get_the_title() Use the page title at the root path
  544. * @uses get_post_type_object() Load the post type object
  545. * @uses bbp_get_topic_post_type() Get the topic post type ID
  546. * @uses get_post_type_labels() Get labels for topic post type
  547. * @uses apply_filters() Allow output to be manipulated
  548. *
  549. * @return string The topic archive title
  550. */
  551. function bbp_get_topic_archive_title( $title = '' ) {
  552. // If no title was passed
  553. if ( empty( $title ) ) {
  554. // Set root text to page title
  555. $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );
  556. if ( !empty( $page ) ) {
  557. $title = get_the_title( $page->ID );
  558. // Default to topic post type name label
  559. } else {
  560. $tto = get_post_type_object( bbp_get_topic_post_type() );
  561. $title = $tto->labels->name;
  562. }
  563. }
  564. return apply_filters( 'bbp_get_topic_archive_title', $title );
  565. }
  566. /**
  567. * Output the content of the topic
  568. *
  569. * @since bbPress (r2780)
  570. *
  571. * @param int $topic_id Optional. Topic id
  572. * @uses bbp_get_topic_content() To get the topic content
  573. */
  574. function bbp_topic_content( $topic_id = 0 ) {
  575. echo bbp_get_topic_content( $topic_id );
  576. }
  577. /**
  578. * Return the content of the topic
  579. *
  580. * @since bbPress (r2780)
  581. *
  582. * @param int $topic_id Optional. Topic id
  583. * @uses bbp_get_topic_id() To get the topic id
  584. * @uses post_password_required() To check if the topic requires pass
  585. * @uses get_the_password_form() To get the password form
  586. * @uses get_post_field() To get the content post field
  587. * @uses apply_filters() Calls 'bbp_get_topic_content' with the content
  588. * and topic id
  589. * @return string Content of the topic
  590. */
  591. function bbp_get_topic_content( $topic_id = 0 ) {
  592. $topic_id = bbp_get_topic_id( $topic_id );
  593. // Check if password is required
  594. if ( post_password_required( $topic_id ) )
  595. return get_the_password_form();
  596. $content = get_post_field( 'post_content', $topic_id );
  597. return apply_filters( 'bbp_get_topic_content', $content, $topic_id );
  598. }
  599. /**
  600. * Output the excerpt of the topic
  601. *
  602. * @since bbPress (r2780)
  603. *
  604. * @param int $topic_id Optional. Topic id
  605. * @param int $length Optional. Length of the excerpt. Defaults to 100 letters
  606. * @uses bbp_get_topic_excerpt() To get the topic excerpt
  607. */
  608. function bbp_topic_excerpt( $topic_id = 0, $length = 100 ) {
  609. echo bbp_get_topic_excerpt( $topic_id, $length );
  610. }
  611. /**
  612. * Return the excerpt of the topic
  613. *
  614. * @since bbPress (r2780)
  615. *
  616. * @param int $topic_id Optional. topic id
  617. * @param int $length Optional. Length of the excerpt. Defaults to 100
  618. * letters
  619. * @uses bbp_get_topic_id() To get the topic id
  620. * @uses get_post_field() To get the excerpt
  621. * @uses bbp_get_topic_content() To get the topic content
  622. * @uses apply_filters() Calls 'bbp_get_topic_excerpt' with the excerpt,
  623. * topic id and length
  624. * @return string topic Excerpt
  625. */
  626. function bbp_get_topic_excerpt( $topic_id = 0, $length = 100 ) {
  627. $topic_id = bbp_get_topic_id( $topic_id );
  628. $length = (int) $length;
  629. $excerpt = get_post_field( 'post_excerpt', $topic_id );
  630. if ( empty( $excerpt ) ) {
  631. $excerpt = bbp_get_topic_content( $topic_id );
  632. }
  633. $excerpt = trim( strip_tags( $excerpt ) );
  634. // Multibyte support
  635. if ( function_exists( 'mb_strlen' ) ) {
  636. $excerpt_length = mb_strlen( $excerpt );
  637. } else {
  638. $excerpt_length = strlen( $excerpt );
  639. }
  640. if ( !empty( $length ) && ( $excerpt_length > $length ) ) {
  641. $excerpt = substr( $excerpt, 0, $length - 1 );
  642. $excerpt .= '&hellip;';
  643. }
  644. return apply_filters( 'bbp_get_topic_excerpt', $excerpt, $topic_id, $length );
  645. }
  646. /**
  647. * Output the post date and time of a topic
  648. *
  649. * @since bbPress (r4155)
  650. *
  651. * @param int $topic_id Optional. Topic id.
  652. * @param bool $humanize Optional. Humanize output using time_since
  653. * @param bool $gmt Optional. Use GMT
  654. * @uses bbp_get_topic_post_date() to get the output
  655. */
  656. function bbp_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
  657. echo bbp_get_topic_post_date( $topic_id, $humanize, $gmt );
  658. }
  659. /**
  660. * Return the post date and time of a topic
  661. *
  662. * @since bbPress (r4155)
  663. *
  664. * @param int $topic_id Optional. Topic id.
  665. * @param bool $humanize Optional. Humanize output using time_since
  666. * @param bool $gmt Optional. Use GMT
  667. * @uses bbp_get_topic_id() To get the topic id
  668. * @uses get_post_time() to get the topic post time
  669. * @uses bbp_get_time_since() to maybe humanize the topic post time
  670. * @return string
  671. */
  672. function bbp_get_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
  673. $topic_id = bbp_get_topic_id( $topic_id );
  674. // 4 days, 4 hours ago
  675. if ( !empty( $humanize ) ) {
  676. $gmt_s = !empty( $gmt ) ? 'U' : 'G';
  677. $date = get_post_time( $gmt_s, $gmt, $topic_id );
  678. $time = false; // For filter below
  679. $result = bbp_get_time_since( $date );
  680. // August 4, 2012 at 2:37 pm
  681. } else {
  682. $date = get_post_time( get_option( 'date_format' ), $gmt, $topic_id, true );
  683. $time = get_post_time( get_option( 'time_format' ), $gmt, $topic_id, true );
  684. $result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time );
  685. }
  686. return apply_filters( 'bbp_get_topic_post_date', $result, $topic_id, $humanize, $gmt, $date, $time );
  687. }
  688. /**
  689. * Output pagination links of a topic within the topic loop
  690. *
  691. * @since bbPress (r2966)
  692. *
  693. * @param mixed $args See {@link bbp_get_topic_pagination()}
  694. * @uses bbp_get_topic_pagination() To get the topic pagination links
  695. */
  696. function bbp_topic_pagination( $args = '' ) {
  697. echo bbp_get_topic_pagination( $args );
  698. }
  699. /**
  700. * Returns pagination links of a topic within the topic loop
  701. *
  702. * @since bbPress (r2966)
  703. *
  704. * @param mixed $args This function supports these arguments:
  705. * - topic_id: Topic id
  706. * - before: Before the links
  707. * - after: After the links
  708. * @uses bbp_get_topic_id() To get the topic id
  709. * @uses WP_Rewrite::using_permalinks() To check if the blog is using
  710. * permalinks
  711. * @uses user_trailingslashit() To add a trailing slash
  712. * @uses trailingslashit() To add a trailing slash
  713. * @uses get_permalink() To get the permalink of the topic
  714. * @uses add_query_arg() To add query args
  715. * @uses bbp_get_topic_reply_count() To get topic reply count
  716. * @uses bbp_show_topic_lead() Are we showing the topic as a lead?
  717. * @uses get_option() To get replies per page option
  718. * @uses paginate_links() To paginate the links
  719. * @uses apply_filters() Calls 'bbp_get_topic_pagination' with the links
  720. * and arguments
  721. * @return string Pagination links
  722. */
  723. function bbp_get_topic_pagination( $args = '' ) {
  724. global $wp_rewrite;
  725. // Bail if threading replies
  726. if ( bbp_thread_replies() ) {
  727. return;
  728. }
  729. // Parse arguments against default values
  730. $r = bbp_parse_args( $args, array(
  731. 'topic_id' => bbp_get_topic_id(),
  732. 'before' => '<span class="bbp-topic-pagination">',
  733. 'after' => '</span>',
  734. ), 'get_topic_pagination' );
  735. // If pretty permalinks are enabled, make our pagination pretty
  736. if ( $wp_rewrite->using_permalinks() ) {
  737. $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
  738. } else {
  739. $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) );
  740. }
  741. // Get total and add 1 if topic is included in the reply loop
  742. $total = bbp_get_topic_reply_count( $r['topic_id'], true );
  743. // Bump if topic is in loop
  744. if ( !bbp_show_lead_topic() )
  745. $total++;
  746. // Pagination settings
  747. $pagination = array(
  748. 'base' => $base,
  749. 'format' => '',
  750. 'total' => ceil( (int) $total / (int) bbp_get_replies_per_page() ),
  751. 'current' => 0,
  752. 'prev_next' => false,
  753. 'mid_size' => 2,
  754. 'end_size' => 3,
  755. 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
  756. );
  757. // Add pagination to query object
  758. $pagination_links = paginate_links( $pagination );
  759. if ( !empty( $pagination_links ) ) {
  760. // Remove first page from pagination
  761. if ( $wp_rewrite->using_permalinks() ) {
  762. $pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $pagination_links );
  763. } else {
  764. $pagination_links = str_replace( '&#038;paged=1', '', $pagination_links );
  765. }
  766. // Add before and after to pagination links
  767. $pagination_links = $r['before'] . $pagination_links . $r['after'];
  768. }
  769. return apply_filters( 'bbp_get_topic_pagination', $pagination_links, $args );
  770. }
  771. /**
  772. * Append revisions to the topic content
  773. *
  774. * @since bbPress (r2782)
  775. *
  776. * @param string $content Optional. Content to which we need to append the revisions to
  777. * @param int $topic_id Optional. Topic id
  778. * @uses bbp_get_topic_revision_log() To get the topic revision log
  779. * @uses apply_filters() Calls 'bbp_topic_append_revisions' with the processed
  780. * content, original content and topic id
  781. * @return string Content with the revisions appended
  782. */
  783. function bbp_topic_content_append_revisions( $content = '', $topic_id = 0 ) {
  784. // Bail if in admin or feed
  785. if ( is_admin() || is_feed() )
  786. return;
  787. // Validate the ID
  788. $topic_id = bbp_get_topic_id( $topic_id );
  789. return apply_filters( 'bbp_topic_append_revisions', $content . bbp_get_topic_revision_log( $topic_id ), $content, $topic_id );
  790. }
  791. /**
  792. * Output the revision log of the topic
  793. *
  794. * @since bbPress (r2782)
  795. *
  796. * @param int $topic_id Optional. Topic id
  797. * @uses bbp_get_topic_revision_log() To get the topic revision log
  798. */
  799. function bbp_topic_revision_log( $topic_id = 0 ) {
  800. echo bbp_get_topic_revision_log( $topic_id );
  801. }
  802. /**
  803. * Return the formatted revision log of the topic
  804. *
  805. * @since bbPress (r2782)
  806. *
  807. * @param int $topic_id Optional. Topic id
  808. * @uses bbp_get_topic_id() To get the topic id
  809. * @uses bbp_get_topic_revisions() To get the topic revisions
  810. * @uses bbp_get_topic_raw_revision_log() To get the raw revision log
  811. * @uses bbp_get_topic_author_display_name() To get the topic author
  812. * @uses bbp_get_author_link() To get the topic author link
  813. * @uses bbp_convert_date() To convert the date
  814. * @uses bbp_get_time_since() To get the time in since format
  815. * @uses apply_filters() Calls 'bbp_get_topic_revision_log' with the
  816. * log and topic id
  817. * @return string Revision log of the topic
  818. */
  819. function bbp_get_topic_revision_log( $topic_id = 0 ) {
  820. // Create necessary variables
  821. $topic_id = bbp_get_topic_id( $topic_id );
  822. $revision_log = bbp_get_topic_raw_revision_log( $topic_id );
  823. if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) )
  824. return false;
  825. $revisions = bbp_get_topic_revisions( $topic_id );
  826. if ( empty( $revisions ) )
  827. return false;
  828. $r = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '" class="bbp-topic-revision-log">' . "\n\n";
  829. // Loop through revisions
  830. foreach ( (array) $revisions as $revision ) {
  831. if ( empty( $revision_log[$revision->ID] ) ) {
  832. $author_id = $revision->post_author;
  833. $reason = '';
  834. } else {
  835. $author_id = $revision_log[$revision->ID]['author'];
  836. $reason = $revision_log[$revision->ID]['reason'];
  837. }
  838. $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_topic_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) );
  839. $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) );
  840. $r .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-topic-revision-log-item">' . "\n";
  841. if ( !empty( $reason ) ) {
  842. $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n";
  843. } else {
  844. $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n";
  845. }
  846. $r .= "\t" . '</li>' . "\n";
  847. }
  848. $r .= "\n" . '</ul>' . "\n\n";
  849. return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id );
  850. }
  851. /**
  852. * Return the raw revision log of the topic
  853. *
  854. * @since bbPress (r2782)
  855. *
  856. * @param int $topic_id Optional. Topic id
  857. * @uses bbp_get_topic_id() To get the topic id
  858. * @uses get_post_meta() To get the revision log meta
  859. * @uses apply_filters() Calls 'bbp_get_topic_raw_revision_log'
  860. * with the log and topic id
  861. * @return string Raw revision log of the topic
  862. */
  863. function bbp_get_topic_raw_revision_log( $topic_id = 0 ) {
  864. $topic_id = bbp_get_topic_id( $topic_id );
  865. $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true );
  866. $revision_log = empty( $revision_log ) ? array() : $revision_log;
  867. return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id );
  868. }
  869. /**
  870. * Return the revisions of the topic
  871. *
  872. * @since bbPress (r2782)
  873. *
  874. * @param int $topic_id Optional. Topic id
  875. * @uses bbp_get_topic_id() To get the topic id
  876. * @uses wp_get_post_revisions() To get the topic revisions
  877. * @uses apply_filters() Calls 'bbp_get_topic_revisions'
  878. * with the revisions and topic id
  879. * @return string Topic revisions
  880. */
  881. function bbp_get_topic_revisions( $topic_id = 0 ) {
  882. $topic_id = bbp_get_topic_id( $topic_id );
  883. $revisions = wp_get_post_revisions( $topic_id, array( 'order' => 'ASC' ) );
  884. return apply_filters( 'bbp_get_topic_revisions', $revisions, $topic_id );
  885. }
  886. /**
  887. * Return the revision count of the topic
  888. *
  889. * @since bbPress (r2782)
  890. *
  891. * @param int $topic_id Optional. Topic id
  892. * @uses bbp_get_topic_revisions() To get the topic revisions
  893. * @uses apply_filters() Calls 'bbp_get_topic_revision_count'
  894. * with the revision count and topic id
  895. * @return string Topic revision count
  896. */
  897. function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) {
  898. $count = (int) count( bbp_get_topic_revisions( $topic_id ) );
  899. $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count';
  900. return apply_filters( $filter, $count, $topic_id );
  901. }
  902. /**
  903. * Output the status of the topic
  904. *
  905. * @since bbPress (r2667)
  906. *
  907. * @param int $topic_id Optional. Topic id
  908. * @uses bbp_get_topic_status() To get the topic status
  909. */
  910. function bbp_topic_status( $topic_id = 0 ) {
  911. echo bbp_get_topic_status( $topic_id );
  912. }
  913. /**
  914. * Return the status of the topic
  915. *
  916. * @since bbPress (r2667)
  917. *
  918. * @param int $topic_id Optional. Topic id
  919. * @uses bbp_get_topic_id() To get the topic id
  920. * @uses get_post_status() To get the topic status
  921. * @uses apply_filters() Calls 'bbp_get_topic_status' with the status
  922. * and topic id
  923. * @return string Status of topic
  924. */
  925. function bbp_get_topic_status( $topic_id = 0 ) {
  926. $topic_id = bbp_get_topic_id( $topic_id );
  927. return apply_filters( 'bbp_get_topic_status', get_post_status( $topic_id ), $topic_id );
  928. }
  929. /**
  930. * Is the topic open to new replies?
  931. *
  932. * @since bbPress (r2727)
  933. *
  934. * @uses bbp_get_topic_status()
  935. *
  936. * @param int $topic_id Optional. Topic id
  937. * @uses bbp_is_topic_closed() To check if the topic is closed
  938. * @return bool True if open, false if closed.
  939. */
  940. function bbp_is_topic_open( $topic_id = 0 ) {
  941. return !bbp_is_topic_closed( $topic_id );
  942. }
  943. /**
  944. * Is the topic closed to new replies?
  945. *
  946. * @since bbPress (r2746)
  947. *
  948. * @param int $topic_id Optional. Topic id
  949. * @uses bbp_get_topic_status() To get the topic status
  950. * @uses apply_filters() Calls 'bbp_is_topic_closed' with the topic id
  951. *
  952. * @return bool True if closed, false if not.
  953. */
  954. function bbp_is_topic_closed( $topic_id = 0 ) {
  955. $closed = bbp_get_topic_status( $topic_id ) === bbp_get_closed_status_id();
  956. return (bool) apply_filters( 'bbp_is_topic_closed', (bool) $closed, $topic_id );
  957. }
  958. /**
  959. * Is the topic a sticky or super sticky?
  960. *
  961. * @since bbPress (r2754)
  962. *
  963. * @param int $topic_id Optional. Topic id
  964. * @param int $check_super Optional. If set to true and if the topic is not a
  965. * normal sticky, it is checked if it is a super
  966. * sticky or not. Defaults to true.
  967. * @uses bbp_get_topic_id() To get the topic id
  968. * @uses bbp_get_topic_forum_id() To get the topic forum id
  969. * @uses bbp_get_stickies() To get the stickies
  970. * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
  971. * @return bool True if sticky or super sticky, false if not.
  972. */
  973. function bbp_is_topic_sticky( $topic_id = 0, $check_super = true ) {
  974. $topic_id = bbp_get_topic_id( $topic_id );
  975. $forum_id = bbp_get_topic_forum_id( $topic_id );
  976. $stickies = bbp_get_stickies( $forum_id );
  977. if ( in_array( $topic_id, $stickies ) || ( !empty( $check_super ) && bbp_is_topic_super_sticky( $topic_id ) ) )
  978. return true;
  979. return false;
  980. }
  981. /**
  982. * Is the topic a super sticky?
  983. *
  984. * @since bbPress (r2754)
  985. *
  986. * @param int $topic_id Optional. Topic id
  987. * @uses bbp_get_topic_id() To get the topic id
  988. * @uses bbp_get_super_stickies() To get the super stickies
  989. * @return bool True if super sticky, false if not.
  990. */
  991. function bbp_is_topic_super_sticky( $topic_id = 0 ) {
  992. $topic_id = bbp_get_topic_id( $topic_id );
  993. $stickies = bbp_get_super_stickies( $topic_id );
  994. return in_array( $topic_id, $stickies );
  995. }
  996. /**
  997. * Is the topic not spam or deleted?
  998. *
  999. * @since bbPress (r3496)
  1000. *
  1001. * @param int $topic_id Optional. Topic id
  1002. * @uses bbp_get_topic_id() To get the topic id
  1003. * @uses bbp_get_topic_status() To get the topic status
  1004. * @uses apply_filters() Calls 'bbp_is_topic_published' with the topic id
  1005. * @return bool True if published, false if not.
  1006. */
  1007. function bbp_is_topic_published( $topic_id = 0 ) {
  1008. $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_public_status_id();
  1009. return (bool) apply_filters( 'bbp_is_topic_published', (bool) $topic_status, $topic_id );
  1010. }
  1011. /**
  1012. * Is the topic marked as spam?
  1013. *
  1014. * @since bbPress (r2727)
  1015. *
  1016. * @param int $topic_id Optional. Topic id
  1017. * @uses bbp_get_topic_id() To get the topic id
  1018. * @uses bbp_get_topic_status() To get the topic status
  1019. * @uses apply_filters() Calls 'bbp_is_topic_spam' with the topic id
  1020. * @return bool True if spam, false if not.
  1021. */
  1022. function bbp_is_topic_spam( $topic_id = 0 ) {
  1023. $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_spam_status_id();
  1024. return (bool) apply_filters( 'bbp_is_topic_spam', (bool) $topic_status, $topic_id );
  1025. }
  1026. /**
  1027. * Is the topic trashed?
  1028. *
  1029. * @since bbPress (r2888)
  1030. *
  1031. * @param int $topic_id Optional. Topic id
  1032. * @uses bbp_get_topic_id() To get the topic id
  1033. * @uses bbp_get_topic_status() To get the topic status
  1034. * @uses apply_filters() Calls 'bbp_is_topic_trash' with the topic id
  1035. * @return bool True if trashed, false if not.
  1036. */
  1037. function bbp_is_topic_trash( $topic_id = 0 ) {
  1038. $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_trash_status_id();
  1039. return (bool) apply_filters( 'bbp_is_topic_trash', (bool) $topic_status, $topic_id );
  1040. }
  1041. /**
  1042. * Is the posted by an anonymous user?
  1043. *
  1044. * @since bbPress (r2753)
  1045. *
  1046. * @param int $topic_id Optional. Topic id
  1047. * @uses bbp_get_topic_id() To get the topic id
  1048. * @uses bbp_get_topic_author_id() To get the topic author id
  1049. * @uses get_post_meta() To get the anonymous user name and email meta
  1050. * @uses apply_filters() Calls 'bbp_is_topic_anonymous' with the topic id
  1051. * @return bool True if the post is by an anonymous user, false if not.
  1052. */
  1053. function bbp_is_topic_anonymous( $topic_id = 0 ) {
  1054. $topic_id = bbp_get_topic_id( $topic_id );
  1055. $retval = false;
  1056. if ( !bbp_get_topic_author_id( $topic_id ) )
  1057. $retval = true;
  1058. elseif ( get_post_meta( $topic_id, '_bbp_anonymous_name', true ) )
  1059. $retval = true;
  1060. elseif ( get_post_meta( $topic_id, '_bbp_anonymous_email', true ) )
  1061. $retval = true;
  1062. // The topic is by an anonymous user
  1063. return (bool) apply_filters( 'bbp_is_topic_anonymous', $retval, $topic_id );
  1064. }
  1065. /**
  1066. * Deprecated. Use bbp_topic_author_display_name() instead.
  1067. *
  1068. * Output the author of the topic.
  1069. *
  1070. * @since bbPress (r2590)
  1071. * @deprecated bbPress (r5119)
  1072. *
  1073. * @param int $topic_id Optional. Topic id
  1074. * @uses bbp_get_topic_author() To get the topic author
  1075. */
  1076. function bbp_topic_author( $topic_id = 0 ) {
  1077. echo bbp_get_topic_author( $topic_id );
  1078. }
  1079. /**
  1080. * Deprecated. Use bbp_get_topic_author_display_name() instead.
  1081. *
  1082. * Return the author of the topic
  1083. *
  1084. * @since bbPress (r2590)
  1085. * @deprecated bbPress (r5119)
  1086. *
  1087. * @param int $topic_id Optional. Topic id
  1088. * @uses bbp_get_topic_id() To get the topic id
  1089. * @uses bbp_is_topic_anonymous() To check if the topic is by an
  1090. * anonymous user
  1091. * @uses bbp_get_topic_author_id() To get the topic author id
  1092. * @uses get_the_author_meta() To get the display name of the author
  1093. * @uses get_post_meta() To get the name of the anonymous poster
  1094. * @uses apply_filters() Calls 'bbp_get_topic_author' with the author
  1095. * and topic id
  1096. * @return string Author of topic
  1097. */
  1098. function bbp_get_topic_author( $topic_id = 0 ) {
  1099. $topic_id = bbp_get_topic_id( $topic_id );
  1100. if ( !bbp_is_topic_anonymous( $topic_id ) ) {
  1101. $author = get_the_author_meta( 'display_name', bbp_get_topic_author_id( $topic_id ) );
  1102. } else {
  1103. $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
  1104. }
  1105. return apply_filters( 'bbp_get_topic_author', $author, $topic_id );
  1106. }
  1107. /**
  1108. * Output the author ID of the topic
  1109. *
  1110. * @since bbPress (r2590)
  1111. *
  1112. * @param int $topic_id Optional. Topic id
  1113. * @uses bbp_get_topic_author_id() To get the topic author id
  1114. */
  1115. function bbp_topic_author_id( $topic_id = 0 ) {
  1116. echo bbp_get_topic_author_id( $topic_id );
  1117. }
  1118. /**
  1119. * Return the author ID of the topic
  1120. *
  1121. * @since bbPress (r2590)
  1122. *
  1123. * @param int $topic_id Optional. Topic id
  1124. * @uses bbp_get_topic_id() To get the topic id
  1125. * @uses get_post_field() To get the topic author id
  1126. * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the author
  1127. * id and topic id
  1128. * @return string Author of topic
  1129. */
  1130. function bbp_get_topic_author_id( $topic_id = 0 ) {
  1131. $topic_id = bbp_get_topic_id( $topic_id );
  1132. $author_id = get_post_field( 'post_author', $topic_id );
  1133. return (int) apply_filters( 'bbp_get_topic_author_id', (int) $author_id, $topic_id );
  1134. }
  1135. /**
  1136. * Output the author display_name of the topic
  1137. *
  1138. * @since bbPress (r2590)
  1139. *
  1140. * @param int $topic_id Optional. Topic id
  1141. * @uses bbp_get_topic_author_display_name() To get the topic author's display
  1142. * name
  1143. */
  1144. function bbp_topic_author_display_name( $topic_id = 0 ) {
  1145. echo bbp_get_topic_author_display_name( $topic_id );
  1146. }
  1147. /**
  1148. * Return the author display_name of the topic
  1149. *
  1150. * @since bbPress (r2485)
  1151. *
  1152. * @param int $topic_id Optional. Topic id
  1153. * @uses bbp_get_topic_id() To get the topic id
  1154. * @uses bbp_is_topic_anonymous() To check if the topic is by an
  1155. * anonymous user
  1156. * @uses bbp_get_topic_author_id() To get the topic author id
  1157. * @uses get_the_author_meta() To get the author meta
  1158. * @uses get_post_meta() To get the anonymous user name
  1159. * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the
  1160. * display name and topic id
  1161. * @return string Topic's author's display name
  1162. */
  1163. function bbp_get_topic_author_display_name( $topic_id = 0 ) {
  1164. $topic_id = bbp_get_topic_id( $topic_id );
  1165. // Check for anonymous user
  1166. if ( !bbp_is_topic_anonymous( $topic_id ) ) {
  1167. // Get the author ID
  1168. $author_id = bbp_get_topic_author_id( $topic_id );
  1169. // Try to get a display name
  1170. $author_name = get_the_author_meta( 'display_name', $author_id );
  1171. // Fall back to user login
  1172. if ( empty( $author_name ) ) {
  1173. $author_name = get_the_author_meta( 'user_login', $author_id );
  1174. }
  1175. // User does not have an account
  1176. } else {
  1177. $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
  1178. }
  1179. // If nothing could be found anywhere, use Anonymous
  1180. if ( empty( $author_name ) )
  1181. $author_name = __( 'Anonymous', 'bbpress' );
  1182. // Encode possible UTF8 display names
  1183. if ( seems_utf8( $author_name ) === false )
  1184. $author_name = utf8_encode( $author_name );
  1185. return apply_filters( 'bbp_get_topic_author_display_name', $author_name, $topic_id );
  1186. }
  1187. /**
  1188. * Output the author avatar of the topic
  1189. *
  1190. * @since bbPress (r2590)
  1191. *
  1192. * @param int $topic_id Optional. Topic id
  1193. * @param int $size Optional. Avatar size. Defaults to 40
  1194. * @uses bbp_get_topic_author_avatar() To get the topic author avatar
  1195. */
  1196. function bbp_topic_author_avatar( $topic_id = 0, $size = 40 ) {
  1197. echo bbp_get_topic_author_avatar( $topic_id, $size );
  1198. }
  1199. /**
  1200. * Return the author avatar of the topic
  1201. *
  1202. * @since bbPress (r2590)
  1203. *
  1204. * @param int $topic_id Optional. Topic id
  1205. * @param int $size Optional. Avatar size. Defaults to 40
  1206. * @uses bbp_get_topic_id() To get the topic id
  1207. * @uses bbp_is_topic_anonymous() To check if the topic is by an
  1208. * anonymous user
  1209. * @uses bbp_get_topic_author_id() To get the topic author id
  1210. * @uses get_post_meta() To get the anonymous user's email
  1211. * @uses get_avatar() To get the avatar
  1212. * @uses apply_filters() Calls 'bbp_get_topic_author_avatar' with the
  1213. * avatar, topic id and size
  1214. * @return string Avatar of the author of the topic
  1215. */
  1216. function bbp_get_topic_author_avatar( $topic_id = 0, $size = 40 ) {
  1217. $author_avatar = '';
  1218. $topic_id = bbp_get_topic_id( $topic_id );
  1219. if ( !empty( $topic_id ) ) {
  1220. if ( !bbp_is_topic_anonymous( $topic_id ) ) {
  1221. $author_avatar = get_avatar( bbp_get_topic_author_id( $topic_id ), $size );
  1222. } else {
  1223. $author_avatar = get_avatar( get_post_meta( $topic_id, '_bbp_anonymous_email', true ), $size );
  1224. }
  1225. }
  1226. return apply_filters( 'bbp_get_topic_author_avatar', $author_avatar, $topic_id, $size );
  1227. }
  1228. /**
  1229. * Output the author link of the topic
  1230. *
  1231. * @since bbPress (r2717)
  1232. *
  1233. * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
  1234. * @uses bbp_get_topic_author_link() To get the topic author link
  1235. */
  1236. function bbp_topic_author_link( $args = '' ) {
  1237. echo bbp_get_topic_author_link( $args );
  1238. }
  1239. /**
  1240. * Return the author link of the topic
  1241. *
  1242. * @since bbPress (r2717)
  1243. *
  1244. * @param mixed|int $args If it is an integer, it is used as topic id.
  1245. * Optional.
  1246. * @uses bbp_get_topic_id() To get the topic id
  1247. * @uses bbp_get_topic_author_display_name() To get the topic author
  1248. * @uses bbp_is_topic_anonymous() To check if the topic is by an
  1249. * anonymous user
  1250. * @uses bbp_get_topic_author_url() To get the topic author url
  1251. * @uses bbp_get_topic_author_avatar() To get the topic author avatar
  1252. * @uses bbp_get_topic_author_display_name() To get the topic author display
  1253. * name
  1254. * @uses bbp_get_user_display_role() To get the topic author display role
  1255. * @uses bbp_get_topic_author_id() To get the topic author id
  1256. * @uses apply_filters() Calls 'bbp_get_topic_author_link' with the link
  1257. * and args
  1258. * @return string Author link of topic
  1259. */
  1260. function bbp_get_topic_author_link( $args = '' ) {
  1261. // Parse arguments against default values
  1262. $r = bbp_parse_args( $args, array(
  1263. 'post_id' => 0,
  1264. 'link_title' => '',
  1265. 'type' => 'both',
  1266. 'size' => 80,
  1267. 'sep' => '&nbsp;',
  1268. 'show_role' => false
  1269. ), 'get_topic_author_link' );
  1270. // Used as topic_id
  1271. if ( is_numeric( $args ) )

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