Make WordPress Core

Ticket #35301: 35301.2.diff

File 35301.2.diff, 6.8 KB (added by dd32, 9 years ago)

35301.diff with less debug output & a simpler convert-to-object routine.

  • src/wp-admin/update-core.php

    function list_plugin_updates() { 
    241241<p><?php _e( 'The following plugins have new versions available. Check the ones you want to update and then click &#8220;Update Plugins&#8221;.' ); ?></p>
    242242<form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
    243243<?php wp_nonce_field('upgrade-core'); ?>
    244244<p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
    245245<table class="widefat" id="update-plugins-table">
    246246        <thead>
    247247        <tr>
    248248                <td scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>
    249249                <th scope="col" class="manage-column"><label for="plugins-select-all"><?php _e('Select All'); ?></label></th>
    250250        </tr>
    251251        </thead>
    252252
    253253        <tbody class="plugins">
    254254<?php
    255255        foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
    256                 $info = plugins_api( 'plugin_information', array(
    257                         'slug' => $plugin_data->update->slug,
    258                         'fields' => array(
    259                                 'short_description' => false,
    260                                 'sections' => false,
    261                                 'requires' => false,
    262                                 'rating' => false,
    263                                 'ratings' => false,
    264                                 'downloaded' => false,
    265                                 'downloadlink' => false,
    266                                 'last_updated' => false,
    267                                 'added' => false,
    268                                 'tags' => false,
    269                                 'homepage' => false,
    270                                 'donate_link' => false,
    271                         ),
    272                 ) );
    273 
    274                 if ( is_wp_error( $info ) ) {
    275                         $info = false;
    276                 }
    277 
    278256                // Get plugin compat for running version of WordPress.
    279                 if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
     257                if ( isset($plugin_data->update->tested) && version_compare($plugin_data->update->tested, $cur_wp_version, '>=') ) {
    280258                        $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
    281                 } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
    282                         $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
    283                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $cur_wp_version, $compat[0], $compat[2], $compat[1]);
     259                } elseif ( isset($plugin_data->update->compatibility->{$cur_wp_version}) ) {
     260                        $compat = $plugin_data->update->compatibility->{$cur_wp_version};
     261                        $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $cur_wp_version, $compat->percent, $compat->votes, $compat->total_votes);
    284262                } else {
    285263                        $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
    286264                }
    287265                // Get plugin compat for updated version of WordPress.
    288266                if ( $core_update_version ) {
    289                         if ( isset( $info->tested ) && version_compare( $info->tested, $core_update_version, '>=' ) ) {
     267                        if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
    290268                                $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
    291                         } elseif ( isset( $info->compatibility[ $core_update_version ][ $plugin_data->update->new_version ] ) ) {
    292                                 $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
    293                                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $core_update_version, $update_compat[0], $update_compat[2], $update_compat[1]);
     269                        } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) {
     270                                $update_compat = $plugin_data->update->compatibility->{$core_update_version};
     271                                $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $core_update_version, $update_compat->percent, $update_compat->votes, $update_compat->total_votes);
    294272                        } else {
    295273                                $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
    296274                        }
    297275                }
    298276                // Get the upgrade notice for the new plugin version.
    299277                if ( isset($plugin_data->update->upgrade_notice) ) {
    300278                        $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
    301279                } else {
    302280                        $upgrade_notice = '';
    303281                }
    304282
    305283                $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&section=changelog&TB_iframe=true&width=640&height=662');
    306284                $details_name = sprintf( '<span class="screen-reader-text">%1$s</span>', esc_attr( $plugin_data->Name ) );
    307285                /* translators: 1: Plugin name 2: Plugin version */
    308286                $details_text = sprintf( __( 'View %1$s version %2$s details.' ), $details_name, $plugin_data->update->new_version );
  • src/wp-includes/update.php

    function wp_update_plugins( $extra_stats 
    298298                $url = set_url_scheme( $url, 'https' );
    299299
    300300        $raw_response = wp_remote_post( $url, $options );
    301301        if ( $ssl && is_wp_error( $raw_response ) ) {
    302302                trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
    303303                $raw_response = wp_remote_post( $http_url, $options );
    304304        }
    305305
    306306        if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
    307307                return;
    308308        }
    309309
    310310        $response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
    311311        foreach ( $response['plugins'] as &$plugin ) {
    312312                $plugin = (object) $plugin;
     313                if ( $plugin->compatibility ) {
     314                        $plugin->compatibility = (object) $plugin->compatibility;
     315                        foreach ( $plugin->compatibility as $version => $data ) {
     316                                $plugin->compatibility->{$version} = (object) $data;
     317                        }
     318                }
    313319        }
    314         unset( $plugin );
     320        unset( $plugin, $_compat, $version, $data );
    315321        foreach ( $response['no_update'] as &$plugin ) {
    316322                $plugin = (object) $plugin;
    317323        }
    318324        unset( $plugin );
    319325
    320326        if ( is_array( $response ) ) {
    321327                $new_option->response = $response['plugins'];
    322328                $new_option->translations = $response['translations'];
    323329                // TODO: Perhaps better to store no_update in a separate transient with an expiry?
    324330                $new_option->no_update = $response['no_update'];
    325331        } else {
    326332                $new_option->response = array();
    327333                $new_option->translations = array();
    328334                $new_option->no_update = array();
    329335        }