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 主题开发
WordPress 常用函数 / sanitize_user
2023-07-25
WordPress 主题开发
WordPress 主题激活和取消激活钩子
2023-07-26
飞翔的鱼丸
39483 阅读
82 发布
2 收藏
动态
FishV 主题 v1.21.0 发布
LandV 企业主题 v2.8.0 发布
MirageV 主题 v2.6.4 发布
FishV 主题 v1.14 发布
MirageV 主题 v2.5 正式发布
BotV 插件 v1.7.0 发布
LandV 企业主题 v2.6.0 发布
MirageV 主题 v2.6.0 发布
生成中...
真诚赞赏,手留余香
登录
注册
重置密码