Changeset 9140
- Timestamp:
- 09/15/2019 04:47:58 PM (5 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php
r9127 r9140 222 222 $result['block_assets'] = get_post_meta( $post_id, 'block_files', true ) ?: []; 223 223 $result['author_block_count'] = get_post_meta( $post_id, 'author_block_count' ) ?: intval( count( $result['blocks'] ) > 0 ); 224 $result['author_block_rating'] = get_post_meta( $post_id, 'author_block_rating' ) ?: $result['rating']; 224 // Fun fact: ratings are stored as 1-5 in postmeta, but returned as percentages by the API 225 $result['author_block_rating'] = get_post_meta( $post_id, 'author_block_rating' ) ? 20 * get_post_meta( $post_id, 'author_block_rating' ) : $result['rating']; 225 226 226 227 // That's all folks! -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-meta-sync.php
r8918 r9140 92 92 \WPORG_Ratings::get_rating_counts( 'plugin', $post->post_name ) 93 93 ); 94 95 $author_block_query = new \WP_Query( array( 96 'author' => $post->post_author, 97 'post_status' => 'publish', 98 'tax_query' => array( 99 array( 100 'taxonomy' => 'plugin_section', 101 'field' => 'slug', 102 'terms' => 'block', 103 ) 104 ), 105 'posts_per_page' => 10, 106 ) ); 107 108 $author_block_count = $author_block_query->found_posts; 109 110 $author_block_slugs = wp_list_pluck( $author_block_query->posts, 'post_name' ); 111 112 update_post_meta( 113 $post->ID, 114 'author_block_count', 115 $author_block_count 116 ); 117 118 if ( count( $author_block_slugs ) > 0 ) { 119 120 // Grab the ratings and counts for each separate block plugin, and use that to calculate the author's average rating 121 $author_rating_total = $author_rating_count = 0; 122 foreach ( $author_block_slugs as $block_slug ) { 123 $block_ratings = \WPORG_Ratings::get_rating_counts( 'plugin', $block_slug ); 124 if ( $block_ratings ) { 125 foreach ( $block_ratings as $rating => $rating_count ) { 126 $author_rating_total += ( $rating * $rating_count ); 127 $author_rating_count += $rating_count; 128 } 129 }; 130 } 131 132 if ( $author_rating_count ) { 133 $avg_block_rating = $author_rating_total / $author_rating_count; 134 update_post_meta( 135 $post->ID, 136 'author_block_rating', 137 $avg_block_rating 138 ); 139 } 140 141 } 94 142 } 95 143
Note: See TracChangeset
for help on using the changeset viewer.