_oembed_rest_pre_serve_request

Advertisement

Private Access Private Access

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Summery Summery

Hooks into the REST API output to print XML instead of JSON.

Syntax Syntax

_oembed_rest_pre_serve_request( bool $served, WP_HTTP_ResponseInterface $result, WP_REST_Request $request, WP_REST_Server $server )

Description Description

This is only done for the oEmbed API endpoint, which supports both formats.

Parameters Parameters

$served

(bool) (Required) Whether the request has already been served.

$result

(WP_HTTP_ResponseInterface) (Required) Result to send to the client. Usually a WP_REST_Response.

$request

(WP_REST_Request) (Required) Request used to generate the response.

$server

(WP_REST_Server) (Required) Server instance.

Return Return

(true)

Source Source

File: wp-includes/embed.php

	if ( '/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method() ) {
		return $served;
	}

	if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) {
		return $served;
	}

	// Embed links inside the request.
	$data = $server->response_to_data( $result, false );

	if ( ! class_exists( 'SimpleXMLElement' ) ) {
		status_header( 501 );
		die( get_status_header_desc( 501 ) );
	}

	$result = _oembed_create_xml( $data );

	// Bail if there's no XML.
	if ( ! $result ) {
		status_header( 501 );
		return get_status_header_desc( 501 );
	}

	if ( ! headers_sent() ) {
		$server->send_header( 'Content-Type', 'text/xml; charset=' . get_option( 'blog_charset' ) );
	}

	echo $result;

	return true;
}

/**
 * Creates an XML string from a given array.

Advertisement

Changelog Changelog

Changelog
Version Description
4.4.0 Introduced.

Advertisement

Leave a Reply

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