Making WordPress.org

Changeset 14504


Ignore:
Timestamp:
08/01/2025 07:26:08 AM (14 months ago)
Author:
dd32
Message:

Plugin Directory: Reviewer Tools: Display the number of installs of the latest version of a plugin in the controls metabox.

This is only displayed privately for now to determine the performance of the queries nad viability of use within the Release rollout functionality for "progress of update".

See #8009.

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/admin/metabox/class-controls.php

    r14246 r14504  
    221221                        </tr>
    222222
     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
    223240                        <?php if ( $post->tested ) : ?>
    224241                        <tr>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php

    r13743 r14504  
    44use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    55use WordPressdotorg\Plugin_Directory\API\Base;
     6use WordPressdotorg\Plugin_Directory\Template;
    67
    78/**
    … …  
    5657                                        update_post_meta( $plugin->ID, '_active_installs', wp_slash( $value ) );
    5758
    58                                         $value = $this->sanitize_active_installs( $value );
     59                                        $value = Template::sanitize_active_installs( $value );
    5960                                } elseif ( 'usage' == $stat_name ) {
    6061                                        $value = $this->sanitize_usage_numbers( $value, $plugin );
    … …  
    7071
    7172                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 0
    96                         $round = 10;
    97                 }
    98 
    99                 return floor( $active_installs / $round ) * $round;
    10073        }
    10174
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r14503 r14504  
    250250        public static function active_installs( $full = true, $post = null ) {
    251251                $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.
    253253
    254254                if ( 'closed' === $post->post_status ) {
    255255                        $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 ) {
    259277                        $million_count = intdiv( $count, 1000000 );
     278
    260279                        /* 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;
    262308                } 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;
    267314        }
    268315
Note: See TracChangeset for help on using the changeset viewer.