register_route() публичный Метод

Registers a route to the server.
С версии: 4.4.0
public register_route ( string $namespace, string $route, array $route_args, boolean $override = false )
$namespace string Namespace.
$route string The REST route.
$route_args array Route arguments.
$override boolean Optional. Whether the route should be overridden if it already exists. Default false.
 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);
 }
 /**
  * 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);
 }