Edit File by line
/home/barbar84/www/wp-inclu...
File: http.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Core HTTP Request API
[2] Fix | Delete
*
[3] Fix | Delete
* Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk
[4] Fix | Delete
* decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations.
[5] Fix | Delete
*
[6] Fix | Delete
* @package WordPress
[7] Fix | Delete
* @subpackage HTTP
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Returns the initialized WP_Http Object
[12] Fix | Delete
*
[13] Fix | Delete
* @since 2.7.0
[14] Fix | Delete
* @access private
[15] Fix | Delete
*
[16] Fix | Delete
* @return WP_Http HTTP Transport object.
[17] Fix | Delete
*/
[18] Fix | Delete
function _wp_http_get_object() {
[19] Fix | Delete
static $http = null;
[20] Fix | Delete
[21] Fix | Delete
if ( is_null( $http ) ) {
[22] Fix | Delete
$http = new WP_Http();
[23] Fix | Delete
}
[24] Fix | Delete
return $http;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Retrieve the raw response from a safe HTTP request.
[29] Fix | Delete
*
[30] Fix | Delete
* This function is ideal when the HTTP request is being made to an arbitrary
[31] Fix | Delete
* URL. The URL is validated to avoid redirection and request forgery attacks.
[32] Fix | Delete
*
[33] Fix | Delete
* @since 3.6.0
[34] Fix | Delete
*
[35] Fix | Delete
* @see wp_remote_request() For more information on the response array format.
[36] Fix | Delete
* @see WP_Http::request() For default arguments information.
[37] Fix | Delete
*
[38] Fix | Delete
* @param string $url URL to retrieve.
[39] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[40] Fix | Delete
* @return array|WP_Error The response or WP_Error on failure.
[41] Fix | Delete
*/
[42] Fix | Delete
function wp_safe_remote_request( $url, $args = array() ) {
[43] Fix | Delete
$args['reject_unsafe_urls'] = true;
[44] Fix | Delete
$http = _wp_http_get_object();
[45] Fix | Delete
return $http->request( $url, $args );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Retrieve the raw response from a safe HTTP request using the GET method.
[50] Fix | Delete
*
[51] Fix | Delete
* This function is ideal when the HTTP request is being made to an arbitrary
[52] Fix | Delete
* URL. The URL is validated to avoid redirection and request forgery attacks.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 3.6.0
[55] Fix | Delete
*
[56] Fix | Delete
* @see wp_remote_request() For more information on the response array format.
[57] Fix | Delete
* @see WP_Http::request() For default arguments information.
[58] Fix | Delete
*
[59] Fix | Delete
* @param string $url URL to retrieve.
[60] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[61] Fix | Delete
* @return array|WP_Error The response or WP_Error on failure.
[62] Fix | Delete
*/
[63] Fix | Delete
function wp_safe_remote_get( $url, $args = array() ) {
[64] Fix | Delete
$args['reject_unsafe_urls'] = true;
[65] Fix | Delete
$http = _wp_http_get_object();
[66] Fix | Delete
return $http->get( $url, $args );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Retrieve the raw response from a safe HTTP request using the POST method.
[71] Fix | Delete
*
[72] Fix | Delete
* This function is ideal when the HTTP request is being made to an arbitrary
[73] Fix | Delete
* URL. The URL is validated to avoid redirection and request forgery attacks.
[74] Fix | Delete
*
[75] Fix | Delete
* @since 3.6.0
[76] Fix | Delete
*
[77] Fix | Delete
* @see wp_remote_request() For more information on the response array format.
[78] Fix | Delete
* @see WP_Http::request() For default arguments information.
[79] Fix | Delete
*
[80] Fix | Delete
* @param string $url URL to retrieve.
[81] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[82] Fix | Delete
* @return array|WP_Error The response or WP_Error on failure.
[83] Fix | Delete
*/
[84] Fix | Delete
function wp_safe_remote_post( $url, $args = array() ) {
[85] Fix | Delete
$args['reject_unsafe_urls'] = true;
[86] Fix | Delete
$http = _wp_http_get_object();
[87] Fix | Delete
return $http->post( $url, $args );
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Retrieve the raw response from a safe HTTP request using the HEAD method.
[92] Fix | Delete
*
[93] Fix | Delete
* This function is ideal when the HTTP request is being made to an arbitrary
[94] Fix | Delete
* URL. The URL is validated to avoid redirection and request forgery attacks.
[95] Fix | Delete
*
[96] Fix | Delete
* @since 3.6.0
[97] Fix | Delete
*
[98] Fix | Delete
* @see wp_remote_request() For more information on the response array format.
[99] Fix | Delete
* @see WP_Http::request() For default arguments information.
[100] Fix | Delete
*
[101] Fix | Delete
* @param string $url URL to retrieve.
[102] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[103] Fix | Delete
* @return array|WP_Error The response or WP_Error on failure.
[104] Fix | Delete
*/
[105] Fix | Delete
function wp_safe_remote_head( $url, $args = array() ) {
[106] Fix | Delete
$args['reject_unsafe_urls'] = true;
[107] Fix | Delete
$http = _wp_http_get_object();
[108] Fix | Delete
return $http->head( $url, $args );
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Performs an HTTP request and returns its response.
[113] Fix | Delete
*
[114] Fix | Delete
* There are other API functions available which abstract away the HTTP method:
[115] Fix | Delete
*
[116] Fix | Delete
* - Default 'GET' for wp_remote_get()
[117] Fix | Delete
* - Default 'POST' for wp_remote_post()
[118] Fix | Delete
* - Default 'HEAD' for wp_remote_head()
[119] Fix | Delete
*
[120] Fix | Delete
* @since 2.7.0
[121] Fix | Delete
*
[122] Fix | Delete
* @see WP_Http::request() For information on default arguments.
[123] Fix | Delete
*
[124] Fix | Delete
* @param string $url URL to retrieve.
[125] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[126] Fix | Delete
* @return array|WP_Error {
[127] Fix | Delete
* The response array or a WP_Error on failure.
[128] Fix | Delete
*
[129] Fix | Delete
* @type string[] $headers Array of response headers keyed by their name.
[130] Fix | Delete
* @type string $body Response body.
[131] Fix | Delete
* @type array $response {
[132] Fix | Delete
* Data about the HTTP response.
[133] Fix | Delete
*
[134] Fix | Delete
* @type int|false $code HTTP response code.
[135] Fix | Delete
* @type string|false $message HTTP response message.
[136] Fix | Delete
* }
[137] Fix | Delete
* @type WP_HTTP_Cookie[] $cookies Array of response cookies.
[138] Fix | Delete
* @type WP_HTTP_Requests_Response|null $http_response Raw HTTP response object.
[139] Fix | Delete
* }
[140] Fix | Delete
*/
[141] Fix | Delete
function wp_remote_request( $url, $args = array() ) {
[142] Fix | Delete
$http = _wp_http_get_object();
[143] Fix | Delete
return $http->request( $url, $args );
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Performs an HTTP request using the GET method and returns its response.
[148] Fix | Delete
*
[149] Fix | Delete
* @since 2.7.0
[150] Fix | Delete
*
[151] Fix | Delete
* @see wp_remote_request() For more information on the response array format.
[152] Fix | Delete
* @see WP_Http::request() For default arguments information.
[153] Fix | Delete
*
[154] Fix | Delete
* @param string $url URL to retrieve.
[155] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[156] Fix | Delete
* @return array|WP_Error The response or WP_Error on failure.
[157] Fix | Delete
*/
[158] Fix | Delete
function wp_remote_get( $url, $args = array() ) {
[159] Fix | Delete
$http = _wp_http_get_object();
[160] Fix | Delete
return $http->get( $url, $args );
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Performs an HTTP request using the POST method and returns its response.
[165] Fix | Delete
*
[166] Fix | Delete
* @since 2.7.0
[167] Fix | Delete
*
[168] Fix | Delete
* @see wp_remote_request() For more information on the response array format.
[169] Fix | Delete
* @see WP_Http::request() For default arguments information.
[170] Fix | Delete
*
[171] Fix | Delete
* @param string $url URL to retrieve.
[172] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[173] Fix | Delete
* @return array|WP_Error The response or WP_Error on failure.
[174] Fix | Delete
*/
[175] Fix | Delete
function wp_remote_post( $url, $args = array() ) {
[176] Fix | Delete
$http = _wp_http_get_object();
[177] Fix | Delete
return $http->post( $url, $args );
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Performs an HTTP request using the HEAD method and returns its response.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 2.7.0
[184] Fix | Delete
*
[185] Fix | Delete
* @see wp_remote_request() For more information on the response array format.
[186] Fix | Delete
* @see WP_Http::request() For default arguments information.
[187] Fix | Delete
*
[188] Fix | Delete
* @param string $url URL to retrieve.
[189] Fix | Delete
* @param array $args Optional. Request arguments. Default empty array.
[190] Fix | Delete
* @return array|WP_Error The response or WP_Error on failure.
[191] Fix | Delete
*/
[192] Fix | Delete
function wp_remote_head( $url, $args = array() ) {
[193] Fix | Delete
$http = _wp_http_get_object();
[194] Fix | Delete
return $http->head( $url, $args );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Retrieve only the headers from the raw response.
[199] Fix | Delete
*
[200] Fix | Delete
* @since 2.7.0
[201] Fix | Delete
* @since 4.6.0 Return value changed from an array to an Requests_Utility_CaseInsensitiveDictionary instance.
[202] Fix | Delete
*
[203] Fix | Delete
* @see \Requests_Utility_CaseInsensitiveDictionary
[204] Fix | Delete
*
[205] Fix | Delete
* @param array|WP_Error $response HTTP response.
[206] Fix | Delete
* @return array|\Requests_Utility_CaseInsensitiveDictionary The headers of the response. Empty array if incorrect parameter given.
[207] Fix | Delete
*/
[208] Fix | Delete
function wp_remote_retrieve_headers( $response ) {
[209] Fix | Delete
if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) {
[210] Fix | Delete
return array();
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
return $response['headers'];
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Retrieve a single header by name from the raw response.
[218] Fix | Delete
*
[219] Fix | Delete
* @since 2.7.0
[220] Fix | Delete
*
[221] Fix | Delete
* @param array|WP_Error $response HTTP response.
[222] Fix | Delete
* @param string $header Header name to retrieve value from.
[223] Fix | Delete
* @return string The header value. Empty string on if incorrect parameter given, or if the header doesn't exist.
[224] Fix | Delete
*/
[225] Fix | Delete
function wp_remote_retrieve_header( $response, $header ) {
[226] Fix | Delete
if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) {
[227] Fix | Delete
return '';
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
if ( isset( $response['headers'][ $header ] ) ) {
[231] Fix | Delete
return $response['headers'][ $header ];
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
return '';
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Retrieve only the response code from the raw response.
[239] Fix | Delete
*
[240] Fix | Delete
* Will return an empty array if incorrect parameter value is given.
[241] Fix | Delete
*
[242] Fix | Delete
* @since 2.7.0
[243] Fix | Delete
*
[244] Fix | Delete
* @param array|WP_Error $response HTTP response.
[245] Fix | Delete
* @return int|string The response code as an integer. Empty string on incorrect parameter given.
[246] Fix | Delete
*/
[247] Fix | Delete
function wp_remote_retrieve_response_code( $response ) {
[248] Fix | Delete
if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
[249] Fix | Delete
return '';
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
return $response['response']['code'];
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Retrieve only the response message from the raw response.
[257] Fix | Delete
*
[258] Fix | Delete
* Will return an empty array if incorrect parameter value is given.
[259] Fix | Delete
*
[260] Fix | Delete
* @since 2.7.0
[261] Fix | Delete
*
[262] Fix | Delete
* @param array|WP_Error $response HTTP response.
[263] Fix | Delete
* @return string The response message. Empty string on incorrect parameter given.
[264] Fix | Delete
*/
[265] Fix | Delete
function wp_remote_retrieve_response_message( $response ) {
[266] Fix | Delete
if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
[267] Fix | Delete
return '';
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
return $response['response']['message'];
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Retrieve only the body from the raw response.
[275] Fix | Delete
*
[276] Fix | Delete
* @since 2.7.0
[277] Fix | Delete
*
[278] Fix | Delete
* @param array|WP_Error $response HTTP response.
[279] Fix | Delete
* @return string The body of the response. Empty string if no body or incorrect parameter given.
[280] Fix | Delete
*/
[281] Fix | Delete
function wp_remote_retrieve_body( $response ) {
[282] Fix | Delete
if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) {
[283] Fix | Delete
return '';
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
return $response['body'];
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Retrieve only the cookies from the raw response.
[291] Fix | Delete
*
[292] Fix | Delete
* @since 4.4.0
[293] Fix | Delete
*
[294] Fix | Delete
* @param array|WP_Error $response HTTP response.
[295] Fix | Delete
* @return WP_Http_Cookie[] An array of `WP_Http_Cookie` objects from the response. Empty array if there are none, or the response is a WP_Error.
[296] Fix | Delete
*/
[297] Fix | Delete
function wp_remote_retrieve_cookies( $response ) {
[298] Fix | Delete
if ( is_wp_error( $response ) || empty( $response['cookies'] ) ) {
[299] Fix | Delete
return array();
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
return $response['cookies'];
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Retrieve a single cookie by name from the raw response.
[307] Fix | Delete
*
[308] Fix | Delete
* @since 4.4.0
[309] Fix | Delete
*
[310] Fix | Delete
* @param array|WP_Error $response HTTP response.
[311] Fix | Delete
* @param string $name The name of the cookie to retrieve.
[312] Fix | Delete
* @return WP_Http_Cookie|string The `WP_Http_Cookie` object. Empty string if the cookie isn't present in the response.
[313] Fix | Delete
*/
[314] Fix | Delete
function wp_remote_retrieve_cookie( $response, $name ) {
[315] Fix | Delete
$cookies = wp_remote_retrieve_cookies( $response );
[316] Fix | Delete
[317] Fix | Delete
if ( empty( $cookies ) ) {
[318] Fix | Delete
return '';
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
foreach ( $cookies as $cookie ) {
[322] Fix | Delete
if ( $cookie->name === $name ) {
[323] Fix | Delete
return $cookie;
[324] Fix | Delete
}
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
return '';
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
/**
[331] Fix | Delete
* Retrieve a single cookie's value by name from the raw response.
[332] Fix | Delete
*
[333] Fix | Delete
* @since 4.4.0
[334] Fix | Delete
*
[335] Fix | Delete
* @param array|WP_Error $response HTTP response.
[336] Fix | Delete
* @param string $name The name of the cookie to retrieve.
[337] Fix | Delete
* @return string The value of the cookie. Empty string if the cookie isn't present in the response.
[338] Fix | Delete
*/
[339] Fix | Delete
function wp_remote_retrieve_cookie_value( $response, $name ) {
[340] Fix | Delete
$cookie = wp_remote_retrieve_cookie( $response, $name );
[341] Fix | Delete
[342] Fix | Delete
if ( ! is_a( $cookie, 'WP_Http_Cookie' ) ) {
[343] Fix | Delete
return '';
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
return $cookie->value;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
/**
[350] Fix | Delete
* Determines if there is an HTTP Transport that can process this request.
[351] Fix | Delete
*
[352] Fix | Delete
* @since 3.2.0
[353] Fix | Delete
*
[354] Fix | Delete
* @param array $capabilities Array of capabilities to test or a wp_remote_request() $args array.
[355] Fix | Delete
* @param string $url Optional. If given, will check if the URL requires SSL and adds
[356] Fix | Delete
* that requirement to the capabilities array.
[357] Fix | Delete
*
[358] Fix | Delete
* @return bool
[359] Fix | Delete
*/
[360] Fix | Delete
function wp_http_supports( $capabilities = array(), $url = null ) {
[361] Fix | Delete
$http = _wp_http_get_object();
[362] Fix | Delete
[363] Fix | Delete
$capabilities = wp_parse_args( $capabilities );
[364] Fix | Delete
[365] Fix | Delete
$count = count( $capabilities );
[366] Fix | Delete
[367] Fix | Delete
// If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array.
[368] Fix | Delete
if ( $count && count( array_filter( array_keys( $capabilities ), 'is_numeric' ) ) == $count ) {
[369] Fix | Delete
$capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
if ( $url && ! isset( $capabilities['ssl'] ) ) {
[373] Fix | Delete
$scheme = parse_url( $url, PHP_URL_SCHEME );
[374] Fix | Delete
if ( 'https' === $scheme || 'ssl' === $scheme ) {
[375] Fix | Delete
$capabilities['ssl'] = true;
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
return (bool) $http->_get_first_available_transport( $capabilities );
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* Get the HTTP Origin of the current request.
[384] Fix | Delete
*
[385] Fix | Delete
* @since 3.4.0
[386] Fix | Delete
*
[387] Fix | Delete
* @return string URL of the origin. Empty string if no origin.
[388] Fix | Delete
*/
[389] Fix | Delete
function get_http_origin() {
[390] Fix | Delete
$origin = '';
[391] Fix | Delete
if ( ! empty( $_SERVER['HTTP_ORIGIN'] ) ) {
[392] Fix | Delete
$origin = $_SERVER['HTTP_ORIGIN'];
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
/**
[396] Fix | Delete
* Change the origin of an HTTP request.
[397] Fix | Delete
*
[398] Fix | Delete
* @since 3.4.0
[399] Fix | Delete
*
[400] Fix | Delete
* @param string $origin The original origin for the request.
[401] Fix | Delete
*/
[402] Fix | Delete
return apply_filters( 'http_origin', $origin );
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
/**
[406] Fix | Delete
* Retrieve list of allowed HTTP origins.
[407] Fix | Delete
*
[408] Fix | Delete
* @since 3.4.0
[409] Fix | Delete
*
[410] Fix | Delete
* @return string[] Array of origin URLs.
[411] Fix | Delete
*/
[412] Fix | Delete
function get_allowed_http_origins() {
[413] Fix | Delete
$admin_origin = parse_url( admin_url() );
[414] Fix | Delete
$home_origin = parse_url( home_url() );
[415] Fix | Delete
[416] Fix | Delete
// @todo Preserve port?
[417] Fix | Delete
$allowed_origins = array_unique(
[418] Fix | Delete
array(
[419] Fix | Delete
'http://' . $admin_origin['host'],
[420] Fix | Delete
'https://' . $admin_origin['host'],
[421] Fix | Delete
'http://' . $home_origin['host'],
[422] Fix | Delete
'https://' . $home_origin['host'],
[423] Fix | Delete
)
[424] Fix | Delete
);
[425] Fix | Delete
[426] Fix | Delete
/**
[427] Fix | Delete
* Change the origin types allowed for HTTP requests.
[428] Fix | Delete
*
[429] Fix | Delete
* @since 3.4.0
[430] Fix | Delete
*
[431] Fix | Delete
* @param string[] $allowed_origins {
[432] Fix | Delete
* Array of default allowed HTTP origins.
[433] Fix | Delete
*
[434] Fix | Delete
* @type string $0 Non-secure URL for admin origin.
[435] Fix | Delete
* @type string $1 Secure URL for admin origin.
[436] Fix | Delete
* @type string $2 Non-secure URL for home origin.
[437] Fix | Delete
* @type string $3 Secure URL for home origin.
[438] Fix | Delete
* }
[439] Fix | Delete
*/
[440] Fix | Delete
return apply_filters( 'allowed_http_origins', $allowed_origins );
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Determines if the HTTP origin is an authorized one.
[445] Fix | Delete
*
[446] Fix | Delete
* @since 3.4.0
[447] Fix | Delete
*
[448] Fix | Delete
* @param null|string $origin Origin URL. If not provided, the value of get_http_origin() is used.
[449] Fix | Delete
* @return string Origin URL if allowed, empty string if not.
[450] Fix | Delete
*/
[451] Fix | Delete
function is_allowed_http_origin( $origin = null ) {
[452] Fix | Delete
$origin_arg = $origin;
[453] Fix | Delete
[454] Fix | Delete
if ( null === $origin ) {
[455] Fix | Delete
$origin = get_http_origin();
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
if ( $origin && ! in_array( $origin, get_allowed_http_origins(), true ) ) {
[459] Fix | Delete
$origin = '';
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
/**
[463] Fix | Delete
* Change the allowed HTTP origin result.
[464] Fix | Delete
*
[465] Fix | Delete
* @since 3.4.0
[466] Fix | Delete
*
[467] Fix | Delete
* @param string $origin Origin URL if allowed, empty string if not.
[468] Fix | Delete
* @param string $origin_arg Original origin string passed into is_allowed_http_origin function.
[469] Fix | Delete
*/
[470] Fix | Delete
return apply_filters( 'allowed_http_origin', $origin, $origin_arg );
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Send Access-Control-Allow-Origin and related headers if the current request
[475] Fix | Delete
* is from an allowed origin.
[476] Fix | Delete
*
[477] Fix | Delete
* If the request is an OPTIONS request, the script exits with either access
[478] Fix | Delete
* control headers sent, or a 403 response if the origin is not allowed. For
[479] Fix | Delete
* other request methods, you will receive a return value.
[480] Fix | Delete
*
[481] Fix | Delete
* @since 3.4.0
[482] Fix | Delete
*
[483] Fix | Delete
* @return string|false Returns the origin URL if headers are sent. Returns false
[484] Fix | Delete
* if headers are not sent.
[485] Fix | Delete
*/
[486] Fix | Delete
function send_origin_headers() {
[487] Fix | Delete
$origin = get_http_origin();
[488] Fix | Delete
[489] Fix | Delete
if ( is_allowed_http_origin( $origin ) ) {
[490] Fix | Delete
header( 'Access-Control-Allow-Origin: ' . $origin );
[491] Fix | Delete
header( 'Access-Control-Allow-Credentials: true' );
[492] Fix | Delete
if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
[493] Fix | Delete
exit;
[494] Fix | Delete
}
[495] Fix | Delete
return $origin;
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function