Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42208 r42343  
    2929
    3030    // Aliases for HTTP response codes.
    31     const HTTP_CONTINUE                   = 100;
    32     const SWITCHING_PROTOCOLS             = 101;
    33     const PROCESSING                      = 102;
    34     const EARLY_HINTS                     = 103;
    35 
    36     const OK                              = 200;
    37     const CREATED                         = 201;
    38     const ACCEPTED                        = 202;
    39     const NON_AUTHORITATIVE_INFORMATION   = 203;
    40     const NO_CONTENT                      = 204;
    41     const RESET_CONTENT                   = 205;
    42     const PARTIAL_CONTENT                 = 206;
    43     const MULTI_STATUS                    = 207;
    44     const IM_USED                         = 226;
    45 
    46     const MULTIPLE_CHOICES                = 300;
    47     const MOVED_PERMANENTLY               = 301;
    48     const FOUND                           = 302;
    49     const SEE_OTHER                       = 303;
    50     const NOT_MODIFIED                    = 304;
    51     const USE_PROXY                       = 305;
    52     const RESERVED                        = 306;
    53     const TEMPORARY_REDIRECT              = 307;
    54     const PERMANENT_REDIRECT              = 308;
     31    const HTTP_CONTINUE       = 100;
     32    const SWITCHING_PROTOCOLS = 101;
     33    const PROCESSING          = 102;
     34    const EARLY_HINTS         = 103;
     35
     36    const OK                            = 200;
     37    const CREATED                       = 201;
     38    const ACCEPTED                      = 202;
     39    const NON_AUTHORITATIVE_INFORMATION = 203;
     40    const NO_CONTENT                    = 204;
     41    const RESET_CONTENT                 = 205;
     42    const PARTIAL_CONTENT               = 206;
     43    const MULTI_STATUS                  = 207;
     44    const IM_USED                       = 226;
     45
     46    const MULTIPLE_CHOICES   = 300;
     47    const MOVED_PERMANENTLY  = 301;
     48    const FOUND              = 302;
     49    const SEE_OTHER          = 303;
     50    const NOT_MODIFIED       = 304;
     51    const USE_PROXY          = 305;
     52    const RESERVED           = 306;
     53    const TEMPORARY_REDIRECT = 307;
     54    const PERMANENT_REDIRECT = 308;
    5555
    5656    const BAD_REQUEST                     = 400;
     
    148148    public function request( $url, $args = array() ) {
    149149        $defaults = array(
    150             'method' => 'GET',
     150            'method'              => 'GET',
    151151            /**
    152152             * Filters the timeout value for an HTTP request.
     
    157157             *                           Default 5.
    158158             */
    159             'timeout' => apply_filters( 'http_request_timeout', 5 ),
     159            'timeout'             => apply_filters( 'http_request_timeout', 5 ),
    160160            /**
    161161             * Filters the number of redirects allowed during an HTTP request.
     
    165165             * @param int $redirect_count Number of redirects allowed. Default 5.
    166166             */
    167             'redirection' => apply_filters( 'http_request_redirection_count', 5 ),
     167            'redirection'         => apply_filters( 'http_request_redirection_count', 5 ),
    168168            /**
    169169             * Filters the version of the HTTP protocol used in a request.
     
    174174             *                        Default '1.0'.
    175175             */
    176             'httpversion' => apply_filters( 'http_request_version', '1.0' ),
     176            'httpversion'         => apply_filters( 'http_request_version', '1.0' ),
    177177            /**
    178178             * Filters the user agent value sent with an HTTP request.
     
    182182             * @param string $user_agent WordPress user agent string.
    183183             */
    184             'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) ),
     184            'user-agent'          => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) ),
    185185            /**
    186186             * Filters whether to pass URLs through wp_http_validate_url() in an HTTP request.
     
    191191             *                       Default false.
    192192             */
    193             'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ),
    194             'blocking' => true,
    195             'headers' => array(),
    196             'cookies' => array(),
    197             'body' => null,
    198             'compress' => false,
    199             'decompress' => true,
    200             'sslverify' => true,
    201             'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
    202             'stream' => false,
    203             'filename' => null,
     193            'reject_unsafe_urls'  => apply_filters( 'http_request_reject_unsafe_urls', false ),
     194            'blocking'            => true,
     195            'headers'             => array(),
     196            'cookies'             => array(),
     197            'body'                => null,
     198            'compress'            => false,
     199            'decompress'          => true,
     200            'sslverify'           => true,
     201            'sslcertificates'     => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
     202            'stream'              => false,
     203            'filename'            => null,
    204204            'limit_response_size' => null,
    205205        );
     
    209209
    210210        // By default, Head requests do not cause redirections.
    211         if ( isset($args['method']) && 'HEAD' == $args['method'] )
     211        if ( isset( $args['method'] ) && 'HEAD' == $args['method'] ) {
    212212            $defaults['redirection'] = 0;
     213        }
    213214
    214215        $r = wp_parse_args( $args, $defaults );
     
    224225
    225226        // The transports decrement this, store a copy of the original value for loop purposes.
    226         if ( ! isset( $r['_redirection'] ) )
     227        if ( ! isset( $r['_redirection'] ) ) {
    227228            $r['_redirection'] = $r['redirection'];
     229        }
    228230
    229231        /**
     
    247249        $pre = apply_filters( 'pre_http_request', false, $r, $url );
    248250
    249         if ( false !== $pre )
     251        if ( false !== $pre ) {
    250252            return $pre;
     253        }
    251254
    252255        if ( function_exists( 'wp_kses_bad_protocol' ) ) {
     
    262265
    263266        if ( empty( $url ) || empty( $arrURL['scheme'] ) ) {
    264             return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
     267            return new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
    265268        }
    266269
     
    290293        if ( ! is_array( $r['headers'] ) ) {
    291294            $processedHeaders = WP_Http::processHeaders( $r['headers'] );
    292             $r['headers'] = $processedHeaders['headers'];
     295            $r['headers']     = $processedHeaders['headers'];
    293296        }
    294297
    295298        // Setup arguments
    296299        $headers = $r['headers'];
    297         $data = $r['body'];
    298         $type = $r['method'];
     300        $data    = $r['body'];
     301        $type    = $r['method'];
    299302        $options = array(
    300             'timeout' => $r['timeout'],
     303            'timeout'   => $r['timeout'],
    301304            'useragent' => $r['user-agent'],
    302             'blocking' => $r['blocking'],
    303             'hooks' => new WP_HTTP_Requests_Hooks( $url, $r ),
     305            'blocking'  => $r['blocking'],
     306            'hooks'     => new WP_HTTP_Requests_Hooks( $url, $r ),
    304307        );
    305308
     
    333336        // SSL certificate handling
    334337        if ( ! $r['sslverify'] ) {
    335             $options['verify'] = false;
     338            $options['verify']     = false;
    336339            $options['verifyname'] = false;
    337340        } else {
     
    360363            if ( $proxy->use_authentication() ) {
    361364                $options['proxy']->use_authentication = true;
    362                 $options['proxy']->user = $proxy->username();
    363                 $options['proxy']->pass = $proxy->password();
     365                $options['proxy']->user               = $proxy->username();
     366                $options['proxy']->pass               = $proxy->password();
    364367            }
    365368        }
     
    373376            // Convert the response into an array
    374377            $http_response = new WP_HTTP_Requests_Response( $requests_response, $r['filename'] );
    375             $response = $http_response->to_array();
     378            $response      = $http_response->to_array();
    376379
    377380            // Add the original object to the array.
    378381            $response['http_response'] = $http_response;
    379         }
    380         catch ( Requests_Exception $e ) {
     382        } catch ( Requests_Exception $e ) {
    381383            $response = new WP_Error( 'http_request_failed', $e->getMessage() );
    382384        }
     
    402404        if ( ! $r['blocking'] ) {
    403405            return array(
    404                 'headers' => array(),
    405                 'body' => '',
    406                 'response' => array(
    407                     'code' => false,
     406                'headers'       => array(),
     407                'body'          => '',
     408                'response'      => array(
     409                    'code'    => false,
    408410                    'message' => false,
    409411                ),
    410                 'cookies' => array(),
     412                'cookies'       => array(),
    411413                'http_response' => null,
    412414            );
     
    481483    public static function validate_redirects( $location ) {
    482484        if ( ! wp_http_validate_url( $location ) ) {
    483             throw new Requests_Exception( __('A valid URL was not provided.'), 'wp_http.redirect_failed_validation' );
     485            throw new Requests_Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );
    484486        }
    485487    }
     
    518520
    519521            // Check to see if this transport is a possibility, calls the transport statically.
    520             if ( !call_user_func( array( $class, 'test' ), $args, $url ) )
     522            if ( ! call_user_func( array( $class, 'test' ), $args, $url ) ) {
    521523                continue;
     524            }
    522525
    523526            return $class;
     
    547550
    548551        $class = $this->_get_first_available_transport( $args, $url );
    549         if ( !$class )
     552        if ( ! $class ) {
    550553            return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) );
     554        }
    551555
    552556        // Transport claims to support request, instantiate it and give it a whirl.
    553         if ( empty( $transports[$class] ) )
    554             $transports[$class] = new $class;
    555 
    556         $response = $transports[$class]->request( $url, $args );
     557        if ( empty( $transports[ $class ] ) ) {
     558            $transports[ $class ] = new $class;
     559        }
     560
     561        $response = $transports[ $class ]->request( $url, $args );
    557562
    558563        /** This action is documented in wp-includes/class-http.php */
    559564        do_action( 'http_api_debug', $response, 'response', $class, $args, $url );
    560565
    561         if ( is_wp_error( $response ) )
     566        if ( is_wp_error( $response ) ) {
    562567            return $response;
     568        }
    563569
    564570        /**
     
    585591     * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
    586592     */
    587     public function post($url, $args = array()) {
    588         $defaults = array('method' => 'POST');
    589         $r = wp_parse_args( $args, $defaults );
    590         return $this->request($url, $r);
     593    public function post( $url, $args = array() ) {
     594        $defaults = array( 'method' => 'POST' );
     595        $r        = wp_parse_args( $args, $defaults );
     596        return $this->request( $url, $r );
    591597    }
    592598
     
    602608     * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
    603609     */
    604     public function get($url, $args = array()) {
    605         $defaults = array('method' => 'GET');
    606         $r = wp_parse_args( $args, $defaults );
    607         return $this->request($url, $r);
     610    public function get( $url, $args = array() ) {
     611        $defaults = array( 'method' => 'GET' );
     612        $r        = wp_parse_args( $args, $defaults );
     613        return $this->request( $url, $r );
    608614    }
    609615
     
    619625     * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
    620626     */
    621     public function head($url, $args = array()) {
    622         $defaults = array('method' => 'HEAD');
    623         $r = wp_parse_args( $args, $defaults );
    624         return $this->request($url, $r);
     627    public function head( $url, $args = array() ) {
     628        $defaults = array( 'method' => 'HEAD' );
     629        $r        = wp_parse_args( $args, $defaults );
     630        return $this->request( $url, $r );
    625631    }
    626632
     
    634640     * @return array Array with 'headers' and 'body' keys.
    635641     */
    636     public static function processResponse($strResponse) {
    637         $res = explode("\r\n\r\n", $strResponse, 2);
    638 
    639         return array('headers' => $res[0], 'body' => isset($res[1]) ? $res[1] : '');
     642    public static function processResponse( $strResponse ) {
     643        $res = explode( "\r\n\r\n", $strResponse, 2 );
     644
     645        return array(
     646            'headers' => $res[0],
     647            'body'    => isset( $res[1] ) ? $res[1] : '',
     648        );
    640649    }
    641650
     
    652661     * @param string $url The URL that was requested
    653662     * @return array Processed string headers. If duplicate headers are encountered,
    654      *                  Then a numbered array is returned as the value of that header-key.
     663     *                  Then a numbered array is returned as the value of that header-key.
    655664     */
    656665    public static function processHeaders( $headers, $url = '' ) {
    657666        // Split headers, one per array element.
    658         if ( is_string($headers) ) {
     667        if ( is_string( $headers ) ) {
    659668            // Tolerate line terminator: CRLF = LF (RFC 2616 19.3).
    660             $headers = str_replace("\r\n", "\n", $headers);
     669            $headers = str_replace( "\r\n", "\n", $headers );
    661670            /*
    662671             * Unfold folded header fields. LWS = [CRLF] 1*( SP | HT ) <US-ASCII SP, space (32)>,
    663672             * <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2).
    664673             */
    665             $headers = preg_replace('/\n[ \t]/', ' ', $headers);
     674            $headers = preg_replace( '/\n[ \t]/', ' ', $headers );
    666675            // Create the headers array.
    667             $headers = explode("\n", $headers);
    668         }
    669 
    670         $response = array('code' => 0, 'message' => '');
     676            $headers = explode( "\n", $headers );
     677        }
     678
     679        $response = array(
     680            'code'    => 0,
     681            'message' => '',
     682        );
    671683
    672684        /*
     
    674686         * In this case, determine the final HTTP header and parse from there.
    675687         */
    676         for ( $i = count($headers)-1; $i >= 0; $i-- ) {
    677             if ( !empty($headers[$i]) && false === strpos($headers[$i], ':') ) {
    678                 $headers = array_splice($headers, $i);
     688        for ( $i = count( $headers ) - 1; $i >= 0; $i-- ) {
     689            if ( ! empty( $headers[ $i ] ) && false === strpos( $headers[ $i ], ':' ) ) {
     690                $headers = array_splice( $headers, $i );
    679691                break;
    680692            }
    681693        }
    682694
    683         $cookies = array();
     695        $cookies    = array();
    684696        $newheaders = array();
    685697        foreach ( (array) $headers as $tempheader ) {
    686             if ( empty($tempheader) )
     698            if ( empty( $tempheader ) ) {
    687699                continue;
    688 
    689             if ( false === strpos($tempheader, ':') ) {
    690                 $stack = explode(' ', $tempheader, 3);
     700            }
     701
     702            if ( false === strpos( $tempheader, ':' ) ) {
     703                $stack   = explode( ' ', $tempheader, 3 );
    691704                $stack[] = '';
    692705                list( , $response['code'], $response['message']) = $stack;
     
    694707            }
    695708
    696             list($key, $value) = explode(':', $tempheader, 2);
    697 
    698             $key = strtolower( $key );
     709            list($key, $value) = explode( ':', $tempheader, 2 );
     710
     711            $key   = strtolower( $key );
    699712            $value = trim( $value );
    700713
    701714            if ( isset( $newheaders[ $key ] ) ) {
    702                 if ( ! is_array( $newheaders[ $key ] ) )
    703                     $newheaders[$key] = array( $newheaders[ $key ] );
     715                if ( ! is_array( $newheaders[ $key ] ) ) {
     716                    $newheaders[ $key ] = array( $newheaders[ $key ] );
     717                }
    704718                $newheaders[ $key ][] = $value;
    705719            } else {
    706720                $newheaders[ $key ] = $value;
    707721            }
    708             if ( 'set-cookie' == $key )
     722            if ( 'set-cookie' == $key ) {
    709723                $cookies[] = new WP_Http_Cookie( $value, $url );
     724            }
    710725        }
    711726
     
    713728        $response['code'] = intval( $response['code'] );
    714729
    715         return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies);
     730        return array(
     731            'response' => $response,
     732            'headers'  => $newheaders,
     733            'cookies'  => $cookies,
     734        );
    716735    }
    717736
     
    729748     */
    730749    public static function buildCookieHeader( &$r ) {
    731         if ( ! empty($r['cookies']) ) {
     750        if ( ! empty( $r['cookies'] ) ) {
    732751            // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances.
    733752            foreach ( $r['cookies'] as $name => $value ) {
    734                 if ( ! is_object( $value ) )
    735                     $r['cookies'][ $name ] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) );
     753                if ( ! is_object( $value ) ) {
     754                    $r['cookies'][ $name ] = new WP_Http_Cookie(
     755                        array(
     756                            'name'  => $name,
     757                            'value' => $value,
     758                        )
     759                    );
     760                }
    736761            }
    737762
     
    741766            }
    742767
    743             $cookies_header = substr( $cookies_header, 0, -2 );
     768            $cookies_header         = substr( $cookies_header, 0, -2 );
    744769            $r['headers']['cookie'] = $cookies_header;
    745770        }
     
    761786    public static function chunkTransferDecode( $body ) {
    762787        // The body is not chunked encoded or is malformed.
    763         if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) )
     788        if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) {
    764789            return $body;
     790        }
    765791
    766792        $parsed_body = '';
     
    771797        while ( true ) {
    772798            $has_chunk = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match );
    773             if ( ! $has_chunk || empty( $match[1] ) )
     799            if ( ! $has_chunk || empty( $match[1] ) ) {
    774800                return $body_original;
    775 
    776             $length = hexdec( $match[1] );
     801            }
     802
     803            $length       = hexdec( $match[1] );
    777804            $chunk_length = strlen( $match[0] );
    778805
     
    784811
    785812            // End of the document.
    786             if ( '0' === trim( $body ) )
     813            if ( '0' === trim( $body ) ) {
    787814                return $parsed_body;
     815            }
    788816        }
    789817    }
     
    811839     * @return bool True to block, false to allow.
    812840     */
    813     public function block_request($uri) {
     841    public function block_request( $uri ) {
    814842        // We don't need to block requests, because nothing is blocked.
    815         if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL )
     843        if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) {
    816844            return false;
    817 
    818         $check = parse_url($uri);
    819         if ( ! $check )
     845        }
     846
     847        $check = parse_url( $uri );
     848        if ( ! $check ) {
    820849            return true;
    821 
    822         $home = parse_url( get_option('siteurl') );
     850        }
     851
     852        $home = parse_url( get_option( 'siteurl' ) );
    823853
    824854        // Don't block requests back to ourselves by default.
     
    835865        }
    836866
    837         if ( !defined('WP_ACCESSIBLE_HOSTS') )
     867        if ( ! defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
    838868            return true;
     869        }
    839870
    840871        static $accessible_hosts = null;
    841         static $wildcard_regex = array();
     872        static $wildcard_regex   = array();
    842873        if ( null === $accessible_hosts ) {
    843             $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS);
    844 
    845             if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) {
     874            $accessible_hosts = preg_split( '|,\s*|', WP_ACCESSIBLE_HOSTS );
     875
     876            if ( false !== strpos( WP_ACCESSIBLE_HOSTS, '*' ) ) {
    846877                $wildcard_regex = array();
    847                 foreach ( $accessible_hosts as $host )
     878                foreach ( $accessible_hosts as $host ) {
    848879                    $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) );
    849                 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i';
    850             }
    851         }
    852 
    853         if ( !empty($wildcard_regex) )
    854             return !preg_match($wildcard_regex, $check['host']);
    855         else
    856             return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it.
     880                }
     881                $wildcard_regex = '/^(' . implode( '|', $wildcard_regex ) . ')$/i';
     882            }
     883        }
     884
     885        if ( ! empty( $wildcard_regex ) ) {
     886            return ! preg_match( $wildcard_regex, $check['host'] );
     887        } else {
     888            return ! in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it.
     889        }
    857890
    858891    }
     
    887920     */
    888921    public static function make_absolute_url( $maybe_relative_path, $url ) {
    889         if ( empty( $url ) )
     922        if ( empty( $url ) ) {
    890923            return $maybe_relative_path;
     924        }
    891925
    892926        if ( ! $url_parts = wp_parse_url( $url ) ) {
     
    908942        if ( isset( $relative_url_parts['host'] ) ) {
    909943            $absolute_path .= $relative_url_parts['host'];
    910             if ( isset( $relative_url_parts['port'] ) )
     944            if ( isset( $relative_url_parts['port'] ) ) {
    911945                $absolute_path .= ':' . $relative_url_parts['port'];
     946            }
    912947        } else {
    913948            $absolute_path .= $url_parts['host'];
    914             if ( isset( $url_parts['port'] ) )
     949            if ( isset( $url_parts['port'] ) ) {
    915950                $absolute_path .= ':' . $url_parts['port'];
     951            }
    916952        }
    917953
     
    923959            $path = $relative_url_parts['path'];
    924960
    925         // Else it's a relative path.
     961            // Else it's a relative path.
    926962        } elseif ( ! empty( $relative_url_parts['path'] ) ) {
    927963            // Strip off any file components from the absolute path.
     
    941977
    942978        // Add the Query string.
    943         if ( ! empty( $relative_url_parts['query'] ) )
     979        if ( ! empty( $relative_url_parts['query'] ) ) {
    944980            $path .= '?' . $relative_url_parts['query'];
     981        }
    945982
    946983        return $absolute_path . '/' . ltrim( $path, '/' );
     
    960997    public static function handle_redirects( $url, $args, $response ) {
    961998        // If no redirects are present, or, redirects were not requested, perform no action.
    962         if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] )
     999        if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) {
    9631000            return false;
     1001        }
    9641002
    9651003        // Only perform redirections on redirection http codes.
    966         if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 )
     1004        if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) {
    9671005            return false;
     1006        }
    9681007
    9691008        // Don't redirect if we've run out of redirects.
    970         if ( $args['redirection']-- <= 0 )
    971             return new WP_Error( 'http_request_failed', __('Too many redirects.') );
     1009        if ( $args['redirection']-- <= 0 ) {
     1010            return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) );
     1011        }
    9721012
    9731013        $redirect_location = $response['headers']['location'];
    9741014
    9751015        // If there were multiple Location headers, use the last header specified.
    976         if ( is_array( $redirect_location ) )
     1016        if ( is_array( $redirect_location ) ) {
    9771017            $redirect_location = array_pop( $redirect_location );
     1018        }
    9781019
    9791020        $redirect_location = WP_Http::make_absolute_url( $redirect_location, $url );
     
    9811022        // POST requests should not POST to a redirected location.
    9821023        if ( 'POST' == $args['method'] ) {
    983             if ( in_array( $response['response']['code'], array( 302, 303 ) ) )
     1024            if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) {
    9841025                $args['method'] = 'GET';
     1026            }
    9851027        }
    9861028
     
    9881030        if ( ! empty( $response['cookies'] ) ) {
    9891031            foreach ( $response['cookies'] as $cookie ) {
    990                 if ( $cookie->test( $redirect_location ) )
     1032                if ( $cookie->test( $redirect_location ) ) {
    9911033                    $args['cookies'][] = $cookie;
     1034                }
    9921035            }
    9931036        }
     
    10131056     */
    10141057    public static function is_ip_address( $maybe_ip ) {
    1015         if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) )
     1058        if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) {
    10161059            return 4;
    1017 
    1018         if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) )
     1060        }
     1061
     1062        if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) {
    10191063            return 6;
     1064        }
    10201065
    10211066        return false;
Note: See TracChangeset for help on using the changeset viewer.