Changeset 6287 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php
- Timestamp:
- 12/19/2017 04:22:37 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php
r5839 r6287 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\API\Routes; 3 3 4 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 4 5 use WordPressdotorg\Plugin_Directory\API\Base; … … 19 20 function __construct() { 20 21 register_rest_route( 'plugins/v1', '/update-stats', array( 21 'methods' => \WP_REST_Server::CREATABLE,22 'callback' => array( $this, 'bulk_update_stats' ),22 'methods' => \WP_REST_Server::CREATABLE, 23 'callback' => array( $this, 'bulk_update_stats' ), 23 24 'permission_callback' => array( $this, 'permission_check_internal_api_bearer' ), 24 25 ) ); … … 112 113 protected function sanitize_usage_numbers( $usage, $plugin ) { 113 114 $latest_version = get_post_meta( $plugin->ID, 'version', true ) ?: '0.0'; 114 $latest_branch = implode( '.', array_slice( explode('.', $latest_version ), 0, 2 ) );115 $latest_branch = implode( '.', array_slice( explode( '.', $latest_version ), 0, 2 ) ); 115 116 116 117 // Exclude any version strings higher than the latest plugin version (ie. 99.9) … … 126 127 127 128 // Calculate the percentage of each version branch 128 $total = array_sum( $usage );129 $total = array_sum( $usage ); 129 130 $others = array(); 130 131 foreach ( $usage as $version => $count ) { … … 141 142 // If there was only one version < $percent_cut_off then display it as-is 142 143 if ( count( $others ) == 1 ) { 143 $version = array_keys( $others );144 $version = array_shift( $version );144 $version = array_keys( $others ); 145 $version = array_shift( $version ); 145 146 $usage[ $version ] = round( $others[ $version ] / $total * 100, 2 ); 146 // Else we'll add an 'others' version.147 // Else we'll add an 'others' version. 147 148 } elseif ( count( $others ) > 1 ) { 148 149 $usage['other'] = round( array_sum( $others ) / $total * 100, 2 );
Note: See TracChangeset
for help on using the changeset viewer.