PageRenderTime 65ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 2672 lines | 951 code | 333 blank | 1388 comment | 150 complexity | 8368e3a7657f9af01d56a3c26a955af5 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 Forum 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 forums
  13. *
  14. * @since bbPress (r2857)
  15. * @uses bbp_get_forum_post_type() To get the forum post type
  16. */
  17. function bbp_forum_post_type() {
  18. echo bbp_get_forum_post_type();
  19. }
  20. /**
  21. * Return the unique id of the custom post type for forums
  22. *
  23. * @since bbPress (r2857)
  24. *
  25. * @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum
  26. * post type id
  27. * @return string The unique forum post type id
  28. */
  29. function bbp_get_forum_post_type() {
  30. return apply_filters( 'bbp_get_forum_post_type', bbpress()->forum_post_type );
  31. }
  32. /**
  33. * Return array of labels used by the forum post type
  34. *
  35. * @since bbPress (r5129)
  36. *
  37. * @return array
  38. */
  39. function bbp_get_forum_post_type_labels() {
  40. return apply_filters( 'bbp_get_forum_post_type_labels', array(
  41. 'name' => __( 'Forums', 'bbpress' ),
  42. 'menu_name' => __( 'Forums', 'bbpress' ),
  43. 'singular_name' => __( 'Forum', 'bbpress' ),
  44. 'all_items' => __( 'All Forums', 'bbpress' ),
  45. 'add_new' => __( 'New Forum', 'bbpress' ),
  46. 'add_new_item' => __( 'Create New Forum', 'bbpress' ),
  47. 'edit' => __( 'Edit', 'bbpress' ),
  48. 'edit_item' => __( 'Edit Forum', 'bbpress' ),
  49. 'new_item' => __( 'New Forum', 'bbpress' ),
  50. 'view' => __( 'View Forum', 'bbpress' ),
  51. 'view_item' => __( 'View Forum', 'bbpress' ),
  52. 'search_items' => __( 'Search Forums', 'bbpress' ),
  53. 'not_found' => __( 'No forums found', 'bbpress' ),
  54. 'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ),
  55. 'parent_item_colon' => __( 'Parent Forum:', 'bbpress' )
  56. ) );
  57. }
  58. /**
  59. * Return array of forum post type rewrite settings
  60. *
  61. * @since bbPress (r5129)
  62. *
  63. * @return array
  64. */
  65. function bbp_get_forum_post_type_rewrite() {
  66. return apply_filters( 'bbp_get_forum_post_type_rewrite', array(
  67. 'slug' => bbp_get_forum_slug(),
  68. 'with_front' => false
  69. ) );
  70. }
  71. /**
  72. * Return array of features the forum post type supports
  73. *
  74. * @since bbPress (r5129)
  75. *
  76. * @return array
  77. */
  78. function bbp_get_forum_post_type_supports() {
  79. return apply_filters( 'bbp_get_forum_post_type_supports', array(
  80. 'title',
  81. 'editor',
  82. 'revisions'
  83. ) );
  84. }
  85. /** Forum Loop ****************************************************************/
  86. /**
  87. * The main forum loop.
  88. *
  89. * WordPress makes this easy for us.
  90. *
  91. * @since bbPress (r2464)
  92. *
  93. * @param mixed $args All the arguments supported by {@link WP_Query}
  94. * @uses WP_Query To make query and get the forums
  95. * @uses bbp_get_forum_post_type() To get the forum post type id
  96. * @uses bbp_get_forum_id() To get the forum id
  97. * @uses get_option() To get the forums per page option
  98. * @uses current_user_can() To check if the current user is capable of editing
  99. * others' forums
  100. * @uses apply_filters() Calls 'bbp_has_forums' with
  101. * bbPres::forum_query::have_posts()
  102. * and bbPres::forum_query
  103. * @return object Multidimensional array of forum information
  104. */
  105. function bbp_has_forums( $args = '' ) {
  106. // Forum archive only shows root
  107. if ( bbp_is_forum_archive() ) {
  108. $default_post_parent = 0;
  109. // User subscriptions shows any
  110. } elseif ( bbp_is_subscriptions() ) {
  111. $default_post_parent = 'any';
  112. // Could be anything, so look for possible parent ID
  113. } else {
  114. $default_post_parent = bbp_get_forum_id();
  115. }
  116. // Parse arguments with default forum query for most circumstances
  117. $bbp_f = bbp_parse_args( $args, array(
  118. 'post_type' => bbp_get_forum_post_type(),
  119. 'post_parent' => $default_post_parent,
  120. 'post_status' => bbp_get_public_status_id(),
  121. 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
  122. 'ignore_sticky_posts' => true,
  123. 'orderby' => 'menu_order title',
  124. 'order' => 'ASC'
  125. ), 'has_forums' );
  126. // Run the query
  127. $bbp = bbpress();
  128. $bbp->forum_query = new WP_Query( $bbp_f );
  129. return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
  130. }
  131. /**
  132. * Whether there are more forums available in the loop
  133. *
  134. * @since bbPress (r2464)
  135. *
  136. * @uses bbPress:forum_query::have_posts() To check if there are more forums
  137. * available
  138. * @return object Forum information
  139. */
  140. function bbp_forums() {
  141. // Put into variable to check against next
  142. $have_posts = bbpress()->forum_query->have_posts();
  143. // Reset the post data when finished
  144. if ( empty( $have_posts ) )
  145. wp_reset_postdata();
  146. return $have_posts;
  147. }
  148. /**
  149. * Loads up the current forum in the loop
  150. *
  151. * @since bbPress (r2464)
  152. *
  153. * @uses bbPress:forum_query::the_post() To get the current forum
  154. * @return object Forum information
  155. */
  156. function bbp_the_forum() {
  157. return bbpress()->forum_query->the_post();
  158. }
  159. /** Forum *********************************************************************/
  160. /**
  161. * Output forum id
  162. *
  163. * @since bbPress (r2464)
  164. *
  165. * @param $forum_id Optional. Used to check emptiness
  166. * @uses bbp_get_forum_id() To get the forum id
  167. */
  168. function bbp_forum_id( $forum_id = 0 ) {
  169. echo bbp_get_forum_id( $forum_id );
  170. }
  171. /**
  172. * Return the forum id
  173. *
  174. * @since bbPress (r2464)
  175. *
  176. * @param $forum_id Optional. Used to check emptiness
  177. * @uses bbPress::forum_query::in_the_loop To check if we're in the loop
  178. * @uses bbPress::forum_query::post::ID To get the forum id
  179. * @uses WP_Query::post::ID To get the forum id
  180. * @uses bbp_is_forum() To check if the search result is a forum
  181. * @uses bbp_is_single_forum() To check if it's a forum page
  182. * @uses bbp_is_single_topic() To check if it's a topic page
  183. * @uses bbp_get_topic_forum_id() To get the topic forum id
  184. * @uses get_post_field() To get the post's post type
  185. * @uses apply_filters() Calls 'bbp_get_forum_id' with the forum id and
  186. * supplied forum id
  187. * @return int The forum id
  188. */
  189. function bbp_get_forum_id( $forum_id = 0 ) {
  190. global $wp_query;
  191. $bbp = bbpress();
  192. // Easy empty checking
  193. if ( !empty( $forum_id ) && is_numeric( $forum_id ) ) {
  194. $bbp_forum_id = $forum_id;
  195. // Currently inside a forum loop
  196. } elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
  197. $bbp_forum_id = $bbp->forum_query->post->ID;
  198. // Currently inside a search loop
  199. } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
  200. $bbp_forum_id = $bbp->search_query->post->ID;
  201. // Currently viewing a forum
  202. } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && !empty( $bbp->current_forum_id ) ) {
  203. $bbp_forum_id = $bbp->current_forum_id;
  204. // Currently viewing a forum
  205. } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) {
  206. $bbp_forum_id = $wp_query->post->ID;
  207. // Currently viewing a topic
  208. } elseif ( bbp_is_single_topic() ) {
  209. $bbp_forum_id = bbp_get_topic_forum_id();
  210. // Fallback
  211. } else {
  212. $bbp_forum_id = 0;
  213. }
  214. return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
  215. }
  216. /**
  217. * Gets a forum
  218. *
  219. * @since bbPress (r2787)
  220. *
  221. * @param int|object $forum forum id or forum object
  222. * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
  223. * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
  224. * @uses get_post() To get the forum
  225. * @uses apply_filters() Calls 'bbp_get_forum' with the forum, output type and
  226. * sanitation filter
  227. * @return mixed Null if error or forum (in specified form) if success
  228. */
  229. function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
  230. // Use forum ID
  231. if ( empty( $forum ) || is_numeric( $forum ) )
  232. $forum = bbp_get_forum_id( $forum );
  233. // Attempt to load the forum
  234. $forum = get_post( $forum, OBJECT, $filter );
  235. if ( empty( $forum ) )
  236. return $forum;
  237. // Bail if post_type is not a forum
  238. if ( $forum->post_type !== bbp_get_forum_post_type() )
  239. return null;
  240. // Tweak the data type to return
  241. if ( $output === OBJECT ) {
  242. return $forum;
  243. } elseif ( $output === ARRAY_A ) {
  244. $_forum = get_object_vars( $forum );
  245. return $_forum;
  246. } elseif ( $output === ARRAY_N ) {
  247. $_forum = array_values( get_object_vars( $forum ) );
  248. return $_forum;
  249. }
  250. return apply_filters( 'bbp_get_forum', $forum, $output, $filter );
  251. }
  252. /**
  253. * Output the link to the forum
  254. *
  255. * @since bbPress (r2464)
  256. *
  257. * @param int $forum_id Optional. Forum id
  258. * @uses bbp_get_forum_permalink() To get the permalink
  259. */
  260. function bbp_forum_permalink( $forum_id = 0 ) {
  261. echo esc_url( bbp_get_forum_permalink( $forum_id ) );
  262. }
  263. /**
  264. * Return the link to the forum
  265. *
  266. * @since bbPress (r2464)
  267. *
  268. * @param int $forum_id Optional. Forum id
  269. * @param $string $redirect_to Optional. Pass a redirect value for use with
  270. * shortcodes and other fun things.
  271. * @uses bbp_get_forum_id() To get the forum id
  272. * @uses get_permalink() Get the permalink of the forum
  273. * @uses apply_filters() Calls 'bbp_get_forum_permalink' with the forum
  274. * link
  275. * @return string Permanent link to forum
  276. */
  277. function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
  278. $forum_id = bbp_get_forum_id( $forum_id );
  279. // Use the redirect address
  280. if ( !empty( $redirect_to ) ) {
  281. $forum_permalink = esc_url_raw( $redirect_to );
  282. // Use the topic permalink
  283. } else {
  284. $forum_permalink = get_permalink( $forum_id );
  285. }
  286. return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id );
  287. }
  288. /**
  289. * Output the title of the forum
  290. *
  291. * @since bbPress (r2464)
  292. *
  293. * @param int $forum_id Optional. Forum id
  294. * @uses bbp_get_forum_title() To get the forum title
  295. */
  296. function bbp_forum_title( $forum_id = 0 ) {
  297. echo bbp_get_forum_title( $forum_id );
  298. }
  299. /**
  300. * Return the title of the forum
  301. *
  302. * @since bbPress (r2464)
  303. *
  304. * @param int $forum_id Optional. Forum id
  305. * @uses bbp_get_forum_id() To get the forum id
  306. * @uses get_the_title() To get the forum title
  307. * @uses apply_filters() Calls 'bbp_get_forum_title' with the title
  308. * @return string Title of forum
  309. */
  310. function bbp_get_forum_title( $forum_id = 0 ) {
  311. $forum_id = bbp_get_forum_id( $forum_id );
  312. $title = get_the_title( $forum_id );
  313. return apply_filters( 'bbp_get_forum_title', $title, $forum_id );
  314. }
  315. /**
  316. * Output the forum archive title
  317. *
  318. * @since bbPress (r3249)
  319. *
  320. * @param string $title Default text to use as title
  321. */
  322. function bbp_forum_archive_title( $title = '' ) {
  323. echo bbp_get_forum_archive_title( $title );
  324. }
  325. /**
  326. * Return the forum archive title
  327. *
  328. * @since bbPress (r3249)
  329. *
  330. * @param string $title Default text to use as title
  331. *
  332. * @uses bbp_get_page_by_path() Check if page exists at root path
  333. * @uses get_the_title() Use the page title at the root path
  334. * @uses get_post_type_object() Load the post type object
  335. * @uses bbp_get_forum_post_type() Get the forum post type ID
  336. * @uses get_post_type_labels() Get labels for forum post type
  337. * @uses apply_filters() Allow output to be manipulated
  338. *
  339. * @return string The forum archive title
  340. */
  341. function bbp_get_forum_archive_title( $title = '' ) {
  342. // If no title was passed
  343. if ( empty( $title ) ) {
  344. // Set root text to page title
  345. $page = bbp_get_page_by_path( bbp_get_root_slug() );
  346. if ( !empty( $page ) ) {
  347. $title = get_the_title( $page->ID );
  348. // Default to forum post type name label
  349. } else {
  350. $fto = get_post_type_object( bbp_get_forum_post_type() );
  351. $title = $fto->labels->name;
  352. }
  353. }
  354. return apply_filters( 'bbp_get_forum_archive_title', $title );
  355. }
  356. /**
  357. * Output the content of the forum
  358. *
  359. * @since bbPress (r2780)
  360. *
  361. * @param int $forum_id Optional. Topic id
  362. * @uses bbp_get_forum_content() To get the forum content
  363. */
  364. function bbp_forum_content( $forum_id = 0 ) {
  365. echo bbp_get_forum_content( $forum_id );
  366. }
  367. /**
  368. * Return the content of the forum
  369. *
  370. * @since bbPress (r2780)
  371. *
  372. * @param int $forum_id Optional. Topic id
  373. * @uses bbp_get_forum_id() To get the forum id
  374. * @uses post_password_required() To check if the forum requires pass
  375. * @uses get_the_password_form() To get the password form
  376. * @uses get_post_field() To get the content post field
  377. * @uses apply_filters() Calls 'bbp_get_forum_content' with the content
  378. * and forum id
  379. * @return string Content of the forum
  380. */
  381. function bbp_get_forum_content( $forum_id = 0 ) {
  382. $forum_id = bbp_get_forum_id( $forum_id );
  383. // Check if password is required
  384. if ( post_password_required( $forum_id ) )
  385. return get_the_password_form();
  386. $content = get_post_field( 'post_content', $forum_id );
  387. return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
  388. }
  389. /**
  390. * Allow forum rows to have adminstrative actions
  391. *
  392. * @since bbPress (r3653)
  393. * @uses do_action()
  394. * @todo Links and filter
  395. */
  396. function bbp_forum_row_actions() {
  397. do_action( 'bbp_forum_row_actions' );
  398. }
  399. /**
  400. * Output the forums last active ID
  401. *
  402. * @since bbPress (r2860)
  403. *
  404. * @uses bbp_get_forum_last_active_id() To get the forum's last active id
  405. * @param int $forum_id Optional. Forum id
  406. */
  407. function bbp_forum_last_active_id( $forum_id = 0 ) {
  408. echo bbp_get_forum_last_active_id( $forum_id );
  409. }
  410. /**
  411. * Return the forums last active ID
  412. *
  413. * @since bbPress (r2860)
  414. *
  415. * @param int $forum_id Optional. Forum id
  416. * @uses bbp_get_forum_id() To get the forum id
  417. * @uses get_post_meta() To get the forum's last active id
  418. * @uses apply_filters() Calls 'bbp_get_forum_last_active_id' with
  419. * the last active id and forum id
  420. * @return int Forum's last active id
  421. */
  422. function bbp_get_forum_last_active_id( $forum_id = 0 ) {
  423. $forum_id = bbp_get_forum_id( $forum_id );
  424. $active_id = get_post_meta( $forum_id, '_bbp_last_active_id', true );
  425. return (int) apply_filters( 'bbp_get_forum_last_active_id', (int) $active_id, $forum_id );
  426. }
  427. /**
  428. * Output the forums last update date/time (aka freshness)
  429. *
  430. * @since bbPress (r2464)
  431. *
  432. * @uses bbp_get_forum_last_active_time() To get the forum freshness
  433. * @param int $forum_id Optional. Forum id
  434. */
  435. function bbp_forum_last_active_time( $forum_id = 0 ) {
  436. echo bbp_get_forum_last_active_time( $forum_id );
  437. }
  438. /**
  439. * Return the forums last update date/time (aka freshness)
  440. *
  441. * @since bbPress (r2464)
  442. *
  443. * @param int $forum_id Optional. Forum id
  444. * @uses bbp_get_forum_id() To get the forum id
  445. * @uses get_post_meta() To retrieve forum last active meta
  446. * @uses bbp_get_forum_last_reply_id() To get forum's last reply id
  447. * @uses get_post_field() To get the post date of the reply
  448. * @uses bbp_get_forum_last_topic_id() To get forum's last topic id
  449. * @uses bbp_get_topic_last_active_time() To get time when the topic was
  450. * last active
  451. * @uses bbp_convert_date() To convert the date
  452. * @uses bbp_get_time_since() To get time in since format
  453. * @uses apply_filters() Calls 'bbp_get_forum_last_active' with last
  454. * active time and forum id
  455. * @return string Forum last update date/time (freshness)
  456. */
  457. function bbp_get_forum_last_active_time( $forum_id = 0 ) {
  458. // Verify forum and get last active meta
  459. $forum_id = bbp_get_forum_id( $forum_id );
  460. $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
  461. if ( empty( $last_active ) ) {
  462. $reply_id = bbp_get_forum_last_reply_id( $forum_id );
  463. if ( !empty( $reply_id ) ) {
  464. $last_active = get_post_field( 'post_date', $reply_id );
  465. } else {
  466. $topic_id = bbp_get_forum_last_topic_id( $forum_id );
  467. if ( !empty( $topic_id ) ) {
  468. $last_active = bbp_get_topic_last_active_time( $topic_id );
  469. }
  470. }
  471. }
  472. $active_time = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
  473. return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id );
  474. }
  475. /**
  476. * Output link to the most recent activity inside a forum.
  477. *
  478. * Outputs a complete link with attributes and content.
  479. *
  480. * @since bbPress (r2625)
  481. *
  482. * @param int $forum_id Optional. Forum id
  483. * @uses bbp_get_forum_freshness_link() To get the forum freshness link
  484. */
  485. function bbp_forum_freshness_link( $forum_id = 0) {
  486. echo bbp_get_forum_freshness_link( $forum_id );
  487. }
  488. /**
  489. * Returns link to the most recent activity inside a forum.
  490. *
  491. * Returns a complete link with attributes and content.
  492. *
  493. * @since bbPress (r2625)
  494. *
  495. * @param int $forum_id Optional. Forum id
  496. * @uses bbp_get_forum_id() To get the forum id
  497. * @uses bbp_get_forum_last_active_id() To get the forum last active id
  498. * @uses bbp_get_forum_last_reply_id() To get the forum last reply id
  499. * @uses bbp_get_forum_last_topic_id() To get the forum last topic id
  500. * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
  501. * @uses bbp_get_forum_last_reply_title() To get the forum last reply
  502. * title
  503. * @uses bbp_get_forum_last_topic_permalink() To get the forum last
  504. * topic permalink
  505. * @uses bbp_get_forum_last_topic_title() To get the forum last topic
  506. * title
  507. * @uses bbp_get_forum_last_active_time() To get the time when the forum
  508. * was last active
  509. * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the
  510. * link and forum id
  511. */
  512. function bbp_get_forum_freshness_link( $forum_id = 0 ) {
  513. $forum_id = bbp_get_forum_id( $forum_id );
  514. $active_id = bbp_get_forum_last_active_id( $forum_id );
  515. $link_url = $title = '';
  516. if ( empty( $active_id ) )
  517. $active_id = bbp_get_forum_last_reply_id( $forum_id );
  518. if ( empty( $active_id ) )
  519. $active_id = bbp_get_forum_last_topic_id( $forum_id );
  520. if ( bbp_is_topic( $active_id ) ) {
  521. $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
  522. $title = bbp_get_forum_last_topic_title( $forum_id );
  523. } elseif ( bbp_is_reply( $active_id ) ) {
  524. $link_url = bbp_get_forum_last_reply_url( $forum_id );
  525. $title = bbp_get_forum_last_reply_title( $forum_id );
  526. }
  527. $time_since = bbp_get_forum_last_active_time( $forum_id );
  528. if ( !empty( $time_since ) && !empty( $link_url ) ) {
  529. $anchor = '<a class="lastMessageTitle" href="' . esc_url( $link_url ) . '">' . esc_attr( $title ) . '</a>';
  530. $anchor .= '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
  531. }
  532. else
  533. $anchor = esc_html__( 'No Topics', 'bbpress' );
  534. return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id );
  535. }
  536. /**
  537. * Output parent ID of a forum, if exists
  538. *
  539. * @since bbPress (r3675)
  540. *
  541. * @param int $forum_id Forum ID
  542. * @uses bbp_get_forum_parent_id() To get the forum's parent ID
  543. */
  544. function bbp_forum_parent_id( $forum_id = 0 ) {
  545. echo bbp_get_forum_parent_id( $forum_id );
  546. }
  547. /**
  548. * Return ID of forum parent, if exists
  549. *
  550. * @since bbPress (r3675)
  551. *
  552. * @param int $forum_id Optional. Forum id
  553. * @uses bbp_get_forum_id() To get the forum id
  554. * @uses get_post_field() To get the forum parent
  555. * @uses apply_filters() Calls 'bbp_get_forum_parent' with the parent & forum id
  556. * @return int Forum parent
  557. */
  558. function bbp_get_forum_parent_id( $forum_id = 0 ) {
  559. $forum_id = bbp_get_forum_id( $forum_id );
  560. $parent_id = get_post_field( 'post_parent', $forum_id );
  561. return (int) apply_filters( 'bbp_get_forum_parent_id', (int) $parent_id, $forum_id );
  562. }
  563. /**
  564. * Return array of parent forums
  565. *
  566. * @since bbPress (r2625)
  567. *
  568. * @param int $forum_id Optional. Forum id
  569. * @uses bbp_get_forum_id() To get the forum id
  570. * @uses bbp_get_forum() To get the forum
  571. * @uses apply_filters() Calls 'bbp_get_forum_ancestors' with the ancestors
  572. * and forum id
  573. * @return array Forum ancestors
  574. */
  575. function bbp_get_forum_ancestors( $forum_id = 0 ) {
  576. $forum_id = bbp_get_forum_id( $forum_id );
  577. $ancestors = array();
  578. $forum = bbp_get_forum( $forum_id );
  579. if ( !empty( $forum ) ) {
  580. while ( 0 !== (int) $forum->post_parent ) {
  581. $ancestors[] = $forum->post_parent;
  582. $forum = bbp_get_forum( $forum->post_parent );
  583. }
  584. }
  585. return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );
  586. }
  587. /**
  588. * Return subforums of given forum
  589. *
  590. * @since bbPress (r2747)
  591. *
  592. * @param mixed $args All the arguments supported by {@link WP_Query}
  593. * @uses bbp_get_forum_id() To get the forum id
  594. * @uses current_user_can() To check if the current user is capable of
  595. * reading private forums
  596. * @uses get_posts() To get the subforums
  597. * @uses apply_filters() Calls 'bbp_forum_get_subforums' with the subforums
  598. * and the args
  599. * @return mixed false if none, array of subs if yes
  600. */
  601. function bbp_forum_get_subforums( $args = '' ) {
  602. // Use passed integer as post_parent
  603. if ( is_numeric( $args ) )
  604. $args = array( 'post_parent' => $args );
  605. // Setup possible post__not_in array
  606. $post_stati[] = bbp_get_public_status_id();
  607. // Super admin get whitelisted post statuses
  608. if ( bbp_is_user_keymaster() ) {
  609. $post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() );
  610. // Not a keymaster, so check caps
  611. } else {
  612. // Check if user can read private forums
  613. if ( current_user_can( 'read_private_forums' ) ) {
  614. $post_stati[] = bbp_get_private_status_id();
  615. }
  616. // Check if user can read hidden forums
  617. if ( current_user_can( 'read_hidden_forums' ) ) {
  618. $post_stati[] = bbp_get_hidden_status_id();
  619. }
  620. }
  621. // Parse arguments against default values
  622. $r = bbp_parse_args( $args, array(
  623. 'post_parent' => 0,
  624. 'post_type' => bbp_get_forum_post_type(),
  625. 'post_status' => implode( ',', $post_stati ),
  626. 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
  627. 'orderby' => 'menu_order title',
  628. 'order' => 'ASC',
  629. 'ignore_sticky_posts' => true,
  630. 'no_found_rows' => true
  631. ), 'forum_get_subforums' );
  632. $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
  633. // Create a new query for the subforums
  634. $get_posts = new WP_Query();
  635. // No forum passed
  636. $sub_forums = !empty( $r['post_parent'] ) ? $get_posts->query( $r ) : array();
  637. return (array) apply_filters( 'bbp_forum_get_subforums', $sub_forums, $r );
  638. }
  639. /**
  640. * Output a list of forums (can be used to list subforums)
  641. *
  642. * @param mixed $args The function supports these args:
  643. * - before: To put before the output. Defaults to '<ul class="bbp-forums">'
  644. * - after: To put after the output. Defaults to '</ul>'
  645. * - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
  646. * - link_after: To put after every link. Defaults to '</li>'
  647. * - separator: Separator. Defaults to ', '
  648. * - forum_id: Forum id. Defaults to ''
  649. * - show_topic_count - To show forum topic count or not. Defaults to true
  650. * - show_reply_count - To show forum reply count or not. Defaults to true
  651. * @uses bbp_forum_get_subforums() To check if the forum has subforums or not
  652. * @uses bbp_get_forum_permalink() To get forum permalink
  653. * @uses bbp_get_forum_title() To get forum title
  654. * @uses bbp_is_forum_category() To check if a forum is a category
  655. * @uses bbp_get_forum_topic_count() To get forum topic count
  656. * @uses bbp_get_forum_reply_count() To get forum reply count
  657. */
  658. function bbp_list_forums( $args = '' ) {
  659. // Define used variables
  660. $output = $sub_forums = $topic_count = $reply_count = $counts = '';
  661. $i = 0;
  662. $count = array();
  663. // Parse arguments against default values
  664. $r = bbp_parse_args( $args, array(
  665. 'before' => '<ul class="bbp-forums-list">',
  666. 'after' => '</ul>',
  667. 'link_before' => '<li class="bbp-forum">',
  668. 'link_after' => '</li>',
  669. 'count_before' => ' (',
  670. 'count_after' => ')',
  671. 'count_sep' => ', ',
  672. 'separator' => ', ',
  673. 'forum_id' => '',
  674. 'show_topic_count' => true,
  675. 'show_reply_count' => true,
  676. ), 'list_forums' );
  677. // Loop through forums and create a list
  678. $sub_forums = bbp_forum_get_subforums( $r['forum_id'] );
  679. if ( !empty( $sub_forums ) ) {
  680. // Total count (for separator)
  681. $total_subs = count( $sub_forums );
  682. foreach ( $sub_forums as $sub_forum ) {
  683. $i++; // Separator count
  684. // Get forum details
  685. $count = array();
  686. $show_sep = $total_subs > $i ? $r['separator'] : '';
  687. $permalink = bbp_get_forum_permalink( $sub_forum->ID );
  688. $title = bbp_get_forum_title( $sub_forum->ID );
  689. // Show topic count
  690. if ( !empty( $r['show_topic_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  691. $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
  692. }
  693. // Show reply count
  694. if ( !empty( $r['show_reply_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  695. $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
  696. }
  697. // Counts to show
  698. if ( !empty( $count ) ) {
  699. $counts = 'Тем: ' . $count['topic'] . '&nbsp;&nbsp;&nbsp;Ответов: ' . $count['reply'];
  700. }
  701. // Build this sub forums link
  702. $output .= $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" class="bbp-forum-link">' . '<img src="/wp-content/themes/wow-guild/images/forumicon.png"> <div class="aboutforum">' . $title . '<p class="counters">' . $counts . '</p></div></a>' . $r['link_after'];
  703. }
  704. // Output the list
  705. echo apply_filters( 'bbp_list_forums', $r['before'] . $output . $r['after'], $r );
  706. }
  707. }
  708. /** Forum Subscriptions *******************************************************/
  709. /**
  710. * Output the forum subscription link
  711. *
  712. * @since bbPress (r5156)
  713. *
  714. * @uses bbp_get_forum_subscription_link()
  715. */
  716. function bbp_forum_subscription_link( $args = array() ) {
  717. echo bbp_get_forum_subscription_link( $args );
  718. }
  719. /**
  720. * Get the forum subscription link
  721. *
  722. * A custom wrapper for bbp_get_user_subscribe_link()
  723. *
  724. * @since bbPress (r5156)
  725. *
  726. * @uses bbp_parse_args()
  727. * @uses bbp_get_user_subscribe_link()
  728. * @uses apply_filters() Calls 'bbp_get_forum_subscribe_link'
  729. */
  730. function bbp_get_forum_subscription_link( $args = array() ) {
  731. // No link
  732. $retval = false;
  733. // Parse the arguments
  734. $r = bbp_parse_args( $args, array(
  735. 'forum_id' => 0,
  736. 'user_id' => 0,
  737. 'before' => '',
  738. 'after' => '',
  739. 'subscribe' => __( 'Subscribe', 'bbpress' ),
  740. 'unsubscribe' => __( 'Unsubscribe', 'bbpress' )
  741. ), 'get_forum_subscribe_link' );
  742. // No link for categories until we support subscription hierarchy
  743. // @see http://bbpress.trac.wordpress.org/ticket/2475
  744. if ( ! bbp_is_forum_category() ) {
  745. $retval = bbp_get_user_subscribe_link( $r );
  746. }
  747. return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r );
  748. }
  749. /** Forum Last Topic **********************************************************/
  750. /**
  751. * Output the forum's last topic id
  752. *
  753. * @since bbPress (r2464)
  754. *
  755. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  756. * @param int $forum_id Optional. Forum id
  757. */
  758. function bbp_forum_last_topic_id( $forum_id = 0 ) {
  759. echo bbp_get_forum_last_topic_id( $forum_id );
  760. }
  761. /**
  762. * Return the forum's last topic id
  763. *
  764. * @since bbPress (r2464)
  765. *
  766. * @param int $forum_id Optional. Forum id
  767. * @uses bbp_get_forum_id() To get the forum id
  768. * @uses get_post_meta() To get the forum's last topic id
  769. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_id' with the
  770. * forum and topic id
  771. * @return int Forum's last topic id
  772. */
  773. function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
  774. $forum_id = bbp_get_forum_id( $forum_id );
  775. $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true );
  776. return (int) apply_filters( 'bbp_get_forum_last_topic_id', (int) $topic_id, $forum_id );
  777. }
  778. /**
  779. * Output the title of the last topic inside a forum
  780. *
  781. * @since bbPress (r2625)
  782. *
  783. * @param int $forum_id Optional. Forum id
  784. * @uses bbp_get_forum_last_topic_title() To get the forum's last topic's title
  785. */
  786. function bbp_forum_last_topic_title( $forum_id = 0 ) {
  787. echo bbp_get_forum_last_topic_title( $forum_id );
  788. }
  789. /**
  790. * Return the title of the last topic inside a forum
  791. *
  792. * @since bbPress (r2625)
  793. *
  794. * @param int $forum_id Optional. Forum id
  795. * @uses bbp_get_forum_id() To get the forum id
  796. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  797. * @uses bbp_get_topic_title() To get the topic's title
  798. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_title' with the
  799. * topic title and forum id
  800. * @return string Forum's last topic's title
  801. */
  802. function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
  803. $forum_id = bbp_get_forum_id( $forum_id );
  804. $topic_id = bbp_get_forum_last_topic_id( $forum_id );
  805. $title = !empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : '';
  806. return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id );
  807. }
  808. /**
  809. * Output the link to the last topic in a forum
  810. *
  811. * @since bbPress (r2464)
  812. *
  813. * @param int $forum_id Optional. Forum id
  814. * @uses bbp_get_forum_last_topic_permalink() To get the forum's last topic's
  815. * permanent link
  816. */
  817. function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
  818. echo esc_url( bbp_get_forum_last_topic_permalink( $forum_id ) );
  819. }
  820. /**
  821. * Return the link to the last topic in a forum
  822. *
  823. * @since bbPress (r2464)
  824. *
  825. * @param int $forum_id Optional. Forum id
  826. * @uses bbp_get_forum_id() To get the forum id
  827. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  828. * @uses bbp_get_topic_permalink() To get the topic's permalink
  829. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with
  830. * the topic link and forum id
  831. * @return string Permanent link to topic
  832. */
  833. function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
  834. $forum_id = bbp_get_forum_id( $forum_id );
  835. return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
  836. }
  837. /**
  838. * Return the author ID of the last topic of a forum
  839. *
  840. * @since bbPress (r2625)
  841. *
  842. * @param int $forum_id Optional. Forum id
  843. * @uses bbp_get_forum_id() To get the forum id
  844. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  845. * @uses bbp_get_topic_author_id() To get the topic's author id
  846. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author' with the author
  847. * id and forum id
  848. * @return int Forum's last topic's author id
  849. */
  850. function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
  851. $forum_id = bbp_get_forum_id( $forum_id );
  852. $author_id = bbp_get_topic_author_id( bbp_get_forum_last_topic_id( $forum_id ) );
  853. return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id );
  854. }
  855. /**
  856. * Output link to author of last topic of forum
  857. *
  858. * @since bbPress (r2625)
  859. *
  860. * @param int $forum_id Optional. Forum id
  861. * @uses bbp_get_forum_last_topic_author_link() To get the forum's last topic's
  862. * author link
  863. */
  864. function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
  865. echo bbp_get_forum_last_topic_author_link( $forum_id );
  866. }
  867. /**
  868. * Return link to author of last topic of forum
  869. *
  870. * @since bbPress (r2625)
  871. *
  872. * @param int $forum_id Optional. Forum id
  873. * @uses bbp_get_forum_id() To get the forum id
  874. * @uses bbp_get_forum_last_topic_author_id() To get the forum's last
  875. * topic's author id
  876. * @uses bbp_get_user_profile_link() To get the author's profile link
  877. * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author_link'
  878. * with the author link and forum id
  879. * @return string Forum's last topic's author link
  880. */
  881. function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
  882. $forum_id = bbp_get_forum_id( $forum_id );
  883. $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
  884. $author_link = bbp_get_user_profile_link( $author_id );
  885. return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
  886. }
  887. /** Forum Last Reply **********************************************************/
  888. /**
  889. * Output the forums last reply id
  890. *
  891. * @since bbPress (r2464)
  892. *
  893. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  894. * @param int $forum_id Optional. Forum id
  895. */
  896. function bbp_forum_last_reply_id( $forum_id = 0 ) {
  897. echo bbp_get_forum_last_reply_id( $forum_id );
  898. }
  899. /**
  900. * Return the forums last reply id
  901. *
  902. * @since bbPress (r2464)
  903. *
  904. * @param int $forum_id Optional. Forum id
  905. * @uses bbp_get_forum_id() To get the forum id
  906. * @uses get_post_meta() To get the forum's last reply id
  907. * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
  908. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_id' with
  909. * the last reply id and forum id
  910. * @return int Forum's last reply id
  911. */
  912. function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
  913. $forum_id = bbp_get_forum_id( $forum_id );
  914. $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true );
  915. if ( empty( $reply_id ) )
  916. $reply_id = bbp_get_forum_last_topic_id( $forum_id );
  917. return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
  918. }
  919. /**
  920. * Output the title of the last reply inside a forum
  921. *
  922. * @param int $forum_id Optional. Forum id
  923. * @uses bbp_get_forum_last_reply_title() To get the forum's last reply's title
  924. */
  925. function bbp_forum_last_reply_title( $forum_id = 0 ) {
  926. echo bbp_get_forum_last_reply_title( $forum_id );
  927. }
  928. /**
  929. * Return the title of the last reply inside a forum
  930. *
  931. * @param int $forum_id Optional. Forum id
  932. * @uses bbp_get_forum_id() To get the forum id
  933. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  934. * @uses bbp_get_reply_title() To get the reply title
  935. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_title' with the
  936. * reply title and forum id
  937. * @return string
  938. */
  939. function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
  940. $forum_id = bbp_get_forum_id( $forum_id );
  941. return apply_filters( 'bbp_get_forum_last_reply_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
  942. }
  943. /**
  944. * Output the link to the last reply in a forum
  945. *
  946. * @since bbPress (r2464)
  947. *
  948. * @param int $forum_id Optional. Forum id
  949. * @uses bbp_get_forum_last_reply_permalink() To get the forum last reply link
  950. */
  951. function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
  952. echo esc_url( bbp_get_forum_last_reply_permalink( $forum_id ) );
  953. }
  954. /**
  955. * Return the link to the last reply in a forum
  956. *
  957. * @since bbPress (r2464)
  958. *
  959. * @param int $forum_id Optional. Forum id
  960. * @uses bbp_get_forum_id() To get the forum id
  961. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  962. * @uses bbp_get_reply_permalink() To get the reply permalink
  963. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_permalink' with
  964. * the reply link and forum id
  965. * @return string Permanent link to the forum's last reply
  966. */
  967. function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
  968. $forum_id = bbp_get_forum_id( $forum_id );
  969. return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
  970. }
  971. /**
  972. * Output the url to the last reply in a forum
  973. *
  974. * @since bbPress (r2683)
  975. *
  976. * @param int $forum_id Optional. Forum id
  977. * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
  978. */
  979. function bbp_forum_last_reply_url( $forum_id = 0 ) {
  980. echo esc_url( bbp_get_forum_last_reply_url( $forum_id ) );
  981. }
  982. /**
  983. * Return the url to the last reply in a forum
  984. *
  985. * @since bbPress (r2683)
  986. *
  987. * @param int $forum_id Optional. Forum id
  988. * @uses bbp_get_forum_id() To get the forum id
  989. * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
  990. * @uses bbp_get_reply_url() To get the reply url
  991. * @uses bbp_get_forum_last_topic_permalink() To get the forum's last
  992. * topic's permalink
  993. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_url' with the
  994. * reply url and forum id
  995. * @return string Paginated URL to latest reply
  996. */
  997. function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
  998. $forum_id = bbp_get_forum_id( $forum_id );
  999. // If forum has replies, get the last reply and use its url
  1000. $reply_id = bbp_get_forum_last_reply_id( $forum_id );
  1001. if ( !empty( $reply_id ) ) {
  1002. $reply_url = bbp_get_reply_url( $reply_id );
  1003. // No replies, so look for topics and use last permalink
  1004. } else {
  1005. $reply_url = bbp_get_forum_last_topic_permalink( $forum_id );
  1006. // No topics either, so set $reply_url as empty string
  1007. if ( empty( $reply_url ) ) {
  1008. $reply_url = '';
  1009. }
  1010. }
  1011. // Filter and return
  1012. return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id );
  1013. }
  1014. /**
  1015. * Output author ID of last reply of forum
  1016. *
  1017. * @since bbPress (r2625)
  1018. *
  1019. * @param int $forum_id Optional. Forum id
  1020. * @uses bbp_get_forum_last_reply_author_id() To get the forum's last reply
  1021. * author id
  1022. */
  1023. function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
  1024. echo bbp_get_forum_last_reply_author_id( $forum_id );
  1025. }
  1026. /**
  1027. * Return author ID of last reply of forum
  1028. *
  1029. * @since bbPress (r2625)
  1030. *
  1031. * @param int $forum_id Optional. Forum id
  1032. * @uses bbp_get_forum_id() To get the forum id
  1033. * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
  1034. * reply's author id
  1035. * @uses bbp_get_reply_author_id() To get the reply's author id
  1036. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_id' with
  1037. * the author id and forum id
  1038. * @return int Forum's last reply author id
  1039. */
  1040. function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
  1041. $forum_id = bbp_get_forum_id( $forum_id );
  1042. $author_id = bbp_get_reply_author_id( bbp_get_forum_last_reply_id( $forum_id ) );
  1043. return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id );
  1044. }
  1045. /**
  1046. * Output link to author of last reply of forum
  1047. *
  1048. * @since bbPress (r2625)
  1049. *
  1050. * @param int $forum_id Optional. Forum id
  1051. * @uses bbp_get_forum_last_reply_author_link() To get the forum's last reply's
  1052. * author link
  1053. */
  1054. function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
  1055. echo bbp_get_forum_last_reply_author_link( $forum_id );
  1056. }
  1057. /**
  1058. * Return link to author of last reply of forum
  1059. *
  1060. * @since bbPress (r2625)
  1061. *
  1062. * @param int $forum_id Optional. Forum id
  1063. * @uses bbp_get_forum_id() To get the forum id
  1064. * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
  1065. * reply's author id
  1066. * @uses bbp_get_user_profile_link() To get the reply's author's profile
  1067. * link
  1068. * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_link'
  1069. * with the author link and forum id
  1070. * @return string Link to author of last reply of forum
  1071. */
  1072. function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
  1073. $forum_id = bbp_get_forum_id( $forum_id );
  1074. $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
  1075. $author_link = bbp_get_user_profile_link( $author_id );
  1076. return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id );
  1077. }
  1078. /** Forum Counts **************************************************************/
  1079. /**
  1080. * Output the topics link of the forum
  1081. *
  1082. * @since bbPress (r2883)
  1083. *
  1084. * @param int $forum_id Optional. Topic id
  1085. * @uses bbp_get_forum_topics_link() To get the forum topics link
  1086. */
  1087. function bbp_forum_topics_link( $forum_id = 0 ) {
  1088. echo bbp_get_forum_topics_link( $forum_id );
  1089. }
  1090. /**
  1091. * Return the topics link of the forum
  1092. *
  1093. * @since bbPress (r2883)
  1094. *
  1095. * @param int $forum_id Optional. Topic id
  1096. * @uses bbp_get_forum_id() To get the forum id
  1097. * @uses bbp_get_forum() To get the forum
  1098. * @uses bbp_get_forum_topic_count() To get the forum topic count
  1099. * @uses bbp_get_forum_permalink() To get the forum permalink
  1100. * @uses remove_query_arg() To remove args from the url
  1101. * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden
  1102. * topic count
  1103. * @uses current_user_can() To check if the current user can edit others
  1104. * topics
  1105. * @uses add_query_arg() To add custom args to the url
  1106. * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the
  1107. * topics link and forum id
  1108. */
  1109. function bbp_get_forum_topics_link( $forum_id = 0 ) {
  1110. $forum = bbp_get_forum( $forum_id );
  1111. $forum_id = $forum->ID;
  1112. $topics = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, false ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id ) );
  1113. $retval = '';
  1114. // First link never has view=all
  1115. if ( bbp_get_view_all( 'edit_others_topics' ) )
  1116. $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_forum_permalink( $forum_id ) ) ) . "'>" . esc_html( $topics ) . "</a>";
  1117. else
  1118. $retval .= esc_html( $topics );
  1119. // Get deleted topics
  1120. $deleted = bbp_get_forum_topic_count_hidden( $forum_id );
  1121. // This forum has hidden topics
  1122. if ( !empty( $deleted ) && current_user_can( 'edit_others_topics' ) ) {
  1123. // Extra text
  1124. $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
  1125. // No link
  1126. if ( bbp_get_view_all() ) {
  1127. $retval .= " $extra";
  1128. // Link
  1129. } else {
  1130. $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_forum_permalink( $forum_id ), true ) ) . "'>" . esc_html( $extra ) . "</a>";
  1131. }
  1132. }
  1133. return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
  1134. }
  1135. /**
  1136. * Output total sub-forum count of a forum
  1137. *
  1138. * @since bbPress (r2464)
  1139. *
  1140. * @param int $forum_id Optional. Forum id to check
  1141. * @param boolean $integer Optional. Whether or not to format the result
  1142. * @uses bbp_get_forum_subforum_count() To get the forum's subforum count
  1143. */
  1144. function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) {
  1145. echo bbp_get_forum_subforum_count( $forum_id, $integer );
  1146. }
  1147. /**
  1148. * Return total subforum count of a forum
  1149. *
  1150. * @since bbPress (r2464)
  1151. *
  1152. * @param int $forum_id Optional. Forum id
  1153. * @param boolean $integer Optional. Whether or not to format the result
  1154. * @uses bbp_get_forum_id() To get the forum id
  1155. * @uses get_post_meta() To get the subforum count
  1156. * @uses apply_filters() Calls 'bbp_get_forum_subforum_count' with the
  1157. * subforum count and forum id
  1158. * @return int Forum's subforum count
  1159. */
  1160. function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
  1161. $forum_id = bbp_get_forum_id( $forum_id );
  1162. $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
  1163. $filter = ( true === $integer ) ? 'bbp_get_forum_subforum_count_int' : 'bbp_get_forum_subforum_count';
  1164. return apply_filters( $filter, $forum_count, $forum_id );
  1165. }
  1166. /**
  1167. * Output total topic count of a forum
  1168. *
  1169. * @since bbPress (r2464)
  1170. *
  1171. * @param int $forum_id Optional. Forum id
  1172. * @param bool $total_count Optional. To get the total count or normal count?
  1173. * @param boolean $integer Optional. Whether or not to format the result
  1174. * @uses bbp_get_forum_topic_count() To get the forum topic count
  1175. */
  1176. function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1177. echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer );
  1178. }
  1179. /**
  1180. * Return total topic count of a forum
  1181. *
  1182. * @since bbPress (r2464)
  1183. *
  1184. * @param int $forum_id Optional. Forum id
  1185. * @param bool $total_count Optional. To get the total count or normal
  1186. * count? Defaults to total.
  1187. * @param boolean $integer Optional. Whether or not to format the result
  1188. * @uses bbp_get_forum_id() To get the forum id
  1189. * @uses get_post_meta() To get the forum topic count
  1190. * @uses apply_filters() Calls 'bbp_get_forum_topic_count' with the
  1191. * topic count and forum id
  1192. * @return int Forum topic count
  1193. */
  1194. function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1195. $forum_id = bbp_get_forum_id( $forum_id );
  1196. $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count';
  1197. $topics = (int) get_post_meta( $forum_id, $meta_key, true );
  1198. $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_int' : 'bbp_get_forum_topic_count';
  1199. return apply_filters( $filter, $topics, $forum_id );
  1200. }
  1201. /**
  1202. * Output total reply count of a forum
  1203. *
  1204. * @since bbPress (r2464)
  1205. *
  1206. * @param int $forum_id Optional. Forum id
  1207. * @param bool $total_count Optional. To get the total count or normal count?
  1208. * @param boolean $integer Optional. Whether or not to format the result
  1209. * @uses bbp_get_forum_reply_count() To get the forum reply count
  1210. */
  1211. function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1212. echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer );
  1213. }
  1214. /**
  1215. * Return total post count of a forum
  1216. *
  1217. * @since bbPress (r2464)
  1218. *
  1219. * @param int $forum_id Optional. Forum id
  1220. * @param bool $total_count Optional. To get the total count or normal
  1221. * count?
  1222. * @param boolean $integer Optional. Whether or not to format the result
  1223. * @uses bbp_get_forum_id() To get the forum id
  1224. * @uses get_post_meta() To get the forum reply count
  1225. * @uses apply_filters() Calls 'bbp_get_forum_reply_count' with the
  1226. * reply count and forum id
  1227. * @return int Forum reply count
  1228. */
  1229. function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1230. $forum_id = bbp_get_forum_id( $forum_id );
  1231. $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
  1232. $replies = (int) get_post_meta( $forum_id, $meta_key, true );
  1233. $filter = ( true === $integer ) ? 'bbp_get_forum_reply_count_int' : 'bbp_get_forum_reply_count';
  1234. return apply_filters( $filter, $replies, $forum_id );
  1235. }
  1236. /**
  1237. * Output total post count of a forum
  1238. *
  1239. * @since bbPress (r2954)
  1240. *
  1241. * @param int $forum_id Optional. Forum id
  1242. * @param bool $total_count Optional. To get the total count or normal count?
  1243. * @param boolean $integer Optional. Whether or not to format the result
  1244. * @uses bbp_get_forum_post_count() To get the forum post count
  1245. */
  1246. function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1247. echo bbp_get_forum_post_count( $forum_id, $total_count, $integer );
  1248. }
  1249. /**
  1250. * Return total post count of a forum
  1251. *
  1252. * @since bbPress (r2954)
  1253. *
  1254. * @param int $forum_id Optional. Forum id
  1255. * @param bool $total_count Optional. To get the total count or normal
  1256. * count?
  1257. * @param boolean $integer Optional. Whether or not to format the result
  1258. * @uses bbp_get_forum_id() To get the forum id
  1259. * @uses get_post_meta() To get the forum post count
  1260. * @uses apply_filters() Calls 'bbp_get_forum_post_count' with the
  1261. * post count and forum id
  1262. * @return int Forum post count
  1263. */
  1264. function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
  1265. $forum_id = bbp_get_forum_id( $forum_id );
  1266. $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true );
  1267. $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
  1268. $replies = (int) get_post_meta( $forum_id, $meta_key, true );
  1269. $retval = $replies + $topics;
  1270. $filter = ( true === $integer ) ? 'bbp_get_forum_post_count_int' : 'bbp_get_forum_post_count';
  1271. return apply_filters( $filter, $retval, $forum_id );
  1272. }
  1273. /**
  1274. * Output total hidden topic count of a forum…

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