本文整理汇总了PHP中WP_REST_Server::get_routes方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Server::get_routes方法的具体用法?PHP WP_REST_Server::get_routes怎么用?PHP WP_REST_Server::get_routes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Server
的用法示例。
在下文中一共展示了WP_REST_Server::get_routes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_route_availability
/**
* Test if our route has been registerd correctly.
*
* Borrowed from the REST API.
*/
public function test_route_availability()
{
// Check the route was registered correctly.
$filtered_routes = $this->server->get_routes();
$this->assertArrayHasKey('/wp/v2/oembed', $filtered_routes);
$route = $filtered_routes['/wp/v2/oembed'];
$this->assertCount(1, $route);
$this->assertArrayHasKey('callback', $route[0]);
$this->assertArrayHasKey('methods', $route[0]);
$this->assertArrayHasKey('args', $route[0]);
}
示例2: test_endpoints
/**
* Test endpoint registration
*
* @since 0.2.0
*
* @group rest
* @group settings_rest
* @group group_rest
* @group tracking_rest
* @group session_rest
* @group variant_rest
*/
public function test_endpoints()
{
$the_route = $this->namespaced_route;
$routes = $this->server->get_routes();
foreach ($routes as $route => $route_config) {
if (0 === strpos($the_route, $route)) {
$this->assertTrue(is_array($route_config));
foreach ($route_config as $i => $endpoint) {
$this->assertArrayHasKey('callback', $endpoint, get_class($this));
$this->assertArrayHasKey(0, $endpoint['callback'], get_class($this));
$this->assertArrayHasKey(1, $endpoint['callback'], get_class($this));
$this->assertTrue(is_callable(array($endpoint['callback'][0], $endpoint['callback'][1])), get_class($this));
}
}
}
}
示例3: rest_send_allow_header
/**
* Sends the "Allow" header to state all methods that can be sent to the current route.
*
* @since 4.4.0
*
* @param WP_REST_Response $response Current response being served.
* @param WP_REST_Server $server ResponseHandler instance (usually WP_REST_Server).
* @param WP_REST_Request $request The request that was used to make current response.
* @return WP_REST_Response Response to be served, with "Allow" header if route has allowed methods.
*/
function rest_send_allow_header($response, $server, $request)
{
$matched_route = $response->get_matched_route();
if (!$matched_route) {
return $response;
}
$routes = $server->get_routes();
$allowed_methods = array();
// Get the allowed methods across the routes.
foreach ($routes[$matched_route] as $_handler) {
foreach ($_handler['methods'] as $handler_method => $value) {
if (!empty($_handler['permission_callback'])) {
$permission = call_user_func($_handler['permission_callback'], $request);
$allowed_methods[$handler_method] = true === $permission;
} else {
$allowed_methods[$handler_method] = true;
}
}
}
// Strip out all the methods that are not allowed (false values).
$allowed_methods = array_filter($allowed_methods);
if ($allowed_methods) {
$response->header('Allow', implode(', ', array_map('strtoupper', array_keys($allowed_methods))));
}
return $response;
}