I came across the news that Automattic1—the company behind WordPress, Jetpack, WooCommerce, Akismet, and Gravatar2—is ready to acquire Tumblr from Verizon3.
As is well known, Tumblr is a microblogging service and was particularly popular among young people during a certain period. Over time, its popularity declined as new alternatives emerged and Tumblr shut down support for adult content. It remains unclear what the outcome of Automattic’s acquisition process will be. It’s evident that Tumblr offers a different experience when compared to WordPress. I will continue to monitor these developments. On the other hand, this news also reminded me of my long-standing silence on writing about WordPress, and I decided to frame the content as a continuation of Headless CMS and prioritize the Headless WordPress articles, specifically focusing on WordPress APIs.
Below is a list of some articles I will frequently reference when discussing the use of the WordPress API. Reading these after this article will be beneficial.
- What is an API? What is it for?
- What is REST and SOAP API?
- Headless CMS
- REST and RESTful
- Beyond REST: GraphQL and Falcor
- Using JavaScript with HTTP Requests
First, there’s one topic I’d like to highlight. WordPress provides us with a wide range of APIs, and most of them are performing important functions within WordPress themes, plugins, and content management processes—often without users even being aware of their existence. For example, the Shortcode API4 offers essential functionality for handling WordPress shortcodes, while the Plugin API5 provides critical capabilities within plugin interactions (actions and filters). As for the REST API, I believe it promises a bright future by elevating WordPress’s capabilities to a higher level and enabling greater application diversity. Of course, the APIs I’ve mentioned are just the most prominent ones6. So, what else is on the list?
WordPress APIs
| Dashboard Widgets API | Metadata API | Shortcode API |
| Database API | Options API | Theme Modification API |
| HTTP API | Plugin API | Theme Customization API |
| REST API | Quicktags API | Transients API |
| File Header API | Rewrite API | Widgets API |
| Filesystem API | Settings API | XML-RPC WordPress API |
For the most up-to-date list, please refer to the WordPress APIs page, where you can click on each API link to view detailed usage information. I’d love to publish a separate article for each API listed here. Unfortunately, at this time—this is not feasible. Therefore, I’ll proceed with the HTTP API, REST API, and Plugin API based on the core functionalities they provide.
WordPress HTTP API
There are numerous functional ways to perform an HTTP request using PHP. WordPress’s HTTP API includes many functions designed for this purpose. However, it’s important to remember that web hosting servers may vary, and some servers may not support any of the required features, potentially leading to issues.
HTTP API, a standardization approach centered around a single, straightforward API that has been available since WordPress 2.7, and gained its full functionality with version 2.8. This object-oriented (object-oriented) API also includes helper functions that enable developers to leverage the API’s features.
For a long time, the HTTP API7 was featured as a separate section under the WordPress Codex. However, currently, developers must access functions individually under Developer Resources8.
Let’s first take a look at the helper functions:
- wp_remote_get() – Executes the GET HTTP method via the specified URL.
- wp_remote_post() – Executes the POST HTTP method via the specified URL.
- wp_remote_head() – Executes the HEAD HTTP method via the specified URL.
- wp_remote_request() – Supports executing various HTTP methods, starting with GET, via the specified URL.
The functions listed above return the WordPress WP_Error9 class in case of an error. The following functions, on the other hand, handle retrieving different parts of the response and perform a test for WP_Error during processing. These helper functions greatly simplify the use of the API and are the preferred methods for processing response objects.
- wp_remote_retrieve_body() – Retrieves only the body from the response.
- wp_remote_retrieve_header() – Retrieves only the relevant HTTP header portion from the response.
- wp_remote_retrieve_headers() – Returns all HTTP headers from the operation as an array.
- wp_remote_retrieve_response_code() – Returns the HTTP response value. This is typically 200. However, it may return values such as 4xx or 3xx in case of potential failure.
- wp_remote_retrieve_response_message() – Returns a response message based on the response code.
In the next post, I will publish a separate article on the HTTP API and demonstrate example operations using helper functions.
WordPress REST API
The WordPress REST API enables developers to interact with remote sites and retrieve and send JSON (JavaScript Object Notation) objects. It includes numerous API endpoints for various WordPress data types. Thanks to the WordPress REST API, developers can retrieve and update WordPress content from client-side JavaScript, external applications, or from programming languages other than PHP.
With the WordPress REST API, many exciting ideas and products can be developed using the WordPress structure. Headless CMS is one example, while on the other hand, Single-Page Applications (SPA / Single Page Application) also remains among the options. Additionally, it’s possible to provide a completely new admin experience for WordPress.
Finally, the WordPress REST API can serve as a more powerful alternative to the core’s admin-ajax API10. AJAX requests can be performed more simply using the REST API.
In the coming time, I will publish many articles and examples on the WordPress REST API. For now, let’s conclude this topic here. If you’d like to learn more details, please take a look at the relevant WordPress REST API11 page.
WordPress Plugin API
If you’re familiar with writing or modifying WordPress plugins, you’ve likely become aware of the WordPress Plugin API. Essentially, the Plugin API consists of a set of filters and actions, which can also be described as API “hooks.” Through these, additional plugins and/or themes can be integrated into the plugin execution process. Indeed, in my earlier article titled WordPress Hooks (Hooks): Filters and Actions, I provided basic explanations and shared example operations—please take a look.
WordPress appears to maintain its popularity as a popular blogging application and platform, both due to its monolithic structure and the other features it offers, and is expected to continue thriving for several more years. Particularly, thanks to its REST API, it has already begun to be integrated into different architectures such as Gatsby. I will strive to generate new ideas based on these features and demonstrate them with examples. Additionally, I will include related articles published in the future, again under separate headings, within this post.
Footnotes
- About Us. Automattic ↩
- About Us. Tumblr ↩
- Verizon to Sell Tumblr to WordPress.com Owner, August 12, 2019 ↩
- Shortcode API. WordPress Codex ↩
- Plugin API. WordPress Codex ↩
- WordPress APIs ↩
- HTTP API. Plugin Developer Handbook ↩
- WordPress Developer Resources ↩
- Code Reference. WordPress Developer Resources ↩
- AJAX in Plugins. WordPress Codex ↩
- REST API Handbook. WordPress Developer Resources ↩