rest_ensure_response() - WordPress 函数参考中文文档

返回介绍

rest_ensure_response()

发布于 2017-09-11 字数7014 浏览 1054 评论 0

rest_ensure_response( WP_Error|WP_HTTP_Response|mixed $response )

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


描述

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 );
}

更新日志

Version 描述
4.4.0 Introduced.

相关函数

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!