Changeset 3039
- Timestamp:
- 04/28/2016 08:30:43 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-ratings.php
r3020 r3039 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Widgets; 3 4 3 use WordPressdotorg\Plugin_Directory\Template; 5 4 … … 30 29 $post = get_post(); 31 30 32 $rating = get_post_meta( $post->ID, 'rating', true );33 $ratings = get_post_meta( $post->ID, 'ratings', true);31 $rating = get_post_meta( $post->ID, 'rating', true ); 32 $ratings = get_post_meta( $post->ID, 'ratings', true ) ?: array(); 34 33 $num_ratings = array_sum( $ratings ); 35 34 36 35 $user_rating = 0; 37 if ( is_user_logged_in() ) {36 if ( is_user_logged_in() && function_exists( 'wporg_get_user_rating' ) ) { 38 37 $user_rating = wporg_get_user_rating( 'plugin', $post->post_name, get_current_user_id() ); 39 38 if ( ! $user_rating ) { … … 47 46 <h4><?php _e( 'Ratings', 'wporg-plugins' ); ?></h4> 48 47 49 <?php if ( $rating ) {?>50 51 52 53 54 <?php } else {?>55 56 57 58 <?php } ?>48 <?php if ( $rating ) : ?> 49 <div class="rating"> 50 <?php echo Template::dashicons_stars( $rating ); ?> 51 <p class="description"><?php printf( __( '%s out of 5 stars.', 'wporg-plugins' ), '<span itemprop="ratingValue">' . $rating . '</span>' ); ?></p> 52 </div> 53 <?php else : ?> 54 <div class="rating"> 55 <div class="ratings"><?php _e( 'This plugin has not been rated yet.', 'wporg-plugins' ); ?></div> 56 </div> 57 <?php endif; // $rating 59 58 60 <?php if ( $ratings ) {?>59 if ( $ratings ) : ?> 61 60 <ul class="ratings-list"> 62 61 <?php foreach ( range( 5, 1 ) as $stars ) : 63 $rating_bar_width = $num_ratings ? 100 * $ratings[ $stars] / $num_ratings : 0;62 $rating_bar_width = $num_ratings ? 100 * $ratings[ $stars ] / $num_ratings : 0; 64 63 ?> 65 64 <li class="counter-container"> … … 69 68 <span class="counter-bar" style="width: <?php echo $rating_bar_width; ?>%;"></span> 70 69 </span> 71 <span class="counter-count"><?php echo $ratings[ $stars]; ?></span>70 <span class="counter-count"><?php echo $ratings[ $stars ]; ?></span> 72 71 </a> 73 72 </li> … … 75 74 </ul> 76 75 <?php 77 }76 endif; // $ratings 78 77 79 78 if ( is_user_logged_in() ) { … … 134 133 </script> 135 134 <?php 136 137 135 } 138 136 139 137 echo $args['after_widget']; 140 138 } 141 142 139 } 143
Note: See TracChangeset
for help on using the changeset viewer.