Make WordPress Core

Changeset 27923


Ignore:
Timestamp:
04/03/2014 03:58:30 AM (11 years ago)
Author:
nacin
Message:

Background Updates: Record plugin & theme update statistics like we do for core updates.

Pass plugin/theme update objects into the Background updater for consistency with core & translations.

Merges [27905] to the 3.8 branch.

props dd32.
fixes #27633.

Location:
branches/3.8
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8

  • branches/3.8/src/wp-admin/includes/class-wp-upgrader.php

    r26851 r27923  
    18721872            return false;
    18731873
     1874        $upgrader_item = $item;
    18741875        switch ( $type ) {
    18751876            case 'core':
     
    18781879                break;
    18791880            case 'theme':
    1880                 $theme = wp_get_theme( $item );
     1881                $upgrader_item = $item->theme;
     1882                $theme = wp_get_theme( $upgrader_item );
    18811883                $item_name = $theme->Get( 'Name' );
    18821884                $skin->feedback( __( 'Updating theme: %s' ), $item_name );
    18831885                break;
    18841886            case 'plugin':
    1885                 $plugin_data = get_plugin_data( $context . '/' . $item );
     1887                $upgrader_item = $item->plugin;
     1888                $plugin_data = get_plugin_data( $context . '/' . $upgrader_item );
    18861889                $item_name = $plugin_data['Name'];
    18871890                $skin->feedback( __( 'Updating plugin: %s' ), $item_name );
     
    18951898
    18961899        // Boom, This sites about to get a whole new splash of paint!
    1897         $upgrade_result = $upgrader->upgrade( $item, array(
     1900        $upgrade_result = $upgrader->upgrade( $upgrader_item, array(
    18981901            'clear_update_cache' => false,
    18991902            'pre_check_md5'      => false, /* always use partial builds if possible for core updates */
     
    19691972        $plugin_updates = get_site_transient( 'update_plugins' );
    19701973        if ( $plugin_updates && !empty( $plugin_updates->response ) ) {
    1971             foreach ( array_keys( $plugin_updates->response ) as $plugin ) {
     1974            foreach ( $plugin_updates->response as $plugin ) {
    19721975                $this->update( 'plugin', $plugin );
    19731976            }
     
    19801983        $theme_updates = get_site_transient( 'update_themes' );
    19811984        if ( $theme_updates && !empty( $theme_updates->response ) ) {
    1982             foreach ( array_keys( $theme_updates->response ) as $theme ) {
    1983                 $this->update( 'theme', $theme );
     1985            foreach ( $theme_updates->response as $theme ) {
     1986                $this->update( 'theme', (object) $theme );
    19841987            }
    19851988            // Force refresh of theme update information
     
    19961999        // Clean up, and check for any pending translations
    19972000        // (Core_Upgrader checks for core updates)
    1998         wp_update_themes();  // Check for Theme updates
    1999         wp_update_plugins(); // Check for Plugin updates
     2001        $theme_stats = array();
     2002        if ( isset( $this->update_results['theme'] ) ) {
     2003            foreach ( $this->update_results['theme'] as $upgrade ) {
     2004                $theme_stats[ $upgrade->item->theme ] = ( true === $upgrade->result );
     2005            }
     2006        }
     2007        wp_update_themes( $theme_stats );  // Check for Theme updates
     2008
     2009        $plugin_stats = array();
     2010        if ( isset( $this->update_results['plugin'] ) ) {
     2011            foreach ( $this->update_results['plugin'] as $upgrade ) {
     2012                $plugin_stats[ $upgrade->item->plugin ] = ( true === $upgrade->result );
     2013            }
     2014        }
     2015        wp_update_plugins( $plugin_stats ); // Check for Plugin updates
    20002016
    20012017        // Finally, Process any new translations
  • branches/3.8/src/wp-includes/update.php

    r26192 r27923  
    169169 * @uses $wp_version Used to notify the WordPress version.
    170170 *
     171 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    171172 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
    172173 */
    173 function wp_update_plugins() {
     174function wp_update_plugins( $extra_stats = array() ) {
    174175    include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
    175176
     
    210211    $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
    211212
    212     if ( $time_not_changed ) {
     213    if ( $time_not_changed && ! $extra_stats ) {
    213214        $plugin_changed = false;
    214215        foreach ( $plugins as $file => $p ) {
     
    259260    );
    260261
     262    if ( $plugin_update_stats ) {
     263        $options['body']['update_stats'] = json_encode( $extra_stats );
     264    }
     265
    261266    $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/';
    262267    if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
     
    300305 * @uses $wp_version Used to notify the WordPress version.
    301306 *
     307 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    302308 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
    303309 */
    304 function wp_update_themes() {
     310function wp_update_themes( $extra_stats = array() ) {
    305311    include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
    306312
     
    352358    $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
    353359
    354     if ( $time_not_changed ) {
     360    if ( $time_not_changed && ! $extra_stats ) {
    355361        $theme_changed = false;
    356362        foreach ( $checked as $slug => $v ) {
     
    398404        'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    399405    );
     406
     407    if ( $theme_update_stats ) {
     408        $options['body']['update_stats'] = json_encode( $extra_stats );
     409    }
    400410
    401411    $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
Note: See TracChangeset for help on using the changeset viewer.