Making WordPress.org

Changeset 5617


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

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

Fixes #2772.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support
Files:
3 edited
1 moved

Legend:

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

    r5094 r5617  
    5555                        <a href="<?php bbp_user_profile_url(); ?>reviews/" title="<?php
    5656                            /* translators: %s: user's display name */
    57                             printf( esc_attr__( "%s's Reviews", 'wporg-forums' ), bbp_get_displayed_user_field( 'display_name' ) );
    58                         ?>"><?php esc_html_e( 'Reviews', 'wporg-forums' ); ?></a>
     57                            printf( esc_attr__( "%s's Reviews Written", 'wporg-forums' ), bbp_get_displayed_user_field( 'display_name' ) );
     58                        ?>"><?php esc_html_e( 'Reviews Written', 'wporg-forums' ); ?></a>
    5959                    </span>
    6060                </li>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/user-profile.php

    r5158 r5617  
    116116
    117117        <p class="bbp-user-topic-count"><?php
     118            $review_count = wporg_support_get_user_review_count();
     119
    118120            /* translators: %s: number of user's topics */
    119             printf( esc_html__( 'Topics Started: %s', 'wporg-forums' ), number_format_i18n( bbp_get_user_topic_count_raw() ) );
     121            printf( esc_html__( 'Topics Started: %s', 'wporg-forums' ), number_format_i18n( bbp_get_user_topic_count_raw() - $review_count ) );
    120122        ?></p>
    121123
     
    124126            printf( esc_html__( 'Replies Created: %s', 'wporg-forums' ), number_format_i18n( bbp_get_user_reply_count_raw() ) );
    125127        ?></p>
     128
     129        <p class="bbp-user-review-count"><?php
     130            /* translators: %s: number of user's reviews */
     131            printf( esc_html__( 'Reviews Written: %s', 'wporg-forums' ), number_format_i18n( $review_count ) );
     132        ?></p>
    126133    </div>
    127134</div><!-- #bbp-author-topics-started -->
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/user-reviews-written.php

    r5616 r5617  
    22
    33/**
    4  * User Reviews Created
     4 * User Reviews Written
    55 *
    66 * @package bbPress
     
    88 */
    99
    10 do_action( 'bbp_template_before_user_topics_created' ); ?>
     10do_action( 'bbp_template_before_user_reviews_written' ); ?>
    1111
    1212<div id="bbp-user-topics-started" class="bbp-user-topics-started">
    13     <h2 class="entry-title"><?php esc_html_e( 'Reviews', 'wporg-forums' ); ?></h2>
     13    <h2 class="entry-title"><?php esc_html_e( 'Reviews Written', 'wporg-forums' ); ?></h2>
    1414    <div class="bbp-user-section">
    1515
     
    2525
    2626            <p><?php bbp_is_user_home()
    27                 ? esc_html_e( 'You have not created any reviews.',      'wporg-forums' )
    28                 : esc_html_e( 'This user has not created any reviews.', 'wporg-forums' );
     27                ? esc_html_e( 'You have not written any reviews.',      'wporg-forums' )
     28                : esc_html_e( 'This user has not written any reviews.', 'wporg-forums' );
    2929            ?></p>
    3030
     
    3434</div><!-- #bbp-user-topics-started -->
    3535
    36 <?php do_action( 'bbp_template_after_user_topics_created' );
     36<?php do_action( 'bbp_template_after_user_reviews_written' );
  • 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.