WP_REST_Response 返回结果类

在开发 WordPress RESTful API 时,用来返回结果集。可以修改 http 请求的状态码。

$data = array( 'some', 'response', 'data' );
 
// Create the response object
$response = new WP_REST_Response( $data );
 
// Add a custom status code
$response->set_status( 201 );
 
// Add a custom header
$response->header( 'Location', 'http://example.com/' );

官方文档:

http://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/

http://developer.wordpress.org/reference/classes/wp_rest_response/

 

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
Git 放弃本地修改,强制和之前的某次提交同步
JavaScript 滚动浏览器窗口到指定的元素
阿里云内容安全 API 签名机制
JavaScript 的 this 指向
ES6 Promise 和 async/await 教程
Express 使用 cookie-parser 处理 cookies
JavaScript navigator对象
WordPress RESTful API 的授权方式