Making WordPress.org


Ignore:
Timestamp:
07/07/2017 08:12:06 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Support Theme: Introduce a function to count user's topics, excluding reviews.

The previous method of substracting the number of reviews from the total number of topics in [5617] was not really accurate and could sometimes result in a negative number.

See #2772.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

    r5626 r5629  
    215215
    216216/**
     217 * Return the raw database count of topics by a user, excluding reviews.
     218 *
     219 * @global wpdb $wpdb WordPress database abstraction object.
     220 *
     221 * @param int $user_id User ID to get count for.
     222 * @return int Raw DB count of topics.
     223 */
     224function wporg_support_get_user_topics_count( $user_id = 0 ) {
     225    global $wpdb;
     226
     227    $user_id = bbp_get_user_id( $user_id );
     228    if ( empty( $user_id ) ) {
     229        return 0;
     230    }
     231
     232    if ( ! class_exists( 'WordPressdotorg\Forums\Plugin' ) ) {
     233        return 0;
     234    }
     235
     236    $count = (int) $wpdb->get_var( $wpdb->prepare(
     237        "SELECT COUNT(*)
     238            FROM {$wpdb->posts}
     239            WHERE post_type = 'topic'
     240                AND post_status IN ( 'publish', 'closed' )
     241                AND post_parent <> %d
     242                AND post_author = %d",
     243        WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
     244        $user_id
     245    ) );
     246
     247    return $count;
     248}
     249
     250/**
    217251 * Return the raw database count of reviews by a user.
    218252 *
     
    222256 * @return int Raw DB count of reviews.
    223257 */
    224 function wporg_support_get_user_review_count( $user_id = 0 ) {
     258function wporg_support_get_user_reviews_count( $user_id = 0 ) {
    225259    global $wpdb;
    226260
Note: See TracChangeset for help on using the changeset viewer.