Make WordPress Core

Changeset 27924 for branches/3.7


Ignore:
Timestamp:
04/03/2014 04:02:35 AM (12 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.7 branch.

props dd32.
fixes #27633.

Location:
branches/3.7
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

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

    r27883 r27924  
    18731873                        return false;
    18741874
     1875                $upgrader_item = $item;
    18751876                switch ( $type ) {
    18761877                        case 'core':
     
    18791880                                break;
    18801881                        case 'theme':
    1881                                 $theme = wp_get_theme( $item );
     1882                                $upgrader_item = $item->theme;
     1883                                $theme = wp_get_theme( $upgrader_item );
    18821884                                $item_name = $theme->Get( 'Name' );
    18831885                                $skin->feedback( __( 'Updating theme: %s' ), $item_name );
    18841886                                break;
    18851887                        case 'plugin':
    1886                                 $plugin_data = get_plugin_data( $context . '/' . $item );
     1888                                $upgrader_item = $item->plugin;
     1889                                $plugin_data = get_plugin_data( $context . '/' . $upgrader_item );
    18871890                                $item_name = $plugin_data['Name'];
    18881891                                $skin->feedback( __( 'Updating plugin: %s' ), $item_name );
     
    18961899
    18971900                // Boom, This sites about to get a whole new splash of paint!
    1898                 $upgrade_result = $upgrader->upgrade( $item, array(
     1901                $upgrade_result = $upgrader->upgrade( $upgrader_item, array(
    18991902                        'clear_update_cache' => false,
    19001903                        'pre_check_md5'      => false, /* always use partial builds if possible for core updates */
     
    19701973                $plugin_updates = get_site_transient( 'update_plugins' );
    19711974                if ( $plugin_updates && !empty( $plugin_updates->response ) ) {
    1972                         foreach ( array_keys( $plugin_updates->response ) as $plugin ) {
     1975                        foreach ( $plugin_updates->response as $plugin ) {
    19731976                                $this->update( 'plugin', $plugin );
    19741977                        }
     
    19811984                $theme_updates = get_site_transient( 'update_themes' );
    19821985                if ( $theme_updates && !empty( $theme_updates->response ) ) {
    1983                         foreach ( array_keys( $theme_updates->response ) as $theme ) {
    1984                                 $this->update( 'theme', $theme );
     1986                        foreach ( $theme_updates->response as $theme ) {
     1987                                $this->update( 'theme', (object) $theme );
    19851988                        }
    19861989                        // Force refresh of theme update information
     
    19972000                // Clean up, and check for any pending translations
    19982001                // (Core_Upgrader checks for core updates)
    1999                 wp_update_themes();  // Check for Theme updates
    2000                 wp_update_plugins(); // Check for Plugin updates
     2002                $theme_stats = array();
     2003                if ( isset( $this->update_results['theme'] ) ) {
     2004                        foreach ( $this->update_results['theme'] as $upgrade ) {
     2005                                $theme_stats[ $upgrade->item->theme ] = ( true === $upgrade->result );
     2006                        }
     2007                }
     2008                wp_update_themes( $theme_stats );  // Check for Theme updates
     2009
     2010                $plugin_stats = array();
     2011                if ( isset( $this->update_results['plugin'] ) ) {
     2012                        foreach ( $this->update_results['plugin'] as $upgrade ) {
     2013                                $plugin_stats[ $upgrade->item->plugin ] = ( true === $upgrade->result );
     2014                        }
     2015                }
     2016                wp_update_plugins( $plugin_stats ); // Check for Plugin updates
    20012017
    20022018                // Finally, Process any new translations
  • branches/3.7/src/wp-includes/update.php

    r26450 r27924  
    161161 * @uses $wp_version Used to notify the WordPress version.
    162162 *
     163 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    163164 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
    164165 */
    165 function wp_update_plugins() {
     166function wp_update_plugins( $extra_stats = array() ) {
    166167        include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
    167168
     
    202203        $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
    203204
    204         if ( $time_not_changed ) {
     205        if ( $time_not_changed && ! $extra_stats ) {
    205206                $plugin_changed = false;
    206207                foreach ( $plugins as $file => $p ) {
     
    251252        );
    252253
     254        if ( $plugin_update_stats ) {
     255                $options['body']['update_stats'] = json_encode( $extra_stats );
     256        }
     257
    253258        $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/';
    254259        if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
     
    292297 * @uses $wp_version Used to notify the WordPress version.
    293298 *
     299 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    294300 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
    295301 */
    296 function wp_update_themes() {
     302function wp_update_themes( $extra_stats = array() ) {
    297303        include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
    298304
     
    344350        $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
    345351
    346         if ( $time_not_changed ) {
     352        if ( $time_not_changed && ! $extra_stats ) {
    347353                $theme_changed = false;
    348354                foreach ( $checked as $slug => $v ) {
     
    390396                'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    391397        );
     398
     399        if ( $theme_update_stats ) {
     400                $options['body']['update_stats'] = json_encode( $extra_stats );
     401        }
    392402
    393403        $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
Note: See TracChangeset for help on using the changeset viewer.