返回介绍

_oembed_rest_pre_serve_request()

发布于 2017-09-11 13:29:28 字数 2670 浏览 1076 评论 0 收藏 0

Alert: 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.

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

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.


参数

$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.


返回值

(true)


源代码

File: wp-includes/embed.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 );
		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;
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

Uses

  • wp-includes/embed.php: _oembed_create_xml()
  • wp-includes/functions.php: status_header()
  • wp-includes/functions.php: get_status_header_desc()
  • wp-includes/option.php: get_option()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文