Make WordPress Core

Changeset 15455


Ignore:
Timestamp:
07/22/2010 01:24:41 PM (14 years ago)
Author:
ryan
Message:

Clean up wp_update_themes(). Fix reporting of active theme. Props josephscott. fixes #14381 for 3.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/update.php

    r14010 r15455  
    212212
    213213    $installed_themes = get_themes( );
    214     $current_theme = get_site_transient( 'update_themes' );
    215     if ( ! is_object($current_theme) )
    216         $current_theme = new stdClass;
    217 
    218     $new_option = new stdClass;
    219     $new_option->last_checked = time( );
     214    $last_update = get_site_transient( 'update_themes' );
     215    if ( ! is_object($last_update) )
     216        $last_update = new stdClass;
     217
    220218    $timeout = 'load-themes.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
    221     $time_not_changed = isset( $current_theme->last_checked ) && $timeout > ( time( ) - $current_theme->last_checked );
     219    $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time( ) - $last_update->last_checked );
    222220
    223221    $themes = array();
    224222    $checked = array();
    225     $themes['current_theme'] = (array) $current_theme;
     223    $exclude_fields = array('Template Files', 'Stylesheet Files', 'Status', 'Theme Root', 'Theme Root URI', 'Template Dir', 'Stylesheet Dir', 'Description', 'Tags', 'Screenshot');
     224
     225    // Put slug of current theme into request.
     226    $themes['current_theme'] = get_option( 'stylesheet' );
     227
    226228    foreach ( (array) $installed_themes as $theme_title => $theme ) {
    227229        $themes[$theme['Stylesheet']] = array();
    228230        $checked[$theme['Stylesheet']] = $theme['Version'];
    229231
    230         foreach ( (array) $theme as $key => $value )
    231             $themes[$theme['Stylesheet']][$key] = $value;
     232        $themes[$theme['Stylesheet']]['Name'] = $theme['Name'];
     233        $themes[$theme['Stylesheet']]['Version'] = $theme['Version'];
     234
     235        foreach ( (array) $theme as $key => $value ) {
     236            if ( !in_array($key, $exclude_fields) )
     237                $themes[$theme['Stylesheet']][$key] = $value;
     238        }
    232239    }
    233240
    234241    $theme_changed = false;
    235242    foreach ( $checked as $slug => $v ) {
    236         $new_option->checked[ $slug ] = $v;
    237 
    238         if ( !isset( $current_theme->checked[ $slug ] ) || strval($current_theme->checked[ $slug ]) !== strval($v) )
     243        $update_request->checked[ $slug ] = $v;
     244
     245        if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
    239246            $theme_changed = true;
    240247    }
    241248
    242     if ( isset ( $current_theme->response ) && is_array( $current_theme->response ) ) {
    243         foreach ( $current_theme->response as $slug => $update_details ) {
     249    if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
     250        foreach ( $last_update->response as $slug => $update_details ) {
    244251            if ( ! isset($checked[ $slug ]) ) {
    245252                $theme_changed = true;
     
    253260
    254261    // Update last_checked for current to prevent multiple blocking requests if request hangs
    255     $current_theme->last_checked = time();
    256     set_site_transient( 'update_themes', $current_theme );
    257 
    258     $current_theme->template = get_option( 'template' );
     262    $last_update->last_checked = time();
     263    set_site_transient( 'update_themes', $last_update );
    259264
    260265    $options = array(
     
    272277        return false;
    273278
     279    $new_update = new stdClass;
     280    $new_update->last_checked = time( );
    274281    $response = unserialize( $raw_response['body'] );
    275282    if ( $response ) {
    276         $new_option->checked = $checked;
    277         $new_option->response = $response;
    278     }
    279 
    280     set_site_transient( 'update_themes', $new_option );
     283        $new_update->checked = $checked;
     284        $new_update->response = $response;
     285    }
     286
     287    set_site_transient( 'update_themes', $new_update );
    281288}
    282289
Note: See TracChangeset for help on using the changeset viewer.