本文整理汇总了PHP中WP_REST_Response::set_matched_route方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Response::set_matched_route方法的具体用法?PHP WP_REST_Response::set_matched_route怎么用?PHP WP_REST_Response::set_matched_route使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Response
的用法示例。
在下文中一共展示了WP_REST_Response::set_matched_route方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rest_handle_options_request
/**
* Handles OPTIONS requests for the server.
*
* This is handled outside of the server code, as it doesn't obey normal route
* mapping.
*
* @since 4.4.0
*
* @param mixed $response Current response, either response or `null` to indicate pass-through.
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
* @param WP_REST_Request $request The request that was used to make current response.
* @return WP_REST_Response Modified response, either response or `null` to indicate pass-through.
*/
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());
if (!$match) {
continue;
}
$data = $handler->get_data_for_route($route, $endpoints, 'help');
$response->set_matched_route($route);
break;
}
$response->set_data($data);
return $response;
}