Adding custom routes to WordPress REST API

In the second version of REST API, there is a new function called register_rest_route() that deserves our attention. It lets you add a route to REST API and then further pass it to an array of endpoints. For each endpoint provided, a defined value for each field will be given in our query, including defaults, validation and callbacks, sanitation, and separate permissions callback.

The focus will be put on the following three main key points:

  • Callback
  • Field arguments
  • Permissions check

They will provide us with an idea on how the architectural side of the API functions. It is important to note that you will know that your requests are authorized, and your fields sanitized, and everything is in place once we ...

Get Learning WordPress REST API now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.