Skip to content

Instantly share code, notes, and snippets.

@krogsgard
Created February 11, 2015 22:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krogsgard/c3975a2ff449f20e56f3 to your computer and use it in GitHub Desktop.
Save krogsgard/c3975a2ff449f20e56f3 to your computer and use it in GitHub Desktop.
Thanks Rachel Baker for this :)
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(),
),
),
) );
@krogsgard
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment