Making WordPress.org

Ticket #1805: 1805.comment.count.diff

File 1805.comment.count.diff, 4.3 KB (added by dufresnesteven, 5 years ago)

Adds a comment count next to the review.

  • wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    diff --git wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
    index 9d679a035..9acbffa46 100644
    class Tools { 
    7474                return $reviews;
    7575        }
    7676
     77        /**
     78         * Returns the replies for a list reviews.
     79         *
     80         * @static
     81         * @global \wpdb $wpdb WordPress database abstraction object.
     82         *
     83         * @param string[] $topic_ids List of topic ids.
     84         * @return array
     85         */
     86        public static function get_reviews_replies( $topic_ids ) {
     87
     88                if( empty( $topic_ids ) ) {
     89                        return [];
     90                }
     91
     92                $topics_string = implode( ',', $topic_ids );
     93                $cache_slug = "reviews_{$topics_string}_replies";
     94                $replies = wp_cache_get( $cache_slug, 'plugin-reviews' );
     95
     96                if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) && false === $replies ) {
     97                        global $wpdb;
     98
     99                        $placeholders = array_fill(0, count( $topic_ids ), '%d');
     100                        $ph = implode(', ', $placeholders);
     101
     102                        $query = "SELECT * FROM " . $wpdb->base_prefix . WPORG_SUPPORT_FORUMS_BLOGID . "_posts p
     103                        WHERE p.post_type = 'reply' AND p.post_parent IN ( $ph ) AND p.post_status = 'publish'";
     104
     105                        $replies = $wpdb->get_results( $wpdb->prepare( $query, $topic_ids ) );
     106
     107                        wp_cache_set( $cache_slug, $replies, 'plugin-reviews', HOUR_IN_SECONDS );
     108                }
     109
     110                return $replies;
     111        }
     112
    77113        /**
    78114         * Retrieve a list of users who have commit to a specific plugin.
    79115         *
  • wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-reviews.php

    diff --git wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-reviews.php wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-reviews.php
    index 049a66d92..e5deab69b 100644
    class Reviews { 
    1616         */
    1717        static function display() {
    1818                $reviews      = Tools::get_plugin_reviews( get_post()->post_name );
     19                $replies      = Tools::get_reviews_replies( wp_list_pluck( $reviews, 'ID' ) );
    1920                $ratings      = get_post_meta( get_the_ID(), 'ratings', true ) ?: array();
    2021                $review_count = array_sum( $ratings );
    2122
    class Reviews { 
    3940                        foreach ( $reviews as $review ) {
    4041                                $GLOBALS['post'] = $review; // Override the_post();
    4142                                setup_postdata( $review );
     43                                $reply_matches = wp_list_filter( $replies, [ 'post_parent' => $review->ID ] );
     44                                $reply_count = Count( $reply_matches );
     45
    4246                                ?>
    4347                                <article class="plugin-review">
    4448                                        <div class="review-avatar">
    class Reviews { 
    4751                                                <header>
    4852                                                        <div class="header-top">
    4953                                                                <?php echo Template::dashicons_stars( $review->post_rating ); ?>
    50                                                                 <h3 class="review-title"><a class="url" href="<?php echo esc_url( 'https://wordpress.org/support/topic/' . $review->post_name . '/' ); ?>"><?php echo get_the_title( $review ); ?></a></h3>
     54                                                                <h3 class="review-title">
     55                                                                        <a class="url" href="<?php echo esc_url( 'https://wordpress.org/support/topic/' . $review->post_name . '/' ); ?>"><?php echo get_the_title( $review ); ?></a>
     56                                                                        <span class="review-title-comments">
     57                                                                                <?php printf( _n( '%s comment', '%s comments', $reply_count, 'wporg-plugins' ), number_format_i18n( $reply_count ) ); ?>
     58                                                                        </span>
     59                                                                </h3>
    5160                                                        </div>
    5261                                                        <div class="header-bottom">
    5362                                                                <span class="review-author author vcard"><?php the_author_posts_link(); ?></span>
  • wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/sections/reviews/style.scss

    diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/sections/reviews/style.scss wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/sections/reviews/style.scss
    index 6244018a5..a76a7ad21 100644
     
    4949                line-height: 1.25;
    5050        }
    5151
     52        .review-title-comments {
     53                padding-left: 8px;
     54                font-size: 13px;
     55                font-weight: normal;
     56                font-style: italic;
     57                color: #666;
     58        }
     59
    5260        .review-author,
    5361        .review-date {
    5462                line-height: 1.25;