返回介绍

rest_ensure_response()

发布于 2017-09-11 10:11:03 字数 7012 浏览 1311 评论 0 收藏 0

rest_ensure_response( WP_Error|WP_HTTP_Response|mixed $response )

Ensures a REST response is a response object (for consistency).


description

This implements WP_HTTP_Response, allowing usage of set_status/header/etc without needing to double-check the object. Will also allow WP_Error to indicate error responses, so users should immediately check for this value.


参数

$response

(WP_Error|WP_HTTP_Response|mixed) (Required) Response to check.


返回值

(WP_REST_Response|mixed) If response generated an error, WP_Error, if response is already an instance, WP_HTTP_Response, otherwise returns a new WP_REST_Response instance.


源代码

File: wp-includes/rest-api.php

function rest_ensure_response( $response ) {
	if ( is_wp_error( $response ) ) {
		return $response;
	}

	if ( $response instanceof WP_HTTP_Response ) {
		return $response;
	}

	return new WP_REST_Response( $response );
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

Uses

  • wp-includes/load.php: is_wp_error()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::get_current_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::create_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php: WP_REST_Revisions_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php: WP_REST_Revisions_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php: WP_REST_Revisions_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::create_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php: WP_REST_Post_Statuses_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php: WP_REST_Post_Statuses_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php: WP_REST_Post_Statuses_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::create_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::create_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php: WP_REST_Taxonomies_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php: WP_REST_Taxonomies_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php: WP_REST_Taxonomies_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php: WP_REST_Post_Types_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php: WP_REST_Post_Types_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php: WP_REST_Post_Types_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::get_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::get_items()
  • wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::dispatch()
  • wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::get_namespace_index()
  • wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::envelope_response()
  • wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::serve_request()
  • wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::embed_links()
  • Show 36 more used by Hide more used by

User Contributed Notes

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

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

发布评论

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