BP_Core_oEmbed_Extension::oembed_xml_request( bool $served, WP_HTTP_ResponseInterface $result, WP_REST_Request $request, WP_REST_Server $server )

If oEmbed request wants XML, return XML instead of JSON.

Description

Basically a copy of _oembed_rest_pre_serve_request(). Unfortunate that we have to duplicate this just for a URL check.

Parameters

$served

(Required) Whether the request has already been served.

$result

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

$request

(Required) Request used to generate the response.

$server

(Required) Server instance.

Return

(bool)

Source

File: bp-core/classes/class-bp-core-oembed-extension.php

	public function oembed_xml_request( $served, $result, $request, $server ) {
		$params = $request->get_params();

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

		// Validate URL against our oEmbed endpoint. If not valid, bail.
		// This is our mod to _oembed_rest_pre_serve_request().
		$query_params = $request->get_query_params();
		if ( false === $this->validate_url_to_item_id( $query_params['url'] ) ) {
			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;
	}

Changelog

Changelog
Version Description
BuddyPress 2.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.