rest_handle_options_request
函数
rest_handle_options_request ( $response, $handler, $request )
- 参数
-
-
(mixed)
$response
Current response, either response or `null` to indicate pass-through.- Required: 是
-
(WP_REST_Server)
$handler
ResponseHandler instance (usually WP_REST_Server).- Required: 是
-
(WP_REST_Request)
$request
The request that was used to make current response.- Required: 是
-
(mixed)
- 返回值
-
- (WP_REST_Response) Modified response, either response or `null` to indicate pass-through.
- 定义位置
-
-
wp-includes/rest-api.php
, line 755
-
wp-includes/rest-api.php
- 引入
- 4.4.0
- 弃用
- –
处理服务器的OPTIONS请求。
这是在服务器代码之外处理的,因为它不服从正常的路由映射。
function rest_handle_options_request( $response, $handler, $request ) {
if ( ! empty( $response ) || $request->get_method() !== 'OPTIONS' ) {
return $response;
}
$response = new WP_REST_Response();
$data = array();
foreach ( $handler->get_routes() as $route => $endpoints ) {
$match = preg_match( '@^' . $route . '$@i', $request->get_route(), $matches );
if ( ! $match ) {
continue;
}
$args = array();
foreach ( $matches as $param => $value ) {
if ( ! is_int( $param ) ) {
$args[ $param ] = $value;
}
}
foreach ( $endpoints as $endpoint ) {
// Remove the redundant preg_match() argument.
unset( $args[0] );
$request->set_url_params( $args );
$request->set_attributes( $endpoint );
}
$data = $handler->get_data_for_route( $route, $endpoints, 'help' );
$response->set_matched_route( $route );
break;
}
$response->set_data( $data );
return $response;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。