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/

 

声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
真诚赞赏,手留余香
赞赏
随机推荐
如何使主题支持 Woocommerce
WordPress 上传附件
CSS 改变 svg 图片颜色
p 标签里面不能嵌套块级元素
Node.js 的 URL 的模块
WordPress 数据库表结构
MySQL 表名预处理
CSS 媒体特性 prefers-color-scheme