Make WordPress Core

Ticket #33241: 33241.diff

File 33241.diff, 1.6 KB (added by rmccue, 9 years ago)

Use direct file streaming, and deprecate the function

  • wp-includes/functions.php

    diff --git a/wp-includes/functions.php b/wp-includes/functions.php
    index 30fac47..6835ddf 100644
    a b function do_enclose( $content, $post_ID ) { 
    580580function wp_get_http( $url, $file_path = false, $red = 1 ) {
    581581        @set_time_limit( 60 );
    582582
    583         if ( $red > 5 )
    584                 return false;
     583        _deprecated_function( 'wp_get_http', '4.4', 'wp_safe_remote_request' );
    585584
    586585        $options = array();
    587586        $options['redirection'] = 5;
    function wp_get_http( $url, $file_path = false, $red = 1 ) { 
    591590        else
    592591                $options['method'] = 'GET';
    593592
     593        // Stream directly to a file
     594        if ( ! empty( $file_path ) ) {
     595                $options['stream'] = true;
     596                $options['filename'] = $file_path;
     597        }
     598
    594599        $response = wp_safe_remote_request( $url, $options );
    595600
    596601        if ( is_wp_error( $response ) )
    function wp_get_http( $url, $file_path = false, $red = 1 ) { 
    598603
    599604        $headers = wp_remote_retrieve_headers( $response );
    600605        $headers['response'] = wp_remote_retrieve_response_code( $response );
    601 
    602         // WP_HTTP no longer follows redirects for HEAD requests.
    603         if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
    604                 return wp_get_http( $headers['location'], $file_path, ++$red );
    605         }
    606 
    607         if ( false == $file_path )
    608                 return $headers;
    609 
    610         // GET request - write it to the supplied filename
    611         $out_fp = fopen($file_path, 'w');
    612         if ( !$out_fp )
    613                 return $headers;
    614 
    615         fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
    616         fclose($out_fp);
    617         clearstatcache();
    618 
    619606        return $headers;
    620607}
    621608