本文整理汇总了PHP中WP_REST_Server::register_route方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Server::register_route方法的具体用法?PHP WP_REST_Server::register_route怎么用?PHP WP_REST_Server::register_route使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Server
的用法示例。
在下文中一共展示了WP_REST_Server::register_route方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_get_namespaces
public function test_get_namespaces()
{
$server = new WP_REST_Server();
$server->register_route('test/example', '/test/example/some-route', array(array('methods' => WP_REST_Server::READABLE, 'callback' => '__return_true')));
$server->register_route('test/another', '/test/another/route', array(array('methods' => WP_REST_Server::READABLE, 'callback' => '__return_false')));
$namespaces = $server->get_namespaces();
$this->assertContains('test/example', $namespaces);
$this->assertContains('test/another', $namespaces);
}
示例2: register_route
/**
* Override the register_route method so we can re-register routes internally if needed.
*
* @param string $namespace Namespace.
* @param string $route The REST route.
* @param array $route_args Route arguments.
* @param bool $override Optional. Whether the route should be overridden if it already exists.
* Default false. Also set $GLOBALS['wp_rest_server']->override_by_default = true
* to set overrides when you don't have access to the caller context.
*/
public function register_route($namespace, $route, $route_args, $override = false)
{
parent::register_route($namespace, $route, $route_args, $override || $this->override_by_default);
}