Uses
Uses | Description |
---|---|
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::register_route() | Registers a route to the server. |
Registers a route to the server.
(string) (Required) Namespace.
(string) (Required) The REST route.
(array) (Required) Route arguments.
(bool) (Optional) Whether the route should be overridden if it already exists.
Default value: false
File: wp-includes/rest-api/class-wp-rest-server.php
public function register_route( $namespace, $route, $route_args, $override = false ) { if ( ! isset( $this->namespaces[ $namespace ] ) ) { $this->namespaces[ $namespace ] = array(); $this->register_route( $namespace, '/' . $namespace, array( array( 'methods' => self::READABLE, 'callback' => array( $this, 'get_namespace_index' ), 'args' => array( 'namespace' => array( 'default' => $namespace, ), 'context' => array( 'default' => 'view', ), ), ), ) ); } // Associative to avoid double-registration. $this->namespaces[ $namespace ][ $route ] = true; $route_args['namespace'] = $namespace; if ( $override || empty( $this->endpoints[ $route ] ) ) { $this->endpoints[ $route ] = $route_args; } else { $this->endpoints[ $route ] = array_merge( $this->endpoints[ $route ], $route_args ); } }
Version | Description |
---|---|
4.4.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_server/register_route