当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_REST_Server::get_routes方法代码示例

本文整理汇总了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]);
 }
开发者ID:noplanman,项目名称:oEmbed-API,代码行数:16,代码来源:test-wp-rest-oembed-controller.php

示例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));
             }
         }
     }
 }
开发者ID:Ramoonus,项目名称:ingot,代码行数:28,代码来源:rest-test-case.php

示例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;
}
开发者ID:023yangbo,项目名称:WordPress,代码行数:36,代码来源:rest-api.php


注:本文中的WP_REST_Server::get_routes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。