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/

 

收藏 0
评论
WordPress 主题开发
WordPress 常用函数 / sanitize_user
2021-07-25 19:59:56
WordPress 基础
WordPress 主题激活和取消激活钩子
2021-07-26 02:09:14
生成中...
登录
注册
重置密码