WP_REST_Server::get_headers()publicWP 4.4.0

Extracts headers from a PHP-style $_SERVER array.

Метод класса: WP_REST_Server{}

Хуков нет.

Возвращает

Массив. Headers extracted from the input.

Использование

$WP_REST_Server = new WP_REST_Server();
$WP_REST_Server->get_headers( $server );
$server(массив) (обязательный)
Associative array similar to $_SERVER.

Список изменений

С версии 4.4.0 Введена.

Код WP_REST_Server::get_headers() WP 6.5.2

public function get_headers( $server ) {
	$headers = array();

	// CONTENT_* headers are not prefixed with HTTP_.
	$additional = array(
		'CONTENT_LENGTH' => true,
		'CONTENT_MD5'    => true,
		'CONTENT_TYPE'   => true,
	);

	foreach ( $server as $key => $value ) {
		if ( str_starts_with( $key, 'HTTP_' ) ) {
			$headers[ substr( $key, 5 ) ] = $value;
		} elseif ( 'REDIRECT_HTTP_AUTHORIZATION' === $key && empty( $server['HTTP_AUTHORIZATION'] ) ) {
			/*
			 * In some server configurations, the authorization header is passed in this alternate location.
			 * Since it would not be passed in in both places we do not check for both headers and resolve.
			 */
			$headers['AUTHORIZATION'] = $value;
		} elseif ( isset( $additional[ $key ] ) ) {
			$headers[ $key ] = $value;
		}
	}

	return $headers;
}