Summery Summery

Set the default values

Syntax Syntax

Requests::set_defaults( string $url, array $headers, array|null $data, string $type, array $options )

Parameters Parameters


(string) (Required) URL to request


(array) (Required) Extra headers to send with the request


(array|null) (Required) Data to send either as a query string for GET/HEAD requests, or in the body for POST requests


(string) (Required) HTTP request type


(array) (Required) Options for the request

Return Return

(array) $options

Source Source

File: wp-includes/class-requests.php

	 * @return array $options
	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) {

		if (is_string($options['proxy']) || is_array($options['proxy'])) {
			$options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
		if ($options['proxy'] !== false) {

		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) {

		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))) {
				$options['data_format'] = 'query';
			else {
				$options['data_format'] = 'body';



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.