WordPress REST API

What is the WordPress REST API?

If you’ve been following the ins and outs of WordPress core development for the last couple of years you may have heard talk of the WP API or the WordPress JSON rest API or JSON API or something similar. The WordPress REST API is a RESTful API that can be accessed simply through HTTP requests to access the data on a WordPress site in JSON format.

In plain English – the WordPress API is a new way of accessing the data WordPress provides without having to go through a theme, or a RSS feed, or XML-RPC. And accessing doesn’t just mean getting the data to read. With the WP API you’ll be able to create, read, update, and delete content in the WordPress database without interacting with WordPress directly.

Up until now if you wanted to read a WordPress post or page you had to use a WordPress query in PHP typically through a WordPress theme. The theme would use the WordPress templating engine and hierarchy, otherwise known as a theme, to output the post or page or other content you requested through the address bar on your browser. This set up had some severe limitations. If for example, you wanted the content from your WordPress site to appear in a mobile app you would have to either build a custom PHP application to do it or pass the data through antiquated protocols.

With the WP API we can bypass this entire process. Getting the data from a WordPress site using the API is as simple as submitting a standard HTTP request or URL. Once you have that data you can use any application or programming language to do whatever you want with it. So, you can build WordPress sites using PHP or you can build them using JavaScript or Ruby or Objective-C or whatever you want. The WP API gives you direct access to the data and allows us to do whatever we want with it.

The WP API also allows you to access and edit the data in the database without going through WordPress Admin. (This is only possible if you have the right security credentials so your data is not at risk.) But it means you can now build new interfaces for creating content with WordPress.

For more information you can go to the WordPress REST API page on WordPress.com. You can also find out how to interact with the rest API by going to: v2.wp-api.org The API project is hosted on GitHub: github.com/WP-API /WP-API

customizer theme setting guidelines

On the 22nd of April 2015, Justin Tadlock announced on WordPress.org that:

Themes are now required to utilize the Customizer API if the theme has custom theme settings. This means no custom settings screens.

The decision was ultimately made on two fronts (so we are told):

  • Having a consistent experience for users
  • Standardizing the theme review process

As can be seen from the comments on his post this is quite a controversial decision.  One of the issues seems to be that many developers will have to rewrite their themes to remove their theme options page. This is because the statement from Justin says:

Then, 6 months from yesterday, all existing themes submitted to the repository [WordPress.org] fall under this guideline. So, mark your calendars for October 21, 2015

The other issue from reading the comments is that there seems to be a feeling the the Customizer doesn’t have the controls and screen space to be able to provide and decent user interface to the user. It seems like the options will be squashed up against the left hand side and the right hand side of the screen will be used to display the current website page. This is because the “best” feature of the Customizer is that the screen automatically applies the changes made in real time (using JavaScript) without having to save the settings. In this way the user can see if they like the changes they have selected or not.

It will be interesting to see hows this all works out.