_oembed_rest_pre_serve_request( bool $served, WP_HTTP_Response $result, WP_REST_Request $request, WP_REST_Server $server ): true
- Since
- 4.4.0
- Source
wp-includes/embed.php:770
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
true
Uses · 4
- status_header()Sets HTTP status header.
- get_status_header_desc()Retrieves the description for the HTTP status.
- _oembed_create_xml()Creates an XML string from a given array.
- get_option()Retrieves an option value based on an option name.
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 ); 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;}History
Introduced in 4.4.0. One change between 6.7.7 and 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 source4.4.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.