WP_REST_URL_Details_Controller::get_document_head()privateWP 5.9.0

Retrieves the head element section.

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

Хуков нет.

Возвращает

Строку. The <head>..</head> section on success. Given $html if not found.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_document_head( $html );
$html(строка) (обязательный)
The string of HTML to parse.

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

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

Код WP_REST_URL_Details_Controller::get_document_head() WP 6.5.2

private function get_document_head( $html ) {
	$head_html = $html;

	// Find the opening `<head>` tag.
	$head_start = strpos( $html, '<head' );
	if ( false === $head_start ) {
		// Didn't find it. Return the original HTML.
		return $html;
	}

	// Find the closing `</head>` tag.
	$head_end = strpos( $head_html, '</head>' );
	if ( false === $head_end ) {
		// Didn't find it. Find the opening `<body>` tag.
		$head_end = strpos( $head_html, '<body' );

		// Didn't find it. Return the original HTML.
		if ( false === $head_end ) {
			return $html;
		}
	}

	// Extract the HTML from opening tag to the closing tag. Then add the closing tag.
	$head_html  = substr( $head_html, $head_start, $head_end );
	$head_html .= '</head>';

	return $head_html;
}