WP_REST_Request::set_headers() WordPress Method

The WP_REST_Request::set_headers() method allows you to set headers on a request. This is useful for setting authentication headers or other types of headers that need to be set on a request.

WP_REST_Request::set_headers( array $headers, bool $override = true ) #

Sets headers on the request.


Parameters

$headers

(array)(Required)Map of header name to value.

$override

(bool)(Optional)If true, replace the request's headers. Otherwise, merge with existing.

Default value: true


Top ↑

Source

File: wp-includes/rest-api/class-wp-rest-request.php

	public function set_headers( $headers, $override = true ) {
		if ( true === $override ) {
			$this->headers = array();
		}

		foreach ( $headers as $key => $value ) {
			$this->set_header( $key, $value );
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.