Yoast\WP\SEO\Schema_Aggregator\User_Interface

Schemamap_Xml_Rewrite_Integration::maybe_render_schema_map │ public │ Yoast 1.0

Outputs the schema map when the main query is a request for it.

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

Хуков нет.

Возвращает

void. Ничего (null).

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

$Schemamap_Xml_Rewrite_Integration = new Schemamap_Xml_Rewrite_Integration();
$Schemamap_Xml_Rewrite_Integration->maybe_render_schema_map( $query );
$query(WP_Query) (обязательный)
The query that is about to run.

Код Schemamap_Xml_Rewrite_Integration::maybe_render_schema_map() Yoast 28.7

public function maybe_render_schema_map( WP_Query $query ) {
	if ( ! $query->is_main_query() || ! $query->get( self::QUERY_VAR ) ) {
		return;
	}

	/*
	 * Without control over the headers the response cannot be typed as XML, and echoing the
	 * document into a half-written HTML body would produce neither a page nor a schema map.
	 */
	if ( $this->headers_already_sent() ) {
		return;
	}

	/*
	 * Build the document before committing any headers. Generating it hits the database and can
	 * throw, and a failure after the 200 and the cache headers were sent would let a proxy store
	 * an HTML error page at this path for the full max-age.
	 */
	$xml = $this->schema_map_xml_provider->get_xml();

	$this->send_headers();

	// DOMDocument::createTextNode() already escaped every value; escaping again would corrupt the XML.
	echo $xml; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Raw XML.

	$this->finish_request();
}