Make WordPress Core


Ignore:
Timestamp:
07/25/2019 12:47:53 AM (4 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-http.php

    r45590 r45667  
    221221        }
    222222
    223         $r = wp_parse_args( $args, $defaults );
     223        $parsed_args = wp_parse_args( $args, $defaults );
    224224        /**
    225225         * Filters the arguments used in an HTTP request.
     
    227227         * @since 2.7.0
    228228         *
    229          * @param array  $r   An array of HTTP request arguments.
     229         * @param array  $parsed_args   An array of HTTP request arguments.
    230230         * @param string $url The request URL.
    231231         */
    232         $r = apply_filters( 'http_request_args', $r, $url );
     232        $parsed_args = apply_filters( 'http_request_args', $parsed_args, $url );
    233233
    234234        // The transports decrement this, store a copy of the original value for loop purposes.
    235         if ( ! isset( $r['_redirection'] ) ) {
    236             $r['_redirection'] = $r['redirection'];
     235        if ( ! isset( $parsed_args['_redirection'] ) ) {
     236            $parsed_args['_redirection'] = $parsed_args['redirection'];
    237237        }
    238238
     
    252252         *
    253253         * @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false.
    254          * @param array               $r        HTTP request arguments.
     254         * @param array               $parsed_args        HTTP request arguments.
    255255         * @param string              $url      The request URL.
    256256         */
    257         $pre = apply_filters( 'pre_http_request', false, $r, $url );
     257        $pre = apply_filters( 'pre_http_request', false, $parsed_args, $url );
    258258
    259259        if ( false !== $pre ) {
     
    262262
    263263        if ( function_exists( 'wp_kses_bad_protocol' ) ) {
    264             if ( $r['reject_unsafe_urls'] ) {
     264            if ( $parsed_args['reject_unsafe_urls'] ) {
    265265                $url = wp_http_validate_url( $url );
    266266            }
     
    275275            $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
    276276            /** This action is documented in wp-includes/class-http.php */
    277             do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
     277            do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
    278278            return $response;
    279279        }
     
    282282            $response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
    283283            /** This action is documented in wp-includes/class-http.php */
    284             do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
     284            do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
    285285            return $response;
    286286        }
     
    288288        // If we are streaming to a file but no filename was given drop it in the WP temp dir
    289289        // and pick its name using the basename of the $url
    290         if ( $r['stream'] ) {
    291             if ( empty( $r['filename'] ) ) {
    292                 $r['filename'] = get_temp_dir() . basename( $url );
     290        if ( $parsed_args['stream'] ) {
     291            if ( empty( $parsed_args['filename'] ) ) {
     292                $parsed_args['filename'] = get_temp_dir() . basename( $url );
    293293            }
    294294
    295295            // Force some settings if we are streaming to a file and check for existence and perms of destination directory
    296             $r['blocking'] = true;
    297             if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) {
     296            $parsed_args['blocking'] = true;
     297            if ( ! wp_is_writable( dirname( $parsed_args['filename'] ) ) ) {
    298298                $response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) );
    299299                /** This action is documented in wp-includes/class-http.php */
    300                 do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
     300                do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
    301301                return $response;
    302302            }
    303303        }
    304304
    305         if ( is_null( $r['headers'] ) ) {
    306             $r['headers'] = array();
     305        if ( is_null( $parsed_args['headers'] ) ) {
     306            $parsed_args['headers'] = array();
    307307        }
    308308
    309309        // WP allows passing in headers as a string, weirdly.
    310         if ( ! is_array( $r['headers'] ) ) {
    311             $processedHeaders = WP_Http::processHeaders( $r['headers'] );
    312             $r['headers']    = $processedHeaders['headers'];
     310        if ( ! is_array( $parsed_args['headers'] ) ) {
     311            $processedHeaders       = WP_Http::processHeaders( $parsed_args['headers'] );
     312            $parsed_args['headers'] = $processedHeaders['headers'];
    313313        }
    314314
    315315        // Setup arguments
    316         $headers = $r['headers'];
    317         $data    = $r['body'];
    318         $type    = $r['method'];
     316        $headers = $parsed_args['headers'];
     317        $data    = $parsed_args['body'];
     318        $type    = $parsed_args['method'];
    319319        $options = array(
    320             'timeout'   => $r['timeout'],
    321             'useragent' => $r['user-agent'],
    322             'blocking'  => $r['blocking'],
    323             'hooks'     => new WP_HTTP_Requests_Hooks( $url, $r ),
     320            'timeout'   => $parsed_args['timeout'],
     321            'useragent' => $parsed_args['user-agent'],
     322            'blocking'  => $parsed_args['blocking'],
     323            'hooks'     => new WP_HTTP_Requests_Hooks( $url, $parsed_args ),
    324324        );
    325325
     
    328328
    329329        // Validate redirected URLs.
    330         if ( function_exists( 'wp_kses_bad_protocol' ) && $r['reject_unsafe_urls'] ) {
     330        if ( function_exists( 'wp_kses_bad_protocol' ) && $parsed_args['reject_unsafe_urls'] ) {
    331331            $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) );
    332332        }
    333333
    334         if ( $r['stream'] ) {
    335             $options['filename'] = $r['filename'];
    336         }
    337         if ( empty( $r['redirection'] ) ) {
     334        if ( $parsed_args['stream'] ) {
     335            $options['filename'] = $parsed_args['filename'];
     336        }
     337        if ( empty( $parsed_args['redirection'] ) ) {
    338338            $options['follow_redirects'] = false;
    339339        } else {
    340             $options['redirects'] = $r['redirection'];
     340            $options['redirects'] = $parsed_args['redirection'];
    341341        }
    342342
    343343        // Use byte limit, if we can
    344         if ( isset( $r['limit_response_size'] ) ) {
    345             $options['max_bytes'] = $r['limit_response_size'];
     344        if ( isset( $parsed_args['limit_response_size'] ) ) {
     345            $options['max_bytes'] = $parsed_args['limit_response_size'];
    346346        }
    347347
    348348        // If we've got cookies, use and convert them to Requests_Cookie.
    349         if ( ! empty( $r['cookies'] ) ) {
    350             $options['cookies'] = WP_Http::normalize_cookies( $r['cookies'] );
     349        if ( ! empty( $parsed_args['cookies'] ) ) {
     350            $options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] );
    351351        }
    352352
    353353        // SSL certificate handling
    354         if ( ! $r['sslverify'] ) {
     354        if ( ! $parsed_args['sslverify'] ) {
    355355            $options['verify']     = false;
    356356            $options['verifyname'] = false;
    357357        } else {
    358             $options['verify'] = $r['sslcertificates'];
     358            $options['verify'] = $parsed_args['sslcertificates'];
    359359        }
    360360
     
    394394
    395395            // Convert the response into an array
    396             $http_response = new WP_HTTP_Requests_Response( $requests_response, $r['filename'] );
     396            $http_response = new WP_HTTP_Requests_Response( $requests_response, $parsed_args['filename'] );
    397397            $response      = $http_response->to_array();
    398398
     
    413413         * @param string         $context  Context under which the hook is fired.
    414414         * @param string         $class    HTTP transport used.
    415          * @param array          $r        HTTP request arguments.
     415         * @param array          $parsed_args        HTTP request arguments.
    416416         * @param string         $url      The request URL.
    417417         */
    418         do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
     418        do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
    419419        if ( is_wp_error( $response ) ) {
    420420            return $response;
    421421        }
    422422
    423         if ( ! $r['blocking'] ) {
     423        if ( ! $parsed_args['blocking'] ) {
    424424            return array(
    425425                'headers'       => array(),
     
    440440         *
    441441         * @param array  $response HTTP response.
    442          * @param array  $r        HTTP request arguments.
     442         * @param array  $parsed_args        HTTP request arguments.
    443443         * @param string $url      The request URL.
    444444         */
    445         return apply_filters( 'http_response', $response, $r, $url );
     445        return apply_filters( 'http_response', $response, $parsed_args, $url );
    446446    }
    447447
     
    601601     */
    602602    public function post( $url, $args = array() ) {
    603         $defaults = array( 'method' => 'POST' );
    604         $r        = wp_parse_args( $args, $defaults );
    605         return $this->request( $url, $r );
     603        $defaults    = array( 'method' => 'POST' );
     604        $parsed_args = wp_parse_args( $args, $defaults );
     605        return $this->request( $url, $parsed_args );
    606606    }
    607607
     
    618618     */
    619619    public function get( $url, $args = array() ) {
    620         $defaults = array( 'method' => 'GET' );
    621         $r        = wp_parse_args( $args, $defaults );
    622         return $this->request( $url, $r );
     620        $defaults    = array( 'method' => 'GET' );
     621        $parsed_args = wp_parse_args( $args, $defaults );
     622        return $this->request( $url, $parsed_args );
    623623    }
    624624
     
    635635     */
    636636    public function head( $url, $args = array() ) {
    637         $defaults = array( 'method' => 'HEAD' );
    638         $r        = wp_parse_args( $args, $defaults );
    639         return $this->request( $url, $r );
     637        $defaults    = array( 'method' => 'HEAD' );
     638        $parsed_args = wp_parse_args( $args, $defaults );
     639        return $this->request( $url, $parsed_args );
    640640    }
    641641
Note: See TracChangeset for help on using the changeset viewer.