bpbbpst_support_statistics

Returns an array of statistics element about support topics.

Description

(array) bpbbpst_support_statistics( (string) $args = '' ); 

Returns (array)

$support_stats the different statistics element

Parameters (1)

0. $args — Optional. (string) => ''
User can customize the query

Usage

  1. if ( !function_exists( 'bpbbpst_support_statistics' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddy-bbpress-support-topic/includes/functions.php'; 
  3.  
  4. // user can customize the query 
  5. $args = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bpbbpst_support_statistics($args); 
  9.  

Defined (1)

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

/includes/functions.php  
  1. function bpbbpst_support_statistics( $args = '' ) { 
  2.  
  3. $defaults = array( 
  4. 'post_type' => bbp_get_topic_post_type(),  
  5. 'posts_per_page' => -1,  
  6. 'meta_query' => array( 
  7. array( 
  8. 'key' => '_bpbbpst_support_topic',  
  9. 'value' => 1,  
  10. 'type' => 'numeric',  
  11. 'compare' => '>=' 
  12. ); 
  13.  
  14. $r = bbp_parse_args( $args, $defaults, 'support_statistics' ); 
  15.  
  16. $support_query = new WP_Query( $r ); 
  17. $total_support = $support_query->found_posts; 
  18.  
  19. $all_status = bpbbpst_get_support_status(); 
  20. unset( $all_status['topic-not-support'] ); 
  21.  
  22. $support_stat = array(); 
  23.  
  24. foreach ( $all_status as $key => $status ) { 
  25. $support_stat[ $status['value'] ] = array( 
  26. 'stat' => 0,  
  27. 'label' => $status['sb-caption'],  
  28. 'admin_class' => $status['admin_class'],  
  29. 'front_class' => sanitize_html_class( $key ) 
  30. ); 
  31.  
  32. if ( ! empty( $status['dashicon'] ) ) { 
  33. $support_stat[ $status['value'] ]['dashicon'] = $status['dashicon']; 
  34.  
  35. if ( $support_query->have_posts() ) : 
  36.  
  37. while ( $support_query->have_posts() ) : $support_query->the_post(); 
  38.  
  39. $db_status = get_post_meta( $support_query->post->ID, '_bpbbpst_support_topic', true ); 
  40.  
  41. // We need to check parent forum support setting to avoid inconsistent stats 
  42. $forum_id = $support_query->post->post_parent; 
  43. $forum_support_status = false; 
  44.  
  45. if ( ! empty( $forum_id ) ) { 
  46. $forum_support_status = get_post_meta( $forum_id, '_bpbbpst_forum_settings', true ); 
  47.  
  48. if ( ! in_array( $forum_support_status, array( 1, 2 ) ) ) { 
  49. // Let's avoid the display of the topic in the WP_List_Table 
  50. delete_post_meta( $support_query->post->ID, '_bpbbpst_support_topic' ); 
  51. continue; 
  52.  
  53. $support_stat[$db_status]['stat'] += 1; 
  54.  
  55. endwhile; 
  56.  
  57. wp_reset_postdata(); 
  58.  
  59. endif; 
  60.  
  61. $goon = false; 
  62.  
  63. foreach ( $support_stat as $notempty ) { 
  64. if ( $notempty['stat'] > 0 ) { 
  65. $goon = true; 
  66.  
  67. if ( ! empty( $goon ) ) { 
  68.  
  69. $percent_support = number_format( ( $support_stat[2]['stat'] / $total_support ) * 100, 2 ) . '%'; 
  70.  
  71. $support_stats['allstatus'] = $support_stat; 
  72. $support_stats['total_support'] = $total_support; 
  73. $support_stats['percent'] = $percent_support; 
  74.  
  75. return apply_filters( 'bpbbpst_support_statistics', $support_stats, $args ); 
  76.  
  77. } else { 
  78. return false; 
  79.