WordPress.org

Making WordPress.org

Changeset 7282


Ignore:
Timestamp:
06/07/2018 04:32:31 AM (15 months ago)
Author:
dd32
Message:

Plugin Directory: Use WPORG_Ratings for the plugin rating/ratings when available.

Fixes #2606.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php

    r6287 r7282  
    116116        $result['requires_php']  = get_post_meta( $post_id, 'requires_php', true ) ?: false;
    117117        $result['compatibility'] = array();
    118         $result['rating']        = ( get_post_meta( $post_id, 'rating', true ) ?: 0 ) * 20; // Stored as 0.0 ~ 5.0, API outputs as 0..100
    119         $result['ratings']       = array_map( 'intval', (array) get_post_meta( $post_id, 'ratings', true ) );
     118
     119        if ( class_exists( '\WPORG_Ratings' ) ) {
     120            $result['rating']  = \WPORG_Ratings::get_avg_rating( 'plugin', $post->post_name ) ?: 0;
     121            $result['ratings'] = \WPORG_Ratings::get_rating_counts( 'plugin', $post->post_name ) ?: array();
     122        } else {
     123            $result['rating']  = get_post_meta( $post->ID, 'rating', true ) ?: 0;
     124            $result['ratings'] = get_post_meta( $post->ID, 'ratings', true ) ?: array();
     125        }
     126
     127        $result['rating']  = $result['rating'] * 20; // Stored as 0.0 ~ 5.0, API outputs as 0..100
     128        $result['ratings'] = array_map( 'intval', $result['ratings'] );
    120129        krsort( $result['ratings'] );
    121130
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r7075 r7282  
    231231        $post = get_post( $post );
    232232
    233         $rating      = get_post_meta( $post->ID, 'rating', true ) ?: 0;
    234         $ratings     = get_post_meta( $post->ID, 'ratings', true ) ?: array();
     233        if ( class_exists( '\WPORG_Ratings' ) ) {
     234            $rating  = \WPORG_Ratings::get_avg_rating( 'plugin', $post->post_name ) ?: 0;
     235            $ratings = \WPORG_Ratings::get_rating_counts( 'plugin', $post->post_name ) ?: array();
     236        } else {
     237            $rating  = get_post_meta( $post->ID, 'rating', true ) ?: 0;
     238            $ratings = get_post_meta( $post->ID, 'ratings', true ) ?: array();
     239        }
     240
    235241        $num_ratings = array_sum( $ratings );
    236242
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-ratings.php

    r6287 r7282  
    2929    public function widget( $args, $instance ) {
    3030        $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Ratings', 'wporg-plugins' ) : $instance['title'], $instance, $this->id_base );
     31        $post  = get_post();
    3132
    32         $post        = get_post();
    33         $rating      = get_post_meta( $post->ID, 'rating', true ) ?: 0;
    34         $ratings     = get_post_meta( $post->ID, 'ratings', true ) ?: array();
     33        if ( class_exists( '\WPORG_Ratings' ) ) {
     34            $rating  = \WPORG_Ratings::get_avg_rating( 'plugin', $post->post_name ) ?: 0;
     35            $ratings = \WPORG_Ratings::get_rating_counts( 'plugin', $post->post_name ) ?: array();
     36        } else {
     37            $rating  = get_post_meta( $post->ID, 'rating', true ) ?: 0;
     38            $ratings = get_post_meta( $post->ID, 'ratings', true ) ?: array();
     39        }
     40
    3541        $num_ratings = array_sum( $ratings );
    3642
Note: See TracChangeset for help on using the changeset viewer.