Make WordPress Core

Changeset 10221


Ignore:
Timestamp:
12/18/2008 05:23:20 PM (15 years ago)
Author:
ryan
Message:

Plugin and theme udpdate check fixes. Props DD32. fixes #8660 for trunk

File:
1 edited

Legend:

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

    r10150 r10221  
    5151
    5252    $options = array('timeout' => 3);
    53     $options['headers'] = array(
    54         'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
    55         'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
    56     );
    57 
    58     $response = wp_remote_request($url, $options);
     53
     54    $response = wp_remote_get($url, $options);
    5955
    6056    if ( is_wp_error( $response ) )
     
    119115        $current = new stdClass;
    120116
    121     $new_option = '';
     117    $new_option = new stdClass;
    122118    $new_option->last_checked = time();
    123     $time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked );
     119    $timeout = 'load-plugins.php' == current_filter() ? 360 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
     120    $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
    124121
    125122    $plugin_changed = false;
     
    127124        $new_option->checked[ $file ] = $p['Version'];
    128125
    129         if ( !isset( $current->checked[ $file ] ) ) {
    130             $plugin_changed = true;
    131             continue;
    132         }
    133 
    134         if ( strval($current->checked[ $file ]) !== strval($p['Version']) )
     126        if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
    135127            $plugin_changed = true;
    136128    }
     
    140132            if ( ! isset($plugins[ $plugin_file ]) ) {
    141133                $plugin_changed = true;
     134                break;
    142135            }
    143136        }
     
    152145    update_option( 'update_plugins', $current );
    153146
    154     $to_send->plugins = $plugins;
    155     $to_send->active = $active;
    156     $send = serialize( $to_send );
    157     $body = 'plugins=' . urlencode( $send );
    158 
    159     $options = array('method' => 'POST', 'timeout' => 3, 'body' => $body);
    160     $options['headers'] = array(
    161         'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
    162         'Content-Length' => strlen($body),
    163         'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
    164     );
    165 
    166     $raw_response = wp_remote_request('http://api.wordpress.org/plugins/update-check/1.0/', $options);
     147    $to_send = (object)compact('plugins', 'active');
     148    $body = array('plugins' => serialize( $to_send ) );
     149
     150    $options = array('timeout' => 3, 'body' => $body);
     151
     152    $raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
    167153
    168154    if ( is_wp_error( $raw_response ) )
    169155        return false;
    170156
    171     if( 200 != $raw_response['response']['code'] ) {
    172         return false;
    173     }
     157    if( 200 != $raw_response['response']['code'] )
     158        return false;
    174159
    175160    $response = unserialize( $raw_response['body'] );
     
    210195        $current_theme = new stdClass;
    211196
    212     $new_option = '';
     197    $new_option = new stdClass;
    213198    $new_option->last_checked = time( );
    214     $time_not_changed = isset( $current_theme->last_checked ) && 43200 > ( time( ) - $current_theme->last_checked );
     199    $timeout = 'load-themes.php' == current_filter() ? 360 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
     200    $time_not_changed = isset( $current_theme->last_checked ) && $timeout > ( time( ) - $current_theme->last_checked );
    215201
    216202    if( $time_not_changed )
     
    232218
    233219    $options = array(
    234         'method'        => 'POST',
    235220        'timeout'       => 3,
    236         'body'          => 'themes=' . urlencode( serialize( $themes ) )
     221        'body'          => array( 'themes' => serialize( $themes ) )
    237222    );
    238     $options['headers'] = array(
    239         'Content-Type'      => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
    240         'Content-Length'    => strlen( $options['body'] ),
    241         'User-Agent'        => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
    242     );
    243 
    244     $raw_response = wp_remote_request( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
     223
     224    $raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
    245225
    246226    if( is_wp_error( $raw_response ) )
     
    296276add_action( 'wp_update_plugins', 'wp_update_plugins' );
    297277
     278add_action( 'load-themes.php', 'wp_update_themes' );
     279add_action( 'load-update.php', 'wp_update_themes' );
    298280add_action( 'admin_init', '_maybe_update_themes' );
    299281add_action( 'wp_update_themes', 'wp_update_themes' );
Note: See TracChangeset for help on using the changeset viewer.