-
-
Save krogsgard/c3975a2ff449f20e56f3 to your computer and use it in GitHub Desktop.
Thanks Rachel Baker for this :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
register_json_route( 'wp', '/comments/(?P<id>[\d]+)', array( | |
array( | |
'methods' => WP_JSON_Server::READABLE, | |
'callback' => array( $controller, 'get_item' ), | |
'args' => array( | |
'context' => array( | |
'default' => 'view', | |
), | |
), | |
), | |
array( | |
'methods' => WP_JSON_Server::EDITABLE, | |
'callback' => array( $controller, 'update_item' ), | |
'args' => array( | |
'post_id' => array(), | |
'status' => array(), | |
'content' => array(), | |
'author' => array(), | |
'author_email' => array(), | |
'author_url' => array(), | |
'date' => array(), | |
), | |
), | |
array( | |
'methods' => WP_JSON_Server::DELETABLE, | |
'callback' => array( $controller, 'delete_item' ), | |
'args' => array( | |
'force' => array(), | |
), | |
), | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a WordPress endpoint, but plugins and themes can register their own, replacing "wp" (which is reserved for core) with something like "plugin/events/v1". And then of course custom arguments for the endpoint.
Also from the team's notes:
Apart from the core routes, routes should be prefixed to avoid overlapping between plugins. The version should be included with the namespace to create a route prefix. The easiest way of achieving this is to require both a namespace and version when defining the routes.