wp/wp-includes/http.php
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:52:52 +0200
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
permissions -rw-r--r--
Update WordPress to latest version (6.7) - Sync WordPress core files from latest release - Updated admin interface, blocks, and core functionality - Enhanced block editor features and performance - Security updates and bug fixes - Preserved custom wp-content directory and configuration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     3
 * Core HTTP Request API
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     5
 * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     6
 * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 * @subpackage HTTP
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * Returns the initialized WP_Http Object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * @return WP_Http HTTP Transport object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
function _wp_http_get_object() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    21
	static $http = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    23
	if ( is_null( $http ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		$http = new WP_Http();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	return $http;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    30
 * Retrieves the raw response from a safe HTTP request.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 * This function is ideal when the HTTP request is being made to an arbitrary
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    33
 * URL. The URL, and every URL it redirects to, are validated with wp_http_validate_url()
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    34
 * to avoid Server Side Request Forgery attacks (SSRF).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
 * @see wp_remote_request() For more information on the response array format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
 * @see WP_Http::request() For default arguments information.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    40
 * @see wp_http_validate_url() For more information about how the URL is validated.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    41
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    42
 * @link https://owasp.org/www-community/attacks/Server_Side_Request_Forgery
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    44
 * @param string $url  URL to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    46
 *                     See WP_Http::request() for information on accepted arguments.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    47
 * @return array|WP_Error The response or WP_Error on failure.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    48
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
function wp_safe_remote_request( $url, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	$args['reject_unsafe_urls'] = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    52
	$http                       = _wp_http_get_object();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	return $http->request( $url, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    57
 * Retrieves the raw response from a safe HTTP request using the GET method.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 * This function is ideal when the HTTP request is being made to an arbitrary
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    60
 * URL. The URL, and every URL it redirects to, are validated with wp_http_validate_url()
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    61
 * to avoid Server Side Request Forgery attacks (SSRF).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
 * @see wp_remote_request() For more information on the response array format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
 * @see WP_Http::request() For default arguments information.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    67
 * @see wp_http_validate_url() For more information about how the URL is validated.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    68
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    69
 * @link https://owasp.org/www-community/attacks/Server_Side_Request_Forgery
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    71
 * @param string $url  URL to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    73
 *                     See WP_Http::request() for information on accepted arguments.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    74
 * @return array|WP_Error The response or WP_Error on failure.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    75
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
function wp_safe_remote_get( $url, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	$args['reject_unsafe_urls'] = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    79
	$http                       = _wp_http_get_object();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	return $http->get( $url, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    84
 * Retrieves the raw response from a safe HTTP request using the POST method.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
 * This function is ideal when the HTTP request is being made to an arbitrary
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    87
 * URL. The URL, and every URL it redirects to, are validated with wp_http_validate_url()
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    88
 * to avoid Server Side Request Forgery attacks (SSRF).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
 * @see wp_remote_request() For more information on the response array format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
 * @see WP_Http::request() For default arguments information.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    94
 * @see wp_http_validate_url() For more information about how the URL is validated.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    95
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    96
 * @link https://owasp.org/www-community/attacks/Server_Side_Request_Forgery
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    98
 * @param string $url  URL to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   100
 *                     See WP_Http::request() for information on accepted arguments.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   101
 * @return array|WP_Error The response or WP_Error on failure.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   102
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
function wp_safe_remote_post( $url, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	$args['reject_unsafe_urls'] = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   106
	$http                       = _wp_http_get_object();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	return $http->post( $url, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   111
 * Retrieves the raw response from a safe HTTP request using the HEAD method.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 * This function is ideal when the HTTP request is being made to an arbitrary
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   114
 * URL. The URL, and every URL it redirects to, are validated with wp_http_validate_url()
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   115
 * to avoid Server Side Request Forgery attacks (SSRF).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
 * @see wp_remote_request() For more information on the response array format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
 * @see WP_Http::request() For default arguments information.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   121
 * @see wp_http_validate_url() For more information about how the URL is validated.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   122
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   123
 * @link https://owasp.org/www-community/attacks/Server_Side_Request_Forgery
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   125
 * @param string $url  URL to retrieve.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   126
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   127
 *                     See WP_Http::request() for information on accepted arguments.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   128
 * @return array|WP_Error The response or WP_Error on failure.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   129
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
function wp_safe_remote_head( $url, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	$args['reject_unsafe_urls'] = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   133
	$http                       = _wp_http_get_object();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
	return $http->head( $url, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   138
 * Performs an HTTP request and returns its response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   140
 * There are other API functions available which abstract away the HTTP method:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 *  - Default 'GET'  for wp_remote_get()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 *  - Default 'POST' for wp_remote_post()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
 *  - Default 'HEAD' for wp_remote_head()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   148
 * @see WP_Http::request() For information on default arguments.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   149
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   150
 * @param string $url  URL to retrieve.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   151
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   152
 *                     See WP_Http::request() for information on accepted arguments.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   153
 * @return array|WP_Error The response array or a WP_Error on failure.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   154
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   156
function wp_remote_request( $url, $args = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   157
	$http = _wp_http_get_object();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   158
	return $http->request( $url, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   162
 * Performs an HTTP request using the GET method and returns its response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
 * @see wp_remote_request() For more information on the response array format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
 * @see WP_Http::request() For default arguments information.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   169
 * @param string $url  URL to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   171
 *                     See WP_Http::request() for information on accepted arguments.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   172
 * @return array|WP_Error The response or WP_Error on failure.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   173
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   175
function wp_remote_get( $url, $args = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   176
	$http = _wp_http_get_object();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   177
	return $http->get( $url, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   181
 * Performs an HTTP request using the POST method and returns its response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
 * @see wp_remote_request() For more information on the response array format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
 * @see WP_Http::request() For default arguments information.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   188
 * @param string $url  URL to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   190
 *                     See WP_Http::request() for information on accepted arguments.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   191
 * @return array|WP_Error The response or WP_Error on failure.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   192
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   194
function wp_remote_post( $url, $args = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
	$http = _wp_http_get_object();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   196
	return $http->post( $url, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   200
 * Performs an HTTP request using the HEAD method and returns its response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
 * @see wp_remote_request() For more information on the response array format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
 * @see WP_Http::request() For default arguments information.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   207
 * @param string $url  URL to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
 * @param array  $args Optional. Request arguments. Default empty array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   209
 *                     See WP_Http::request() for information on accepted arguments.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   210
 * @return array|WP_Error The response or WP_Error on failure.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   211
 *                        See WP_Http::request() for information on return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   213
function wp_remote_head( $url, $args = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
	$http = _wp_http_get_object();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
	return $http->head( $url, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   219
 * Retrieves only the headers from the raw response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 * @since 2.7.0
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   222
 * @since 4.6.0 Return value changed from an array to an WpOrg\Requests\Utility\CaseInsensitiveDictionary instance.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
 *
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   224
 * @see \WpOrg\Requests\Utility\CaseInsensitiveDictionary
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   226
 * @param array|WP_Error $response HTTP response.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   227
 * @return \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array The headers of the response, or empty array
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   228
 *                                                                 if incorrect parameter given.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
function wp_remote_retrieve_headers( $response ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   231
	if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		return array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   233
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	return $response['headers'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   239
 * Retrieves a single header by name from the raw response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   243
 * @param array|WP_Error $response HTTP response.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   244
 * @param string         $header   Header name to retrieve value from.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   245
 * @return array|string The header(s) value(s). Array if multiple headers with the same name are retrieved.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   246
 *                      Empty string if incorrect parameter given, or if the header doesn't exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
function wp_remote_retrieve_header( $response, $header ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   249
	if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		return '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   253
	if ( isset( $response['headers'][ $header ] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   254
		return $response['headers'][ $header ];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   261
 * Retrieves only the response code from the raw response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   263
 * Will return an empty string if incorrect parameter value is given.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   267
 * @param array|WP_Error $response HTTP response.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   268
 * @return int|string The response code as an integer. Empty string if incorrect parameter given.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
function wp_remote_retrieve_response_code( $response ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   271
	if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		return '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   273
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	return $response['response']['code'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   279
 * Retrieves only the response message from the raw response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   281
 * Will return an empty string if incorrect parameter value is given.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   285
 * @param array|WP_Error $response HTTP response.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   286
 * @return string The response message. Empty string if incorrect parameter given.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
function wp_remote_retrieve_response_message( $response ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   289
	if ( is_wp_error( $response ) || ! isset( $response['response'] ) || ! is_array( $response['response'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
		return '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   291
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	return $response['response']['message'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   297
 * Retrieves only the body from the raw response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   301
 * @param array|WP_Error $response HTTP response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 * @return string The body of the response. Empty string if no body or incorrect parameter given.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
function wp_remote_retrieve_body( $response ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   305
	if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
		return '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   307
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	return $response['body'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   313
 * Retrieves only the cookies from the raw response.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   314
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   316
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   317
 * @param array|WP_Error $response HTTP response.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   318
 * @return WP_Http_Cookie[] An array of `WP_Http_Cookie` objects from the response.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   319
 *                          Empty array if there are none, or the response is a WP_Error.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   320
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   321
function wp_remote_retrieve_cookies( $response ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   322
	if ( is_wp_error( $response ) || empty( $response['cookies'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   323
		return array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   324
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   325
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
	return $response['cookies'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   327
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   330
 * Retrieves a single cookie by name from the raw response.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   331
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   332
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   333
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   334
 * @param array|WP_Error $response HTTP response.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   335
 * @param string         $name     The name of the cookie to retrieve.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   336
 * @return WP_Http_Cookie|string The `WP_Http_Cookie` object, or empty string
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   337
 *                               if the cookie is not present in the response.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   338
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
function wp_remote_retrieve_cookie( $response, $name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
	$cookies = wp_remote_retrieve_cookies( $response );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
	if ( empty( $cookies ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
		return '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
	foreach ( $cookies as $cookie ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
		if ( $cookie->name === $name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   348
			return $cookie;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   350
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   351
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   352
	return '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   353
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   355
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   356
 * Retrieves a single cookie's value by name from the raw response.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   357
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   360
 * @param array|WP_Error $response HTTP response.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   361
 * @param string         $name     The name of the cookie to retrieve.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   362
 * @return string The value of the cookie, or empty string
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   363
 *                if the cookie is not present in the response.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   365
function wp_remote_retrieve_cookie_value( $response, $name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
	$cookie = wp_remote_retrieve_cookie( $response, $name );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   367
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   368
	if ( ! ( $cookie instanceof WP_Http_Cookie ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   369
		return '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   370
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   371
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   372
	return $cookie->value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   373
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   374
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   375
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
 * Determines if there is an HTTP Transport that can process this request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
 * @param array  $capabilities Array of capabilities to test or a wp_remote_request() $args array.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   381
 * @param string $url          Optional. If given, will check if the URL requires SSL and adds
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   382
 *                             that requirement to the capabilities array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
function wp_http_supports( $capabilities = array(), $url = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
	$capabilities = wp_parse_args( $capabilities );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	$count = count( $capabilities );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   391
	// If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   392
	if ( $count && count( array_filter( array_keys( $capabilities ), 'is_numeric' ) ) === $count ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
		$capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   396
	if ( $url && ! isset( $capabilities['ssl'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
		$scheme = parse_url( $url, PHP_URL_SCHEME );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   398
		if ( 'https' === $scheme || 'ssl' === $scheme ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
			$capabilities['ssl'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   403
	return WpOrg\Requests\Requests::has_capabilities( $capabilities );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   407
 * Gets the HTTP Origin of the current request.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
 * @return string URL of the origin. Empty string if no origin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
function get_http_origin() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	$origin = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   415
	if ( ! empty( $_SERVER['HTTP_ORIGIN'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   416
		$origin = $_SERVER['HTTP_ORIGIN'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   417
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   420
	 * Changes the origin of an HTTP request.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 * @param string $origin The original origin for the request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	return apply_filters( 'http_origin', $origin );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   430
 * Retrieves list of allowed HTTP origins.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   434
 * @return string[] Array of origin URLs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
function get_allowed_http_origins() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	$admin_origin = parse_url( admin_url() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   438
	$home_origin  = parse_url( home_url() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   440
	// @todo Preserve port?
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   441
	$allowed_origins = array_unique(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   442
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   443
			'http://' . $admin_origin['host'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   444
			'https://' . $admin_origin['host'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   445
			'http://' . $home_origin['host'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   446
			'https://' . $home_origin['host'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   447
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   448
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   451
	 * Changes the origin types allowed for HTTP requests.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   455
	 * @param string[] $allowed_origins {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   456
	 *     Array of default allowed HTTP origins.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   457
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   458
	 *     @type string $0 Non-secure URL for admin origin.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   459
	 *     @type string $1 Secure URL for admin origin.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   460
	 *     @type string $2 Non-secure URL for home origin.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   461
	 *     @type string $3 Secure URL for home origin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	 * }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   464
	return apply_filters( 'allowed_http_origins', $allowed_origins );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
 * Determines if the HTTP origin is an authorized one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
 *
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   472
 * @param string|null $origin Origin URL. If not provided, the value of get_http_origin() is used.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   473
 * @return string Origin URL if allowed, empty string if not.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
function is_allowed_http_origin( $origin = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	$origin_arg = $origin;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   478
	if ( null === $origin ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
		$origin = get_http_origin();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   480
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   482
	if ( $origin && ! in_array( $origin, get_allowed_http_origins(), true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		$origin = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   484
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   487
	 * Changes the allowed HTTP origin result.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   491
	 * @param string $origin     Origin URL if allowed, empty string if not.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   492
	 * @param string $origin_arg Original origin string passed into is_allowed_http_origin function.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	return apply_filters( 'allowed_http_origin', $origin, $origin_arg );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   498
 * Sends Access-Control-Allow-Origin and related headers if the current request
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
 * is from an allowed origin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
 * If the request is an OPTIONS request, the script exits with either access
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
 * control headers sent, or a 403 response if the origin is not allowed. For
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
 * other request methods, you will receive a return value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   507
 * @return string|false Returns the origin URL if headers are sent. Returns false
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   508
 *                      if headers are not sent.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
function send_origin_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	$origin = get_http_origin();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	if ( is_allowed_http_origin( $origin ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   514
		header( 'Access-Control-Allow-Origin: ' . $origin );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   515
		header( 'Access-Control-Allow-Credentials: true' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   516
		if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
			exit;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   518
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		return $origin;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
		status_header( 403 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   531
 * Validates a URL for safe use in the HTTP API.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   532
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   533
 * Examples of URLs that are considered unsafe:
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   534
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   535
 * - ftp://example.com/caniload.php - Invalid protocol - only http and https are allowed.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   536
 * - http:///example.com/caniload.php - Malformed URL.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   537
 * - http://user:pass@example.com/caniload.php - Login information.
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   538
 * - http://example.invalid/caniload.php - Invalid hostname, as the IP cannot be looked up in DNS.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   539
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   540
 * Examples of URLs that are considered unsafe by default:
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   541
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   542
 * - http://192.168.0.1/caniload.php - IPs from LAN networks.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   543
 *   This can be changed with the {@see 'http_request_host_is_external'} filter.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   544
 * - http://198.143.164.252:81/caniload.php - By default, only 80, 443, and 8080 ports are allowed.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   545
 *   This can be changed with the {@see 'http_allowed_safe_ports'} filter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
 * @since 3.5.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   549
 * @param string $url Request URL.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   550
 * @return string|false URL or false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
function wp_http_validate_url( $url ) {
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   553
	if ( ! is_string( $url ) || '' === $url || is_numeric( $url ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   554
		return false;
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   555
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   556
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
	$original_url = $url;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   558
	$url          = wp_kses_bad_protocol( $url, array( 'http', 'https' ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   559
	if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   561
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   563
	$parsed_url = parse_url( $url );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   564
	if ( ! $parsed_url || empty( $parsed_url['host'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   566
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   568
	if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   570
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   572
	if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   574
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   576
	$parsed_home = parse_url( get_option( 'home' ) );
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   577
	$same_host   = isset( $parsed_home['host'] ) && strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   578
	$host        = trim( $parsed_url['host'], '.' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	if ( ! $same_host ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   581
		if ( preg_match( '#^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$#', $host ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
			$ip = $host;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
			$ip = gethostbyname( $host );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   585
			if ( $ip === $host ) { // Error condition for gethostbyname().
13
d255fe9cd479 Upgrade wordpress again
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   586
				return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   587
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
		if ( $ip ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
			$parts = array_map( 'intval', explode( '.', $ip ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   591
			if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0]
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
				|| ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
				|| ( 192 === $parts[0] && 168 === $parts[1] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
			) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
				// If host appears local, reject unless specifically allowed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
				/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   597
				 * Checks if HTTP request is external or not.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
				 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
				 * Allows to change and allow external requests for the HTTP request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
				 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
				 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
				 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   603
				 * @param bool   $external Whether HTTP request is external or not.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   604
				 * @param string $host     Host name of the requested URL.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   605
				 * @param string $url      Requested URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
				 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   607
				if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
					return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   609
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   614
	if ( empty( $parsed_url['port'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
		return $url;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   616
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	$port = $parsed_url['port'];
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   619
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   620
	/**
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   621
	 * Controls the list of ports considered safe in HTTP API.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   622
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   623
	 * Allows to change and allow external requests for the HTTP request.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   624
	 *
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   625
	 * @since 5.9.0
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   626
	 *
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   627
	 * @param int[]  $allowed_ports Array of integers for valid ports.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   628
	 * @param string $host          Host name of the requested URL.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   629
	 * @param string $url           Requested URL.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   630
	 */
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   631
	$allowed_ports = apply_filters( 'http_allowed_safe_ports', array( 80, 443, 8080 ), $host, $url );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   632
	if ( is_array( $allowed_ports ) && in_array( $port, $allowed_ports, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
		return $url;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   634
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   636
	if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
		return $url;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   638
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   644
 * Marks allowed redirect hosts safe for HTTP requests as well.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   646
 * Attached to the {@see 'http_request_host_is_external'} filter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   650
 * @param bool   $is_external
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
 * @param string $host
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
function allowed_http_request_hosts( $is_external, $host ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   655
	if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
		$is_external = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   657
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	return $is_external;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   662
 * Adds any domain in a multisite installation for safe HTTP requests to the
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   663
 * allowed list.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   665
 * Attached to the {@see 'http_request_host_is_external'} filter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   669
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   670
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   671
 * @param bool   $is_external
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
 * @param string $host
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
function ms_allowed_http_request_hosts( $is_external, $host ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
	global $wpdb;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	static $queried = array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   678
	if ( $is_external ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
		return $is_external;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   680
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   681
	if ( get_network()->domain === $host ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   683
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   684
	if ( isset( $queried[ $host ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
		return $queried[ $host ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   686
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	$queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
	return $queried[ $host ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   690
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   691
/**
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   692
 * A wrapper for PHP's parse_url() function that handles consistency in the return values
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   693
 * across PHP versions.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   694
 *
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   695
 * Across various PHP versions, schemeless URLs containing a ":" in the query
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
   696
 * are being handled inconsistently. This function works around those differences.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   697
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   698
 * @since 4.4.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   699
 * @since 4.7.0 The `$component` parameter was added for parity with PHP's `parse_url()`.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   700
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   701
 * @link https://www.php.net/manual/en/function.parse-url.php
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   702
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   703
 * @param string $url       The URL to parse.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   704
 * @param int    $component The specific component to retrieve. Use one of the PHP
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   705
 *                          predefined constants to specify which one.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   706
 *                          Defaults to -1 (= return all parts as an array).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   707
 * @return mixed False on parse failure; Array of URL components on success;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   708
 *               When a specific component has been requested: null if the component
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   709
 *               doesn't exist in the given URL; a string or - in the case of
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   710
 *               PHP_URL_PORT - integer when it does. See parse_url()'s return values.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   711
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   712
function wp_parse_url( $url, $component = -1 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   713
	$to_unset = array();
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   714
	$url      = (string) $url;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   715
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   716
	if ( str_starts_with( $url, '//' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   717
		$to_unset[] = 'scheme';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   718
		$url        = 'placeholder:' . $url;
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   719
	} elseif ( str_starts_with( $url, '/' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   720
		$to_unset[] = 'scheme';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   721
		$to_unset[] = 'host';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   722
		$url        = 'placeholder://placeholder' . $url;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   723
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   724
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   725
	$parts = parse_url( $url );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   726
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   727
	if ( false === $parts ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   728
		// Parsing failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   729
		return $parts;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   730
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   731
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   732
	// Remove the placeholder values.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   733
	foreach ( $to_unset as $key ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   734
		unset( $parts[ $key ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   735
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   736
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   737
	return _get_component_from_parsed_url_array( $parts, $component );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   738
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   739
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   740
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   741
 * Retrieves a specific component from a parsed URL array.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   742
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   743
 * @internal
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   744
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   745
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   746
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   747
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   748
 * @link https://www.php.net/manual/en/function.parse-url.php
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   749
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   750
 * @param array|false $url_parts The parsed URL. Can be false if the URL failed to parse.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   751
 * @param int         $component The specific component to retrieve. Use one of the PHP
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   752
 *                               predefined constants to specify which one.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   753
 *                               Defaults to -1 (= return all parts as an array).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   754
 * @return mixed False on parse failure; Array of URL components on success;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   755
 *               When a specific component has been requested: null if the component
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   756
 *               doesn't exist in the given URL; a string or - in the case of
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   757
 *               PHP_URL_PORT - integer when it does. See parse_url()'s return values.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   758
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   759
function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   760
	if ( -1 === $component ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   761
		return $url_parts;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   762
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   763
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   764
	$key = _wp_translate_php_url_constant_to_key( $component );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   765
	if ( false !== $key && is_array( $url_parts ) && isset( $url_parts[ $key ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   766
		return $url_parts[ $key ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   767
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   768
		return null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   769
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   770
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   771
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   772
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   773
 * Translates a PHP_URL_* constant to the named array keys PHP uses.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   774
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   775
 * @internal
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   776
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   777
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   778
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   779
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   780
 * @link https://www.php.net/manual/en/url.constants.php
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   781
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   782
 * @param int $constant PHP_URL_* constant.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   783
 * @return string|false The named key or false.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   784
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   785
function _wp_translate_php_url_constant_to_key( $constant ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   786
	$translation = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
		PHP_URL_SCHEME   => 'scheme',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   788
		PHP_URL_HOST     => 'host',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   789
		PHP_URL_PORT     => 'port',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   790
		PHP_URL_USER     => 'user',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
		PHP_URL_PASS     => 'pass',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   792
		PHP_URL_PATH     => 'path',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   793
		PHP_URL_QUERY    => 'query',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   794
		PHP_URL_FRAGMENT => 'fragment',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   795
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   796
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   797
	if ( isset( $translation[ $constant ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   798
		return $translation[ $constant ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   799
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   800
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   801
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   802
}