bbp_get_statistics

Get the forum statistics.

Description

(object) bbp_get_statistics( (string) $args = '' ); 

Returns (object)

Walked forum tree

Parameters (1)

0. $args — Optional. (string) => ''
The function supports these arguments (all default to true): - count_users: Count users? - count_forums: Count forums? - count_topics: Count topics? If set to false, private, spammed and trashed topics are also not counted. - count_private_topics: Count private topics? (only counted if the current user has read_private_topics cap) - count_spammed_topics: Count spammed topics? (only counted if the current user has edit_others_topics cap) - count_trashed_topics: Count trashed topics? (only counted if the current user has view_trash cap) - count_replies: Count replies? If set to false, private, spammed and trashed replies are also not counted. - count_private_replies: Count private replies? (only counted if the current user has read_private_replies cap) - count_spammed_replies: Count spammed replies? (only counted if the current user has edit_others_replies cap) - count_trashed_replies: Count trashed replies? (only counted if the current user has view_trash cap) - count_tags: Count tags? If set to false, empty tags are also not counted - count_empty_tags: Count empty tags?

Usage

  1. if ( !function_exists( 'bbp_get_statistics' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3. $args = ''; 
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_get_statistics($args); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/common/functions.php  
  1. function bbp_get_statistics( $args = '' ) { 
  2.  
  3. // Parse arguments against default values 
  4. $r = bbp_parse_args( $args, array( 
  5. 'count_users' => true,  
  6. 'count_forums' => true,  
  7. 'count_topics' => true,  
  8. 'count_private_topics' => true,  
  9. 'count_spammed_topics' => true,  
  10. 'count_trashed_topics' => true,  
  11. 'count_replies' => true,  
  12. 'count_private_replies' => true,  
  13. 'count_spammed_replies' => true,  
  14. 'count_trashed_replies' => true,  
  15. 'count_tags' => true,  
  16. 'count_empty_tags' => true 
  17. ), 'get_statistics' ); 
  18.  
  19. // Defaults 
  20. $user_count = 0; 
  21. $forum_count = 0; 
  22. $topic_count = 0; 
  23. $topic_count_hidden = 0; 
  24. $reply_count = 0; 
  25. $reply_count_hidden = 0; 
  26. $topic_tag_count = 0; 
  27. $empty_topic_tag_count = 0; 
  28.  
  29. // Users 
  30. if ( !empty( $r['count_users'] ) ) { 
  31. $user_count = bbp_get_total_users(); 
  32.  
  33. // Forums 
  34. if ( !empty( $r['count_forums'] ) ) { 
  35. $forum_count = wp_count_posts( bbp_get_forum_post_type() )->publish; 
  36.  
  37. // Post statuses 
  38. $private = bbp_get_private_status_id(); 
  39. $closed = bbp_get_closed_status_id(); 
  40.  
  41. // Topics 
  42. if ( !empty( $r['count_topics'] ) ) { 
  43. $all_topics = wp_count_posts( bbp_get_topic_post_type() ); 
  44.  
  45. // Published (publish + closed) 
  46. $topic_count = $all_topics->publish + $all_topics->{$closed}; 
  47.  
  48. if ( current_user_can( 'read_private_topics' ) || current_user_can( 'edit_others_topics' ) || current_user_can( 'view_trash' ) ) { 
  49.  
  50. // Private 
  51. $topics['private'] = ( !empty( $r['count_private_topics'] ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0; 
  52.  
  53. // Spam 
  54. $topics['spammed'] = ( !empty( $r['count_spammed_topics'] ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$spam} : 0; 
  55.  
  56. // Trash 
  57. $topics['trashed'] = ( !empty( $r['count_trashed_topics'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_topics->{$trash} : 0; 
  58.  
  59. // Total hidden (private + spam + trash) 
  60. $topic_count_hidden = $topics['private'] + $topics['spammed'] + $topics['trashed']; 
  61.  
  62. // Generate the hidden topic count's title attribute 
  63. $topic_titles[] = !empty( $topics['private'] ) ? sprintf( __( 'Private: %s', bbpress ), number_format_i18n( $topics['private'] ) ) : ''; 
  64. $topic_titles[] = !empty( $topics['spammed'] ) ? sprintf( __( 'Spammed: %s', bbpress ), number_format_i18n( $topics['spammed'] ) ) : ''; 
  65. $topic_titles[] = !empty( $topics['trashed'] ) ? sprintf( __( 'Trashed: %s', bbpress ), number_format_i18n( $topics['trashed'] ) ) : ''; 
  66.  
  67. // Compile the hidden topic title 
  68. $hidden_topic_title = implode( ' | ', array_filter( $topic_titles ) ); 
  69.  
  70. // Replies 
  71. if ( !empty( $r['count_replies'] ) ) { 
  72.  
  73. $all_replies = wp_count_posts( bbp_get_reply_post_type() ); 
  74.  
  75. // Published 
  76. $reply_count = $all_replies->publish; 
  77.  
  78. if ( current_user_can( 'read_private_replies' ) || current_user_can( 'edit_others_replies' ) || current_user_can( 'view_trash' ) ) { 
  79.  
  80. // Private 
  81. $replies['private'] = ( !empty( $r['count_private_replies'] ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0; 
  82.  
  83. // Spam 
  84. $replies['spammed'] = ( !empty( $r['count_spammed_replies'] ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$spam} : 0; 
  85.  
  86. // Trash 
  87. $replies['trashed'] = ( !empty( $r['count_trashed_replies'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_replies->{$trash} : 0; 
  88.  
  89. // Total hidden (private + spam + trash) 
  90. $reply_count_hidden = $replies['private'] + $replies['spammed'] + $replies['trashed']; 
  91.  
  92. // Generate the hidden topic count's title attribute 
  93. $reply_titles[] = !empty( $replies['private'] ) ? sprintf( __( 'Private: %s', bbpress ), number_format_i18n( $replies['private'] ) ) : ''; 
  94. $reply_titles[] = !empty( $replies['spammed'] ) ? sprintf( __( 'Spammed: %s', bbpress ), number_format_i18n( $replies['spammed'] ) ) : ''; 
  95. $reply_titles[] = !empty( $replies['trashed'] ) ? sprintf( __( 'Trashed: %s', bbpress ), number_format_i18n( $replies['trashed'] ) ) : ''; 
  96.  
  97. // Compile the hidden replies title 
  98. $hidden_reply_title = implode( ' | ', array_filter( $reply_titles ) ); 
  99.  
  100.  
  101. // Topic Tags 
  102. if ( !empty( $r['count_tags'] ) && bbp_allow_topic_tags() ) { 
  103.  
  104. // Get the count 
  105. $topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id(), array( 'hide_empty' => true ) ); 
  106.  
  107. // Empty tags 
  108. if ( !empty( $r['count_empty_tags'] ) && current_user_can( 'edit_topic_tags' ) ) { 
  109. $empty_topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id() ) - $topic_tag_count; 
  110.  
  111. // Tally the tallies 
  112. $statistics = array_map( 'number_format_i18n', array_map( 'absint', compact( 
  113. 'user_count',  
  114. 'forum_count',  
  115. 'topic_count',  
  116. 'topic_count_hidden',  
  117. 'reply_count',  
  118. 'reply_count_hidden',  
  119. 'topic_tag_count',  
  120. 'empty_topic_tag_count' 
  121. ) ) ); 
  122.  
  123. // Add the hidden (topic/reply) count title attribute strings because we 
  124. // don't need to run the math functions on these (see above) 
  125. $statistics['hidden_topic_title'] = isset( $hidden_topic_title ) ? $hidden_topic_title : ''; 
  126. $statistics['hidden_reply_title'] = isset( $hidden_reply_title ) ? $hidden_reply_title : ''; 
  127.  
  128. return apply_filters( 'bbp_get_statistics', $statistics, $r );