Making WordPress.org


Ignore:
Timestamp:
07/03/2017 10:43:31 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Support Theme: Add "Reviews Written" count to user's profile page.

Fixes #2772.

File:
1 edited

Legend:

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

    r5602 r5617  
    212212    /* translators: registration date format, see https://secure.php.net/date */
    213213    return mysql2date( __( 'F jS, Y', 'wporg-forums' ), $user->user_registered );
     214}
     215
     216/**
     217 * Return the raw database count of reviews by a user.
     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 reviews.
     223 */
     224function wporg_support_get_user_review_count( $user_id = 0 ) {
     225    global $wpdb;
     226
     227    $user_id = bbp_get_user_id( $user_id );
     228    if ( empty( $user_id ) ) {
     229        return false;
     230    }
     231
     232    if ( ! class_exists( 'WordPressdotorg\Forums\Plugin' ) ) {
     233        return false;
     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 = %s
     242                AND post_author = %d",
     243        WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID,
     244        $user_id
     245    ) );
     246
     247    return $count;
    214248}
    215249
Note: See TracChangeset for help on using the changeset viewer.