bbp_get_statistics( array $args = array() )
Get the forum statistics
Description Description
Parameters Parameters
- $args
-
(Optional) 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_pending_topics: Count pending topics? (only counted if the current user has edit_others_topics cap) - 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_pending_replies: Count pending replies? (only counted if the current user has edit_others_replies cap) - 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?
Default value: array()
Return Return
(object) Walked forum tree
Source Source
File: includes/common/functions.php
function bbp_get_statistics( $args = array() ) { // Parse arguments against default values $r = bbp_parse_args( $args, array( // Users 'count_users' => true, // Forums 'count_forums' => true, // Topics 'count_topics' => true, 'count_pending_topics' => true, 'count_private_topics' => true, 'count_spammed_topics' => true, 'count_trashed_topics' => true, // Replies 'count_replies' => true, 'count_pending_replies' => true, 'count_private_replies' => true, 'count_spammed_replies' => true, 'count_trashed_replies' => true, // Topic tags 'count_tags' => true, 'count_empty_tags' => true ), 'get_statistics' ); // Defaults $topic_count = $topic_count_hidden = 0; $reply_count = $reply_count_hidden = 0; $topic_tag_count = $empty_topic_tag_count = 0; $hidden_topic_title = $hidden_reply_title = ''; // Users $user_count = ! empty( $r['count_users'] ) ? bbp_get_total_users() : 0; // Forums $forum_count = ! empty( $r['count_forums'] ) ? wp_count_posts( bbp_get_forum_post_type() )->publish : 0; // Post statuses $pending = bbp_get_pending_status_id(); $private = bbp_get_private_status_id(); $spam = bbp_get_spam_status_id(); $trash = bbp_get_trash_status_id(); $closed = bbp_get_closed_status_id(); // Topics if ( ! empty( $r['count_topics'] ) ) { $all_topics = wp_count_posts( bbp_get_topic_post_type() ); // Published (publish + closed) $topic_count = $all_topics->publish + $all_topics->{$closed}; if ( current_user_can( 'read_private_topics' ) || current_user_can( 'edit_others_topics' ) || current_user_can( 'view_trash' ) ) { // Declare empty arrays $topics = $topic_titles = array(); // Pending $topics['pending'] = ( ! empty( $r['count_pending_topics'] ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$pending} : 0; // Private $topics['private'] = ( ! empty( $r['count_private_topics'] ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0; // Spam $topics['spammed'] = ( ! empty( $r['count_spammed_topics'] ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$spam} : 0; // Trash $topics['trashed'] = ( ! empty( $r['count_trashed_topics'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_topics->{$trash} : 0; // Total hidden (pending + private + spam + trash) $topic_count_hidden = $topics['pending'] + $topics['private'] + $topics['spammed'] + $topics['trashed']; // Generate the hidden topic count's title attribute $topic_titles[] = ! empty( $topics['pending'] ) ? sprintf( esc_html__( 'Pending: %s', 'bbpress' ), bbp_number_format_i18n( $topics['pending'] ) ) : ''; $topic_titles[] = ! empty( $topics['private'] ) ? ''//sprintf( esc_html__( 'Private: %s', 'bbpress' ), bbp_number_format_i18n( $topics['private'] ) ) : ''; $topic_titles[] = ! empty( $topics['spammed'] ) ? sprintf( esc_html__( 'Spammed: %s', 'bbpress' ), bbp_number_format_i18n( $topics['spammed'] ) ) : ''; $topic_titles[] = ! empty( $topics['trashed'] ) ? sprintf( esc_html__( 'Trashed: %s', 'bbpress' ), bbp_number_format_i18n( $topics['trashed'] ) ) : ''; // Compile the hidden topic title $hidden_topic_title = implode( ' | ', array_filter( $topic_titles ) ); } } // Replies if ( ! empty( $r['count_replies'] ) ) { $all_replies = wp_count_posts( bbp_get_reply_post_type() ); // Published $reply_count = $all_replies->publish; if ( current_user_can( 'read_private_replies' ) || current_user_can( 'edit_others_replies' ) || current_user_can( 'view_trash' ) ) { // Declare empty arrays $replies = $reply_titles = array(); // Pending $replies['pending'] = ( ! empty( $r['count_pending_replies'] ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$pending} : 0; // Private $replies['private'] = ( ! empty( $r['count_private_replies'] ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0; // Spam $replies['spammed'] = ( ! empty( $r['count_spammed_replies'] ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$spam} : 0; // Trash $replies['trashed'] = ( ! empty( $r['count_trashed_replies'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_replies->{$trash} : 0; // Total hidden (pending + private + spam + trash) $reply_count_hidden = $replies['pending'] + $replies['private'] + $replies['spammed'] + $replies['trashed']; // Generate the hidden topic count's title attribute $reply_titles[] = ! empty( $replies['pending'] ) ? sprintf( esc_html__( 'Pending: %s', 'bbpress' ), bbp_number_format_i18n( $replies['pending'] ) ) : ''; $reply_titles[] = ! empty( $replies['private'] ) ? sprintf( esc_html__( 'Private: %s', 'bbpress' ), bbp_number_format_i18n( $replies['private'] ) ) : ''; $reply_titles[] = ! empty( $replies['spammed'] ) ? sprintf( esc_html__( 'Spammed: %s', 'bbpress' ), bbp_number_format_i18n( $replies['spammed'] ) ) : ''; $reply_titles[] = ! empty( $replies['trashed'] ) ? sprintf( esc_html__( 'Trashed: %s', 'bbpress' ), bbp_number_format_i18n( $replies['trashed'] ) ) : ''; // Compile the hidden replies title $hidden_reply_title = implode( ' | ', array_filter( $reply_titles ) ); } } // Topic Tags if ( ! empty( $r['count_tags'] ) && bbp_allow_topic_tags() ) { // Get the count $topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id(), array( 'hide_empty' => true ) ); // Empty tags if ( ! empty( $r['count_empty_tags'] ) && current_user_can( 'edit_topic_tags' ) ) { $empty_topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id() ) - $topic_tag_count; } } // Tally the tallies $counts = array_filter( array_map( 'absint', compact( 'user_count', 'forum_count', 'topic_count', 'topic_count_hidden', 'reply_count', 'reply_count_hidden', 'topic_tag_count', 'empty_topic_tag_count' ) ) ); // Define return value $statistics = array(); // Loop through and store the integer and i18n formatted counts. foreach ( $counts as $key => $count ) { $statistics[ $key ] = bbp_number_format_i18n( $count ); $statistics[ "{$key}_int" ] = $count; } // Add the hidden (topic/reply) count title attribute strings because we // don't need to run the math functions on these (see above) $statistics['hidden_topic_title'] = $hidden_topic_title; $statistics['hidden_reply_title'] = $hidden_reply_title; // Filter & return return (array) apply_filters( 'bbp_get_statistics', $statistics, $r, $args ); }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | bbPress (r6055) Introduced the count_pending_topics and count_pending_replies arguments. |
2.0.0 | Introduced. |