Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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/http.php

    r41573 r42343  
    4646function wp_safe_remote_request( $url, $args = array() ) {
    4747        $args['reject_unsafe_urls'] = true;
    48         $http = _wp_http_get_object();
     48        $http                       = _wp_http_get_object();
    4949        return $http->request( $url, $args );
    5050}
    … …  
    6767function wp_safe_remote_get( $url, $args = array() ) {
    6868        $args['reject_unsafe_urls'] = true;
    69         $http = _wp_http_get_object();
     69        $http                       = _wp_http_get_object();
    7070        return $http->get( $url, $args );
    7171}
    … …  
    8888function wp_safe_remote_post( $url, $args = array() ) {
    8989        $args['reject_unsafe_urls'] = true;
    90         $http = _wp_http_get_object();
     90        $http                       = _wp_http_get_object();
    9191        return $http->post( $url, $args );
    9292}
    … …  
    109109function wp_safe_remote_head( $url, $args = array() ) {
    110110        $args['reject_unsafe_urls'] = true;
    111         $http = _wp_http_get_object();
     111        $http                       = _wp_http_get_object();
    112112        return $http->head( $url, $args );
    113113}
    … …  
    149149 * @return WP_Error|array The response or WP_Error on failure.
    150150 */
    151 function wp_remote_request($url, $args = array()) {
     151function wp_remote_request( $url, $args = array() ) {
    152152        $http = _wp_http_get_object();
    153153        return $http->request( $url, $args );
    … …  
    166166 * @return WP_Error|array The response or WP_Error on failure.
    167167 */
    168 function wp_remote_get($url, $args = array()) {
     168function wp_remote_get( $url, $args = array() ) {
    169169        $http = _wp_http_get_object();
    170170        return $http->get( $url, $args );
    … …  
    183183 * @return WP_Error|array The response or WP_Error on failure.
    184184 */
    185 function wp_remote_post($url, $args = array()) {
     185function wp_remote_post( $url, $args = array() ) {
    186186        $http = _wp_http_get_object();
    187187        return $http->post( $url, $args );
    … …  
    200200 * @return WP_Error|array The response or WP_Error on failure.
    201201 */
    202 function wp_remote_head($url, $args = array()) {
     202function wp_remote_head( $url, $args = array() ) {
    203203        $http = _wp_http_get_object();
    204204        return $http->head( $url, $args );
    … …  
    239239
    240240        if ( isset( $response['headers'][ $header ] ) ) {
    241                 return $response['headers'][$header];
     241                return $response['headers'][ $header ];
    242242        }
    243243
    … …  
    256256 */
    257257function wp_remote_retrieve_response_code( $response ) {
    258         if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response']))
     258        if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
    259259                return '';
     260        }
    260261
    261262        return $response['response']['code'];
    … …  
    273274 */
    274275function wp_remote_retrieve_response_message( $response ) {
    275         if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response']))
     276        if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
    276277                return '';
     278        }
    277279
    278280        return $response['response']['message'];
    … …  
    288290 */
    289291function wp_remote_retrieve_body( $response ) {
    290         if ( is_wp_error($response) || ! isset($response['body']) )
     292        if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) {
    291293                return '';
     294        }
    292295
    293296        return $response['body'];
    … …  
    377380        }
    378381
    379         if ( $url && !isset( $capabilities['ssl'] ) ) {
     382        if ( $url && ! isset( $capabilities['ssl'] ) ) {
    380383                $scheme = parse_url( $url, PHP_URL_SCHEME );
    381384                if ( 'https' == $scheme || 'ssl' == $scheme ) {
    … …  
    396399function get_http_origin() {
    397400        $origin = '';
    398         if ( ! empty ( $_SERVER[ 'HTTP_ORIGIN' ] ) )
    399                 $origin = $_SERVER[ 'HTTP_ORIGIN' ];
     401        if ( ! empty( $_SERVER['HTTP_ORIGIN'] ) ) {
     402                $origin = $_SERVER['HTTP_ORIGIN'];
     403        }
    400404
    401405        /**
    … …  
    418422function get_allowed_http_origins() {
    419423        $admin_origin = parse_url( admin_url() );
    420         $home_origin = parse_url( home_url() );
     424        $home_origin  = parse_url( home_url() );
    421425
    422426        // @todo preserve port?
    423         $allowed_origins = array_unique( array(
    424                 'http://' . $admin_origin[ 'host' ],
    425                 'https://' . $admin_origin[ 'host' ],
    426                 'http://' . $home_origin[ 'host' ],
    427                 'https://' . $home_origin[ 'host' ],
    428         ) );
     427        $allowed_origins = array_unique(
     428                array(
     429                        'http://' . $admin_origin['host'],
     430                        'https://' . $admin_origin['host'],
     431                        'http://' . $home_origin['host'],
     432                        'https://' . $home_origin['host'],
     433                )
     434        );
    429435
    430436        /**
    … …  
    441447         * }
    442448         */
    443         return apply_filters( 'allowed_http_origins' , $allowed_origins );
     449        return apply_filters( 'allowed_http_origins', $allowed_origins );
    444450}
    445451
    … …  
    455461        $origin_arg = $origin;
    456462
    457         if ( null === $origin )
     463        if ( null === $origin ) {
    458464                $origin = get_http_origin();
    459 
    460         if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) )
     465        }
     466
     467        if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) ) {
    461468                $origin = '';
     469        }
    462470
    463471        /**
    … …  
    489497
    490498        if ( is_allowed_http_origin( $origin ) ) {
    491                 @header( 'Access-Control-Allow-Origin: ' .  $origin );
     499                @header( 'Access-Control-Allow-Origin: ' . $origin );
    492500                @header( 'Access-Control-Allow-Credentials: true' );
    493                 if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] )
     501                if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
    494502                        exit;
     503                }
    495504                return $origin;
    496505        }
    … …  
    514523function wp_http_validate_url( $url ) {
    515524        $original_url = $url;
    516         $url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) );
    517         if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) )
     525        $url          = wp_kses_bad_protocol( $url, array( 'http', 'https' ) );
     526        if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) {
    518527                return false;
     528        }
    519529
    520530        $parsed_url = @parse_url( $url );
    521         if ( ! $parsed_url || empty( $parsed_url['host'] ) )
     531        if ( ! $parsed_url || empty( $parsed_url['host'] ) ) {
    522532                return false;
    523 
    524         if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) )
     533        }
     534
     535        if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) {
    525536                return false;
    526 
    527         if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) )
     537        }
     538
     539        if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) {
    528540                return false;
     541        }
    529542
    530543        $parsed_home = @parse_url( get_option( 'home' ) );
    … …  
    542555                } else {
    543556                        $ip = gethostbyname( $host );
    544                         if ( $ip === $host ) // Error condition for gethostbyname()
     557                        if ( $ip === $host ) { // Error condition for gethostbyname()
    545558                                $ip = false;
     559                        }
    546560                }
    547561                if ( $ip ) {
    … …  
    563577                                 * @param string $url  URL of the requested host.
    564578                                 */
    565                                 if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) )
     579                                if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) {
    566580                                        return false;
     581                                }
    567582                        }
    568583                }
    569584        }
    570585
    571         if ( empty( $parsed_url['port'] ) )
     586        if ( empty( $parsed_url['port'] ) ) {
    572587                return $url;
     588        }
    573589
    574590        $port = $parsed_url['port'];
    575         if ( 80 === $port || 443 === $port || 8080 === $port )
     591        if ( 80 === $port || 443 === $port || 8080 === $port ) {
    576592                return $url;
    577 
    578         if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port )
     593        }
     594
     595        if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) {
    579596                return $url;
     597        }
    580598
    581599        return false;
    … …  
    594612 */
    595613function allowed_http_request_hosts( $is_external, $host ) {
    596         if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) )
     614        if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) {
    597615                $is_external = true;
     616        }
    598617        return $is_external;
    599618}
    … …  
    616635        global $wpdb;
    617636        static $queried = array();
    618         if ( $is_external )
     637        if ( $is_external ) {
    619638                return $is_external;
    620         if ( $host === get_network()->domain )
     639        }
     640        if ( $host === get_network()->domain ) {
    621641                return true;
    622         if ( isset( $queried[ $host ] ) )
     642        }
     643        if ( isset( $queried[ $host ] ) ) {
    623644                return $queried[ $host ];
     645        }
    624646        $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) );
    625647        return $queried[ $host ];
    … …  
    657679function wp_parse_url( $url, $component = -1 ) {
    658680        $to_unset = array();
    659         $url = strval( $url );
     681        $url      = strval( $url );
    660682
    661683        if ( '//' === substr( $url, 0, 2 ) ) {
    662684                $to_unset[] = 'scheme';
    663                 $url = 'placeholder:' . $url;
     685                $url        = 'placeholder:' . $url;
    664686        } elseif ( '/' === substr( $url, 0, 1 ) ) {
    665687                $to_unset[] = 'scheme';
    666688                $to_unset[] = 'host';
    667                 $url = 'placeholder://placeholder' . $url;
     689                $url        = 'placeholder://placeholder' . $url;
    668690        }
    669691
Note: See TracChangeset for help on using the changeset viewer.