In the previous sections of this series, we have looked at reasons you should build a custom database API, we have discussed how to structure your data, and we have looked at how to create the database tables. Now it is time to build the basic API that we will use to actually interact with our database. This will involve writing an API class with all of the necessary methods for retrieving, inserting, updating, and deleting data.
Black Friday & Cyber Monday sale, save 30%! Valid until November 30th at 11:59:59 PM (UTC - 6). Enter BFCM2015 at checkout or Click here to apply discount →
I love side projects. They are what wake me up at night with excitement; they are what causes light bulbs to flash on inside my brain while walking my dog; they are what motivate me when all other motivation is lost; they are the distraction from my worries; they are a fundamental part of who I am as a developer; and they are an integral part to the success of so many of this world’s greatest developers and business owners.
Several years ago, I wrote a tutorial on how to create custom registration and log in forms. That tutorial was shortly after transformed into a complete plugin that has been sold on this site since. It was a fun and popular plugin but over the last few years it was lost focus from me, primarily due to the growth of my other projects. Today I’m thrilled to announce the plugin has a new owner that will keep it updated and breath new life into it.
Since early child hood, I have always been a do-it-myself individual. It is an attitude I attribute largely to the way my father raised me and my brother. The three of us were always working around the farm making repairs and handling new construction. We did our own plumbing, electrical work, mowing, cleaning, car maintenance, and everything else. My family was reasonably well off financially so we could have hired plumbers, electricians, mechanics, etc, if something needed built or repaired, but that just was not in our nature.
When starting out with building an API for your custom tables, one of the very first things you need to do is determine what data you need to store in your tables, and what format that data will be stored in. This is a fundamental aspect of creating your API as it is one of the defining factors for how your tables are structured.
The WordPress database class and the other various APIs available make it pretty easy to interact with the WordPress database but often times you need to go a step further and create a custom API specific to your plugin’s database tables. Large plugins especially can benefit from having a custom database API as it standardizes common tasks, making them more reliable, more repeatable, and simpler to debug.
A club membership store is one that requires customers to pay a membership fee in order to purchase (or access for free) the products available in the catalogue. A common examples of this types of store would be a WordPress theme shop that grants access to all available themes with the purchase of a membership.
When it comes to handling large amounts of data, there is really only one way to reliably do it: batch processing. The concept of batch processing is simple. Instead of performing one large query and then parsing / formatting the data as a single process, you do it in batches, one small piece at a time. If you have ever attempted to query or export a large amount of data and had your server timeout, you’ll easily understand just how beneficial batch processing is.
WordPress includes an exceptionally useful API called the HTTP API that can be used for sending data to and retrieving data from remote APIs. If you are building a plugin that talks to Stripe, MailChimp, or just about any other service that provides an API, you can use the WP HTTP API to make your job significantly easier. For this tutorial, I’m going to show you how to use wp_remote_get(), one of the several functions included in the HTTP API, to retrieve and parse JSON data from a remote API.