WordPress.org

Making WordPress.org

Changeset 5861


Ignore:
Timestamp:
09/03/2017 09:58:57 AM (2 years ago)
Author:
SergeyBiryukov
Message:

Support Theme: Use the methods added in [5860] in wporg_support_get_user_topics_count() and wporg_support_get_user_reviews_count().

See #2967, #2772.

File:
1 edited

Legend:

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

    r5859 r5861  
    232232 * Return the raw database count of topics by a user, excluding reviews.
    233233 *
    234  * @global wpdb $wpdb WordPress database abstraction object.
    235  *
    236234 * @param int $user_id User ID to get count for.
    237235 * @return int Raw DB count of topics.
    238236 */
    239237function wporg_support_get_user_topics_count( $user_id = 0 ) {
    240     global $wpdb;
    241 
    242     $user_id = bbp_get_user_id( $user_id );
    243     if ( empty( $user_id ) ) {
    244         return 0;
    245     }
    246 
    247238    if ( ! class_exists( 'WordPressdotorg\Forums\Plugin' ) ) {
    248239        return 0;
    249240    }
    250241
    251         $count = (int) $wpdb->get_var( $wpdb->prepare(
    252             "SELECT COUNT(*)
    253                 FROM {$wpdb->posts}
    254                 WHERE post_type = 'topic'
    255                     AND post_status IN ( 'publish', 'closed' )
    256                     AND post_parent <> %d
    257                     AND post_author = %d",
    258             WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
    259             $user_id
    260         ) );
    261 
    262     return $count;
     242    $plugin_instance = WordPressdotorg\Forums\Plugin::get_instance();
     243
     244    return $plugin_instance->users->get_user_topics_count( $user_id );
    263245}
    264246
    265247/**
    266248 * Return the raw database count of reviews by a user.
    267  *
    268  * @global wpdb $wpdb WordPress database abstraction object.
    269249 *
    270250 * @param int $user_id User ID to get count for.
     
    272252 */
    273253function wporg_support_get_user_reviews_count( $user_id = 0 ) {
    274     global $wpdb;
    275 
    276     $user_id = bbp_get_user_id( $user_id );
    277     if ( empty( $user_id ) ) {
    278         return 0;
    279     }
    280 
    281254    if ( ! class_exists( 'WordPressdotorg\Forums\Plugin' ) ) {
    282255        return 0;
    283256    }
    284257
    285         $count = (int) $wpdb->get_var( $wpdb->prepare(
    286             "SELECT COUNT(*)
    287                 FROM {$wpdb->posts}
    288                 WHERE post_type = 'topic'
    289                     AND post_status IN ( 'publish', 'closed' )
    290                     AND post_parent = %d
    291                     AND post_author = %d",
    292             WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
    293             $user_id
    294         ) );
    295 
    296     return $count;
     258    $plugin_instance = WordPressdotorg\Forums\Plugin::get_instance();
     259
     260    return $plugin_instance->users->get_user_reviews_count( $user_id );
    297261}
    298262
Note: See TracChangeset for help on using the changeset viewer.