Changeset 14504
- Timestamp:
- 08/01/2025 07:26:08 AM (11 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 3 edited
-
admin/metabox/class-controls.php (modified) (1 diff)
-
api/routes/class-internal-stats.php (modified) (3 diffs)
-
class-template.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-controls.php
r14246 r14504 221 221 </tr> 222 222 223 <?php if ( 224 function_exists( 'WordPressdotorg\Stats\plugin_active_installs' ) && 225 $post->version && 226 'publish' === $post->post_status 227 ): ?> 228 <tr> 229 <td><?php echo esc_html( "Installs of {$post->version}:" ); ?></td> 230 <td><strong><?php 231 echo Template::format_active_installs_for_display( 232 Template::sanitize_active_installs( 233 \WordPressdotorg\Stats\plugin_active_installs( $post->post_name, $post->version ) 234 ) 235 ); 236 ?></strong></td> 237 </tr> 238 <?php endif; ?> 239 223 240 <?php if ( $post->tested ) : ?> 224 241 <tr> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php
r13743 r14504 4 4 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 5 5 use WordPressdotorg\Plugin_Directory\API\Base; 6 use WordPressdotorg\Plugin_Directory\Template; 6 7 7 8 /** … … 56 57 update_post_meta( $plugin->ID, '_active_installs', wp_slash( $value ) ); 57 58 58 $value = $this->sanitize_active_installs( $value );59 $value = Template::sanitize_active_installs( $value ); 59 60 } elseif ( 'usage' == $stat_name ) { 60 61 $value = $this->sanitize_usage_numbers( $value, $plugin ); … … 70 71 71 72 return true; 72 }73 74 /**75 * Sanitizes the Active Install count number to a rounded display value.76 *77 * @param int $active_installs The raw active install number.78 * @return int The sanitized version for display.79 */80 protected function sanitize_active_installs( $active_installs ) {81 if ( $active_installs > 10000000 ) {82 // 10 million +83 return 10000000;84 } elseif ( $active_installs > 1000000 ) {85 $round = 1000000;86 } elseif ( $active_installs > 100000 ) {87 $round = 100000;88 } elseif ( $active_installs > 10000 ) {89 $round = 10000;90 } elseif ( $active_installs > 1000 ) {91 $round = 1000;92 } elseif ( $active_installs > 100 ) {93 $round = 100;94 } else {95 // Rounded to ten, else 096 $round = 10;97 }98 99 return floor( $active_installs / $round ) * $round;100 73 } 101 74 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r14503 r14504 250 250 public static function active_installs( $full = true, $post = null ) { 251 251 $post = get_post( $post ); 252 $count = get_post_meta( $post->ID, 'active_installs', true ) ?: 0; 252 $count = get_post_meta( $post->ID, 'active_installs', true ) ?: 0; // Already sanitized to a round number. 253 253 254 254 if ( 'closed' === $post->post_status ) { 255 255 $text = __( 'N/A', 'wporg-plugins' ); 256 } elseif ( $count < 10 ) { 257 $text = __( 'Fewer than 10', 'wporg-plugins' ); 258 } elseif ( $count >= 1000000 ) { 256 } else { 257 $text = self::format_active_installs_for_display( $count ); 258 } 259 260 return $full ? sprintf( __( '%s active installations', 'wporg-plugins' ), $text ) : $text; 261 } 262 263 /** 264 * Formats the active installs count for display. 265 * 266 * @static 267 * 268 * @param int $count The active installs count. 269 * @return string The formatted count. 270 */ 271 public static function format_active_installs_for_display( $count ) { 272 if ( $count < 10 ) { 273 return __( 'Fewer than 10', 'wporg-plugins' ); 274 } 275 276 if ( $count >= 1000000 ) { 259 277 $million_count = intdiv( $count, 1000000 ); 278 260 279 /* translators: %d: The integer number of million active installs */ 261 $text = sprintf( _n( '%d+ million', '%d+ million', $million_count, 'wporg-plugins' ), $million_count ); 280 return sprintf( _n( '%d+ million', '%d+ million', $million_count, 'wporg-plugins' ), $million_count ); 281 } 282 283 return number_format_i18n( $count ) . '+'; 284 } 285 286 /** 287 * Sanitizes the Active Install count number to a rounded display value. 288 * 289 * @static 290 * 291 * @param int $active_installs The raw active install number. 292 * @return int The sanitized version for display. 293 */ 294 public static function sanitize_active_installs( $active_installs ) { 295 if ( $active_installs > 10000000 ) { 296 // 10 million + 297 return 10000000; 298 } elseif ( $active_installs > 1000000 ) { 299 $round = 1000000; 300 } elseif ( $active_installs > 100000 ) { 301 $round = 100000; 302 } elseif ( $active_installs > 10000 ) { 303 $round = 10000; 304 } elseif ( $active_installs > 1000 ) { 305 $round = 1000; 306 } elseif ( $active_installs > 100 ) { 307 $round = 100; 262 308 } else { 263 $text = number_format_i18n( $count ) . '+'; 264 } 265 266 return $full ? sprintf( __( '%s active installations', 'wporg-plugins' ), $text ) : $text; 309 // Rounded to ten, else 0 310 $round = 10; 311 } 312 313 return floor( $active_installs / $round ) * $round; 267 314 } 268 315
Note: See TracChangeset
for help on using the changeset viewer.