On this page
Requests::set_defaults( string $url, array $headers, array|null $data, string $type, array $options ): array
Set the default values
Parameters
$urlstring Required-
URL to request
$headersarray Required-
Extra headers to send with the request
$dataarray|null Required-
Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
$typestring Required-
HTTP request type
$optionsarray Required-
Options for the request
Return
array $options
Source
File: wp-includes/class-requests.php. View all references
protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) {
if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) {
throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url);
}
if (empty($options['hooks'])) {
$options['hooks'] = new Requests_Hooks();
}
if (is_array($options['auth'])) {
$options['auth'] = new Requests_Auth_Basic($options['auth']);
}
if ($options['auth'] !== false) {
$options['auth']->register($options['hooks']);
}
if (is_string($options['proxy']) || is_array($options['proxy'])) {
$options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
}
if ($options['proxy'] !== false) {
$options['proxy']->register($options['hooks']);
}
if (is_array($options['cookies'])) {
$options['cookies'] = new Requests_Cookie_Jar($options['cookies']);
}
elseif (empty($options['cookies'])) {
$options['cookies'] = new Requests_Cookie_Jar();
}
if ($options['cookies'] !== false) {
$options['cookies']->register($options['hooks']);
}
if ($options['idn'] !== false) {
$iri = new Requests_IRI($url);
$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
$url = $iri->uri;
}
// Massage the type to ensure we support it.
$type = strtoupper($type);
if (!isset($options['data_format'])) {
if (in_array($type, array(self::HEAD, self::GET, self::DELETE), true)) {
$options['data_format'] = 'query';
}
else {
$options['data_format'] = 'body';
}
}
}
Related
Uses
| Uses | Description |
|---|---|
| Requests_IRI::__construct() wp-includes/Requests/IRI.php | Create a new IRI object, from a specified string |
| Requests_Exception::__construct() wp-includes/Requests/Exception.php | Create a new exception |
| Requests_Proxy_HTTP::__construct() wp-includes/Requests/Proxy/HTTP.php | Constructor |
| Requests_Auth_Basic::__construct() wp-includes/Requests/Auth/Basic.php | Constructor |
| Requests_Hooks::__construct() wp-includes/Requests/Hooks.php | Constructor |
| Requests_Cookie_Jar::__construct() wp-includes/Requests/Cookie/Jar.php | Create a new jar |
| Requests_IDNAEncoder::encode() wp-includes/Requests/IDNAEncoder.php | Encode a hostname using Punycode |
Used By
| Used By | Description |
|---|---|
| Requests::request() wp-includes/class-requests.php | Main interface for HTTP requests |
| Requests::request_multiple() wp-includes/class-requests.php | Send multiple HTTP requests simultaneously |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/requests/set_defaults