Make WordPress Core


Ignore:
Timestamp:
07/25/2019 12:47:53 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Rename $r variable used with wp_parse_args() to $parsed_args for clarity.

Props freewebmentor.
Fixes #45059.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-http-curl.php

    r45590 r45667  
    8080        );
    8181
    82         $r = wp_parse_args( $args, $defaults );
    83 
    84         if ( isset( $r['headers']['User-Agent'] ) ) {
    85             $r['user-agent'] = $r['headers']['User-Agent'];
    86             unset( $r['headers']['User-Agent'] );
    87         } elseif ( isset( $r['headers']['user-agent'] ) ) {
    88             $r['user-agent'] = $r['headers']['user-agent'];
    89             unset( $r['headers']['user-agent'] );
     82        $parsed_args = wp_parse_args( $args, $defaults );
     83
     84        if ( isset( $parsed_args['headers']['User-Agent'] ) ) {
     85            $parsed_args['user-agent'] = $parsed_args['headers']['User-Agent'];
     86            unset( $parsed_args['headers']['User-Agent'] );
     87        } elseif ( isset( $parsed_args['headers']['user-agent'] ) ) {
     88            $parsed_args['user-agent'] = $parsed_args['headers']['user-agent'];
     89            unset( $parsed_args['headers']['user-agent'] );
    9090        }
    9191
    9292        // Construct Cookie: header if any cookies are set.
    93         WP_Http::buildCookieHeader( $r );
     93        WP_Http::buildCookieHeader( $parsed_args );
    9494
    9595        $handle = curl_init();
     
    110110        }
    111111
    112         $is_local   = isset( $r['local'] ) && $r['local'];
    113         $ssl_verify = isset( $r['sslverify'] ) && $r['sslverify'];
     112        $is_local   = isset( $parsed_args['local'] ) && $parsed_args['local'];
     113        $ssl_verify = isset( $parsed_args['sslverify'] ) && $parsed_args['sslverify'];
    114114        if ( $is_local ) {
    115115            /** This filter is documented in wp-includes/class-wp-http-streams.php */
     
    124124         * a value of 0 will allow an unlimited timeout.
    125125         */
    126         $timeout = (int) ceil( $r['timeout'] );
     126        $timeout = (int) ceil( $parsed_args['timeout'] );
    127127        curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout );
    128128        curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
     
    134134
    135135        if ( $ssl_verify ) {
    136             curl_setopt( $handle, CURLOPT_CAINFO, $r['sslcertificates'] );
    137         }
    138 
    139         curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
     136            curl_setopt( $handle, CURLOPT_CAINFO, $parsed_args['sslcertificates'] );
     137        }
     138
     139        curl_setopt( $handle, CURLOPT_USERAGENT, $parsed_args['user-agent'] );
    140140
    141141        /*
     
    148148        }
    149149
    150         switch ( $r['method'] ) {
     150        switch ( $parsed_args['method'] ) {
    151151            case 'HEAD':
    152152                curl_setopt( $handle, CURLOPT_NOBODY, true );
     
    154154            case 'POST':
    155155                curl_setopt( $handle, CURLOPT_POST, true );
    156                 curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
     156                curl_setopt( $handle, CURLOPT_POSTFIELDS, $parsed_args['body'] );
    157157                break;
    158158            case 'PUT':
    159159                curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, 'PUT' );
    160                 curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
     160                curl_setopt( $handle, CURLOPT_POSTFIELDS, $parsed_args['body'] );
    161161                break;
    162162            default:
    163                 curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] );
    164                 if ( ! is_null( $r['body'] ) ) {
    165                     curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
     163                curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $parsed_args['method'] );
     164                if ( ! is_null( $parsed_args['body'] ) ) {
     165                    curl_setopt( $handle, CURLOPT_POSTFIELDS, $parsed_args['body'] );
    166166                }
    167167                break;
    168168        }
    169169
    170         if ( true === $r['blocking'] ) {
     170        if ( true === $parsed_args['blocking'] ) {
    171171            curl_setopt( $handle, CURLOPT_HEADERFUNCTION, array( $this, 'stream_headers' ) );
    172172            curl_setopt( $handle, CURLOPT_WRITEFUNCTION, array( $this, 'stream_body' ) );
     
    175175        curl_setopt( $handle, CURLOPT_HEADER, false );
    176176
    177         if ( isset( $r['limit_response_size'] ) ) {
    178             $this->max_body_length = intval( $r['limit_response_size'] );
     177        if ( isset( $parsed_args['limit_response_size'] ) ) {
     178            $this->max_body_length = intval( $parsed_args['limit_response_size'] );
    179179        } else {
    180180            $this->max_body_length = false;
     
    182182
    183183        // If streaming to a file open a file handle, and setup our curl streaming handler.
    184         if ( $r['stream'] ) {
     184        if ( $parsed_args['stream'] ) {
    185185            if ( ! WP_DEBUG ) {
    186                 $this->stream_handle = @fopen( $r['filename'], 'w+' );
     186                $this->stream_handle = @fopen( $parsed_args['filename'], 'w+' );
    187187            } else {
    188                 $this->stream_handle = fopen( $r['filename'], 'w+' );
     188                $this->stream_handle = fopen( $parsed_args['filename'], 'w+' );
    189189            }
    190190            if ( ! $this->stream_handle ) {
     
    195195                        __( 'Could not open handle for %1$s to %2$s.' ),
    196196                        'fopen()',
    197                         $r['filename']
     197                        $parsed_args['filename']
    198198                    )
    199199                );
     
    203203        }
    204204
    205         if ( ! empty( $r['headers'] ) ) {
     205        if ( ! empty( $parsed_args['headers'] ) ) {
    206206            // cURL expects full header strings in each element.
    207207            $headers = array();
    208             foreach ( $r['headers'] as $name => $value ) {
     208            foreach ( $parsed_args['headers'] as $name => $value ) {
    209209                $headers[] = "{$name}: $value";
    210210            }
     
    212212        }
    213213
    214         if ( $r['httpversion'] == '1.0' ) {
     214        if ( $parsed_args['httpversion'] == '1.0' ) {
    215215            curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
    216216        } else {
     
    227227         *
    228228         * @param resource $handle  The cURL handle returned by curl_init() (passed by reference).
    229          * @param array    $r       The HTTP request arguments.
     229         * @param array    $parsed_args       The HTTP request arguments.
    230230         * @param string   $url     The request URL.
    231231         */
    232         do_action_ref_array( 'http_api_curl', array( &$handle, $r, $url ) );
     232        do_action_ref_array( 'http_api_curl', array( &$handle, $parsed_args, $url ) );
    233233
    234234        // We don't need to return the body, so don't. Just execute request and return.
    235         if ( ! $r['blocking'] ) {
     235        if ( ! $parsed_args['blocking'] ) {
    236236            curl_exec( $handle );
    237237
     
    273273            if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error ) {
    274274                if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total ) {
    275                     if ( $r['stream'] ) {
     275                    if ( $parsed_args['stream'] ) {
    276276                        curl_close( $handle );
    277277                        fclose( $this->stream_handle );
     
    297297        curl_close( $handle );
    298298
    299         if ( $r['stream'] ) {
     299        if ( $parsed_args['stream'] ) {
    300300            fclose( $this->stream_handle );
    301301        }
     
    306306            'response' => $theHeaders['response'],
    307307            'cookies'  => $theHeaders['cookies'],
    308             'filename' => $r['filename'],
     308            'filename' => $parsed_args['filename'],
    309309        );
    310310
    311311        // Handle redirects.
    312         $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response );
     312        $redirect_response = WP_HTTP::handle_redirects( $url, $parsed_args, $response );
    313313        if ( false !== $redirect_response ) {
    314314            return $redirect_response;
    315315        }
    316316
    317         if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode( $theHeaders['headers'] ) ) {
     317        if ( true === $parsed_args['decompress'] && true === WP_Http_Encoding::should_decode( $theHeaders['headers'] ) ) {
    318318            $theBody = WP_Http_Encoding::decompress( $theBody );
    319319        }
Note: See TracChangeset for help on using the changeset viewer.