WordPress.org

Make WordPress Core

Ticket #4779: 4779.core.r8512.diff

File 4779.core.r8512.diff, 4.8 KB (added by jacobsantos, 6 years ago)

Converts spawn_cron() and wp_version_check() based off of r8512

  • cron.php

     
    7171        return false; 
    7272} 
    7373 
     74/** 
     75 * Send request to run cron through HTTP request that doesn't halt page loading. 
     76 * 
     77 * @since 2.1.0 
     78 * 
     79 * @return null CRON could not be spawned, because it is not needed to run. 
     80 */ 
    7481function spawn_cron() { 
    7582        $crons = _get_cron_array(); 
    7683 
     
    8188        if ( array_shift( $keys ) > time() ) 
    8289                return; 
    8390 
    84         $cron_url = get_option( 'siteurl' ) . '/wp-cron.php'; 
    85         $parts = parse_url( $cron_url ); 
     91        $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425'); 
    8692 
    87         if ($parts['scheme'] == 'https') { 
    88                 // support for SSL was added in 4.3.0 
    89                 if (version_compare(phpversion(), '4.3.0', '>=') && function_exists('openssl_open')) { 
    90                         $port = isset($parts['port']) ? $parts['port'] : 443; 
    91                         $argyle = @fsockopen('ssl://' . $parts['host'], $port, $errno, $errstr, 0.01); 
    92                 } else { 
    93                         return false; 
    94                 } 
    95         } else { 
    96                 $port = isset($parts['port']) ? $parts['port'] : 80; 
    97                 $argyle = @ fsockopen( $parts['host'], $port, $errno, $errstr, 0.01 ); 
    98         } 
    99  
    100         if ( $argyle ) 
    101                 fputs( $argyle, 
    102                           "GET {$parts['path']}?check=" . wp_hash('187425') . " HTTP/1.0\r\n" 
    103                         . "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n" 
    104                 ); 
     93        wp_remote_post($cron_url, array('timeout' => 0.01)); 
    10594} 
    10695 
    10796function wp_cron() { 
  • update.php

     
    77 */ 
    88 
    99/** 
    10  * wp_version_check() - Check WordPress version against the newest version. 
     10 * Check WordPress version against the newest version. 
    1111 * 
    12  * The WordPress version, PHP version, and Locale is sent. Checks against the WordPress server at 
    13  * api.wordpress.org server. Will only check if PHP has fsockopen enabled and WordPress isn't installing. 
     12 * The WordPress version, PHP version, and Locale is sent. Checks against the 
     13 * WordPress server at api.wordpress.org server. Will only check if WordPress 
     14 * isn't installing. 
    1415 * 
    1516 * @package WordPress 
    1617 * @since 2.3 
     
    1920 * @return mixed Returns null if update is unsupported. Returns false if check is too soon. 
    2021 */ 
    2122function wp_version_check() { 
    22         if ( !function_exists('fsockopen') || strpos($_SERVER['PHP_SELF'], 'install.php') !== false || defined('WP_INSTALLING') ) 
     23        if ( strpos($_SERVER['PHP_SELF'], 'install.php') !== false || defined('WP_INSTALLING') ) 
    2324                return; 
    2425 
    2526        global $wp_version; 
     
    3940        $new_option->last_checked = time(); // this gets set whether we get a response or not, so if something is down or misconfigured it won't delay the page load for more than 3 seconds, twice a day 
    4041        $new_option->version_checked = $wp_version; 
    4142 
    42         $http_request  = "GET /core/version-check/1.1/?version=$wp_version&php=$php_version&locale=$locale HTTP/1.0\r\n"; 
    43         $http_request .= "Host: api.wordpress.org\r\n"; 
    44         $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n"; 
    45         $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n"; 
    46         $http_request .= "\r\n"; 
     43        $url = "http://api.wordpress.org/core/version-check/1.1/?version=$wp_version&php=$php_version&locale=$locale"; 
     44        $options = array('timeout' => 3); 
    4745 
    48         $response = ''; 
    49         if ( false !== ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3 ) ) && is_resource($fs) ) { 
    50                 fwrite( $fs, $http_request ); 
    51                 while ( !feof( $fs ) ) 
    52                         $response .= fgets( $fs, 1160 ); // One TCP-IP packet 
    53                 fclose( $fs ); 
     46        $headers = array( 
     47                'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 
     48                'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url') 
     49        ); 
    5450 
    55                 $response = explode("\r\n\r\n", $response, 2); 
    56                 if ( !preg_match( '|HTTP/.*? 200|', $response[0] ) ) 
    57                         return false; 
     51        $response = wp_remote_request($url, $options, $headers); 
    5852 
    59                 $body = trim( $response[1] ); 
    60                 $body = str_replace(array("\r\n", "\r"), "\n", $body); 
     53        if( 200 != $response['response']['code'] ) 
     54                return false; 
    6155 
    62                 $returns = explode("\n", $body); 
     56        $body = $response['body']; 
    6357 
    64                 $new_option->response = attribute_escape( $returns[0] ); 
    65                 if ( isset( $returns[1] ) ) 
    66                         $new_option->url = clean_url( $returns[1] ); 
    67                 if ( isset( $returns[2] ) ) 
    68                         $new_option->current = attribute_escape( $returns[2] ); 
    69         } 
     58        $body = trim( $response[1] ); 
     59        $body = str_replace(array("\r\n", "\r"), "\n", $body); 
     60 
     61        $returns = explode("\n", $body); 
     62 
     63        $new_option->response = attribute_escape( $returns[0] ); 
     64        if ( isset( $returns[1] ) ) 
     65                $new_option->url = clean_url( $returns[1] ); 
     66        if ( isset( $returns[2] ) ) 
     67                $new_option->current = attribute_escape( $returns[2] ); 
     68 
    7069        update_option( 'update_core', $new_option ); 
    7170} 
    7271