wppaste
WordPress

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

Since
4.4.0
Source
wp-includes/embed.php:786
Hooks into the REST API output to print XML instead of JSON.

Description

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

Parameters

$servedbool
Whether the request has already been served.
$resultWP_HTTP_Response
Result to send to the client. Usually a WP_REST_Response.
$requestWP_REST_Request
Request used to generate the response.
$serverWP_REST_Server
Server instance.

Return

bool
True if the request was served, false otherwise.

Uses · 4

Source

function _oembed_rest_pre_serve_request( $served, $result, $request, $server ) {	$params = $request->get_params(); 	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 );		die( get_status_header_desc( 501 ) );	} 	if ( ! headers_sent() ) {		$server->send_header( 'Content-Type', 'text/xml; charset=' . get_option( 'blog_charset' ) );	} 	echo $result; 	return true;}

History

Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.9.7
Return type changed from true to bool.verified against source
4.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/embed.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.