WordPress.org

Make WordPress Core

Ticket #8660: 8660.diff

File 8660.diff, 4.7 KB (added by DD32, 9 years ago)
  • wp-includes/update.php

     
    5050        $url = "http://api.wordpress.org/core/version-check/1.3/?version=$wp_version&php=$php_version&locale=$locale&mysql=$mysql_version&local_package=$local_package";
    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         );
    5753
    58         $response = wp_remote_request($url, $options);
     54        $response = wp_remote_get($url, $options);
    5955
    6056        if ( is_wp_error( $response ) )
    6157                return false;
     
    118114        if ( ! is_object($current) )
    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;
    126123        foreach ( $plugins as $file => $p ) {
    127124                $new_option->checked[ $file ] = $p['Version'];
    128125
    129                 if ( !isset( $current->checked[ $file ] ) ) {
     126                if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
    130127                        $plugin_changed = true;
    131                         continue;
    132                 }
    133 
    134                 if ( strval($current->checked[ $file ]) !== strval($p['Version']) )
    135                         $plugin_changed = true;
    136128        }
    137129
    138130        if ( isset ( $current->response ) && is_array( $current->response ) ) {
    139131                foreach ( $current->response as $plugin_file => $update_details ) {
    140132                        if ( ! isset($plugins[ $plugin_file ]) ) {
    141133                                $plugin_changed = true;
     134                                break;
    142135                        }
    143136                }
    144137        }
     
    151144        $current->last_checked = time();
    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 );
     147        $to_send = (object)compact('plugins', 'active');
     148        $body = array('plugins' => serialize( $to_send ) );
    158149
    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         );
     150        $options = array('timeout' => 3, 'body' => $body);
    165151
    166         $raw_response = wp_remote_request('http://api.wordpress.org/plugins/update-check/1.0/', $options);
     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'] ) {
     157        if( 200 != $raw_response['response']['code'] )
    172158                return false;
    173         }
    174159
    175160        $response = unserialize( $raw_response['body'] );
    176161
     
    209194        if ( ! is_object($current_theme) )
    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 )
    217203                return false;
     
    231217        }
    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         );
    243223
    244         $raw_response = wp_remote_request( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
     224        $raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
    245225
    246226        if( is_wp_error( $raw_response ) )
    247227                return false;
     
    295275add_action( 'admin_init', '_maybe_update_plugins' );
    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' );
    300282