Title: _oembed_rest_pre_serve_request
Published: December 9, 2015
Last modified: May 20, 2026

---

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

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#wp--skip-link--target)

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

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#description)󠁿

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#parameters)󠁿

 `$served`boolrequired

Whether the request has already been served.

`$result`[WP_HTTP_Response](https://developer.wordpress.org/reference/classes/wp_http_response/)
required

Result to send to the client. Usually a `WP_REST_Response`.

`$request`[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)
required

Request used to generate the response.

`$server`[WP_REST_Server](https://developer.wordpress.org/reference/classes/wp_rest_server/)
required

Server instance.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#return)󠁿

 bool True if the request was served, false otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#source)󠁿

    ```php
    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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/embed.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/embed.php#L782)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/embed.php#L782-L816)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#related)󠁿

| Uses | Description | 
| [_oembed_create_xml()](https://developer.wordpress.org/reference/functions/_oembed_create_xml/)`wp-includes/embed.php` |

Creates an XML string from a given array.

  | 
| [status_header()](https://developer.wordpress.org/reference/functions/status_header/)`wp-includes/functions.php` |

Sets HTTP status header.

  | 
| [get_status_header_desc()](https://developer.wordpress.org/reference/functions/get_status_header_desc/)`wp-includes/functions.php` |

Retrieves the description for the HTTP status.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_oembed_rest_pre_serve_request/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_oembed_rest_pre_serve_request%2F)
before being able to contribute a note or feedback.