返回介绍

rest_get_server()

发布于 2017-09-11 10:11:22 字数 2210 浏览 900 评论 0 收藏 0

rest_get_server()

Retrieves the current REST server instance.


description

Instantiates a new instance if none exists already.


返回值

(WP_REST_Server) REST server instance.


源代码

File: wp-includes/rest-api.php

function rest_get_server() {
	/* @var WP_REST_Server $wp_rest_server */
	global $wp_rest_server;

	if ( empty( $wp_rest_server ) ) {
		/**
		 * Filters the REST Server Class.
		 *
		 * This filter allows you to adjust the server class used by the API, using a
		 * different class to handle requests.
		 *
		 * @since 4.4.0
		 *
		 * @param string $class_name The name of the server class. Default 'WP_REST_Server'.
		 */
		$wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' );
		$wp_rest_server = new $wp_rest_server_class;

		/**
		 * Fires when preparing to serve an API request.
		 *
		 * Endpoint objects should be created and register their hooks on this action rather
		 * than another action to ensure they're only loaded when needed.
		 *
		 * @since 4.4.0
		 *
		 * @param WP_REST_Server $wp_rest_server Server object.
		 */
		do_action( 'rest_api_init', $wp_rest_server );
	}

	return $wp_rest_server;
}

更新日志

Versiondescription
4.5.0Introduced.

相关函数

Uses

  • wp-includes/rest-api.php: wp_rest_server_class
  • wp-includes/rest-api.php: rest_api_init
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/plugin.php: do_action()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-controller.php: WP_REST_Controller::prepare_response_for_collection()
  • wp-includes/rest-api.php: rest_do_request()
  • wp-includes/rest-api.php: rest_api_loaded()

User Contributed Notes

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

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

发布评论

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