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/

 

收藏
评论
打赏
WordPress 常用函数 / sanitize_user
上一篇
WordPress 主题激活和取消激活钩子
下一篇
像素鱼丸
50005 阅读
91 发布
3 收藏
动态
MirageV 主题 2.16.2 发布
MirageV 主题 v2.6.4 发布
LandV 企业主题 v2.6.0 发布
FishV 主题 v1.14 发布
BotV 插件 v1.7.0 发布
FishV 主题 v1.21.0 发布
MirageV 主题 v2.5 正式发布
MirageV 主题 v2.6.0 发布
生成中...
真诚赞赏,手留余香
登录
注册
重置密码