diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/http.php --- a/wp/wp-includes/http.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/http.php Mon Oct 14 18:28:13 2019 +0200 @@ -45,7 +45,7 @@ */ function wp_safe_remote_request( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; - $http = _wp_http_get_object(); + $http = _wp_http_get_object(); return $http->request( $url, $args ); } @@ -66,7 +66,7 @@ */ function wp_safe_remote_get( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; - $http = _wp_http_get_object(); + $http = _wp_http_get_object(); return $http->get( $url, $args ); } @@ -87,7 +87,7 @@ */ function wp_safe_remote_post( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; - $http = _wp_http_get_object(); + $http = _wp_http_get_object(); return $http->post( $url, $args ); } @@ -108,7 +108,7 @@ */ function wp_safe_remote_head( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; - $http = _wp_http_get_object(); + $http = _wp_http_get_object(); return $http->head( $url, $args ); } @@ -148,7 +148,7 @@ * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ -function wp_remote_request($url, $args = array()) { +function wp_remote_request( $url, $args = array() ) { $http = _wp_http_get_object(); return $http->request( $url, $args ); } @@ -165,7 +165,7 @@ * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ -function wp_remote_get($url, $args = array()) { +function wp_remote_get( $url, $args = array() ) { $http = _wp_http_get_object(); return $http->get( $url, $args ); } @@ -182,7 +182,7 @@ * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ -function wp_remote_post($url, $args = array()) { +function wp_remote_post( $url, $args = array() ) { $http = _wp_http_get_object(); return $http->post( $url, $args ); } @@ -199,7 +199,7 @@ * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ -function wp_remote_head($url, $args = array()) { +function wp_remote_head( $url, $args = array() ) { $http = _wp_http_get_object(); return $http->head( $url, $args ); } @@ -238,7 +238,7 @@ } if ( isset( $response['headers'][ $header ] ) ) { - return $response['headers'][$header]; + return $response['headers'][ $header ]; } return ''; @@ -255,8 +255,9 @@ * @return int|string The response code as an integer. Empty string on incorrect parameter given. */ function wp_remote_retrieve_response_code( $response ) { - if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) + if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) { return ''; + } return $response['response']['code']; } @@ -272,8 +273,9 @@ * @return string The response message. Empty string on incorrect parameter given. */ function wp_remote_retrieve_response_message( $response ) { - if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) + if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) { return ''; + } return $response['response']['message']; } @@ -287,8 +289,9 @@ * @return string The body of the response. Empty string if no body or incorrect parameter given. */ function wp_remote_retrieve_body( $response ) { - if ( is_wp_error($response) || ! isset($response['body']) ) + if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) { return ''; + } return $response['body']; } @@ -376,7 +379,7 @@ $capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) ); } - if ( $url && !isset( $capabilities['ssl'] ) ) { + if ( $url && ! isset( $capabilities['ssl'] ) ) { $scheme = parse_url( $url, PHP_URL_SCHEME ); if ( 'https' == $scheme || 'ssl' == $scheme ) { $capabilities['ssl'] = true; @@ -395,8 +398,9 @@ */ function get_http_origin() { $origin = ''; - if ( ! empty ( $_SERVER[ 'HTTP_ORIGIN' ] ) ) - $origin = $_SERVER[ 'HTTP_ORIGIN' ]; + if ( ! empty( $_SERVER['HTTP_ORIGIN'] ) ) { + $origin = $_SERVER['HTTP_ORIGIN']; + } /** * Change the origin of an HTTP request. @@ -417,15 +421,17 @@ */ function get_allowed_http_origins() { $admin_origin = parse_url( admin_url() ); - $home_origin = parse_url( home_url() ); + $home_origin = parse_url( home_url() ); // @todo preserve port? - $allowed_origins = array_unique( array( - 'http://' . $admin_origin[ 'host' ], - 'https://' . $admin_origin[ 'host' ], - 'http://' . $home_origin[ 'host' ], - 'https://' . $home_origin[ 'host' ], - ) ); + $allowed_origins = array_unique( + array( + 'http://' . $admin_origin['host'], + 'https://' . $admin_origin['host'], + 'http://' . $home_origin['host'], + 'https://' . $home_origin['host'], + ) + ); /** * Change the origin types allowed for HTTP requests. @@ -440,7 +446,7 @@ * @type string Secure URL for home origin. * } */ - return apply_filters( 'allowed_http_origins' , $allowed_origins ); + return apply_filters( 'allowed_http_origins', $allowed_origins ); } /** @@ -454,11 +460,13 @@ function is_allowed_http_origin( $origin = null ) { $origin_arg = $origin; - if ( null === $origin ) + if ( null === $origin ) { $origin = get_http_origin(); + } - if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) ) + if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) ) { $origin = ''; + } /** * Change the allowed HTTP origin result. @@ -488,10 +496,11 @@ $origin = get_http_origin(); if ( is_allowed_http_origin( $origin ) ) { - @header( 'Access-Control-Allow-Origin: ' . $origin ); + @header( 'Access-Control-Allow-Origin: ' . $origin ); @header( 'Access-Control-Allow-Credentials: true' ); - if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) + if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) { exit; + } return $origin; } @@ -513,19 +522,23 @@ */ function wp_http_validate_url( $url ) { $original_url = $url; - $url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) ); - if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) + $url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) ); + if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) { return false; + } $parsed_url = @parse_url( $url ); - if ( ! $parsed_url || empty( $parsed_url['host'] ) ) + if ( ! $parsed_url || empty( $parsed_url['host'] ) ) { return false; + } - if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) + if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) { return false; + } - if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) + if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) { return false; + } $parsed_home = @parse_url( get_option( 'home' ) ); @@ -541,8 +554,9 @@ $ip = $host; } else { $ip = gethostbyname( $host ); - if ( $ip === $host ) // Error condition for gethostbyname() + if ( $ip === $host ) { // Error condition for gethostbyname() $ip = false; + } } if ( $ip ) { $parts = array_map( 'intval', explode( '.', $ip ) ); @@ -562,21 +576,25 @@ * @param string $host IP of the requested host. * @param string $url URL of the requested host. */ - if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) + if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) { return false; + } } } } - if ( empty( $parsed_url['port'] ) ) + if ( empty( $parsed_url['port'] ) ) { return $url; + } $port = $parsed_url['port']; - if ( 80 === $port || 443 === $port || 8080 === $port ) + if ( 80 === $port || 443 === $port || 8080 === $port ) { return $url; + } - if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) + if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) { return $url; + } return false; } @@ -593,8 +611,9 @@ * @return bool */ function allowed_http_request_hosts( $is_external, $host ) { - if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) + if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) { $is_external = true; + } return $is_external; } @@ -615,12 +634,15 @@ function ms_allowed_http_request_hosts( $is_external, $host ) { global $wpdb; static $queried = array(); - if ( $is_external ) + if ( $is_external ) { return $is_external; - if ( $host === get_network()->domain ) + } + if ( $host === get_network()->domain ) { return true; - if ( isset( $queried[ $host ] ) ) + } + if ( isset( $queried[ $host ] ) ) { return $queried[ $host ]; + } $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) ); return $queried[ $host ]; } @@ -641,7 +663,7 @@ * when URL parsing failed. * * @since 4.4.0 - * @since 4.7.0 The $component parameter was added for parity with PHP's parse_url(). + * @since 4.7.0 The `$component` parameter was added for parity with PHP's `parse_url()`. * * @link https://secure.php.net/manual/en/function.parse-url.php * @@ -656,15 +678,15 @@ */ function wp_parse_url( $url, $component = -1 ) { $to_unset = array(); - $url = strval( $url ); + $url = strval( $url ); if ( '//' === substr( $url, 0, 2 ) ) { $to_unset[] = 'scheme'; - $url = 'placeholder:' . $url; + $url = 'placeholder:' . $url; } elseif ( '/' === substr( $url, 0, 1 ) ) { $to_unset[] = 'scheme'; $to_unset[] = 'host'; - $url = 'placeholder://placeholder' . $url; + $url = 'placeholder://placeholder' . $url; } $parts = @parse_url( $url );