For the last couple weeks, I’ve talked about creating database abstractions. In the first article, I spoke about the need for creating a high-level API, on top of standard WordPress APIs to act as a CRUD interface for your projects. The second was about using classes with all static methods for validation and storage of options. In part three, I want to talk about dependency injection and illustrate the value of this concept by offering a different way to create a database abstraction than I did before. What I showed in the last article works for its purpose. But, that […]
Using Static Methods & Late Static Bindings In Your Database Abstractions
In some cases, creating classes that produce objects for working with a specific item, like an order in an eCommerce store, are perfect. You create one class and instantiate a new object every time you need it. Conversely, some data, like a plugin’s options, really only need one “store.” This is a perfect use for a class with all of the static methods. In this article, I will show you how to build a database abstraction for options used in a plugin or theme and provide an example of when a class with all static methods is useful and explain late static […]
Why WordPress Projects Need A Proper Database Abstraction
A golden rule of WordPress development is “always use a WordPress API when possible.” We want to use classes and functions provided by WordPress to communicate with the database to ensure the right hooks are fired, and our code is as protected against changes made in future versions of WordPress. This also means we need to create a database abstraction on top of WordPress APIs. Doing so early on in a WordPress plugin, theme, or site will lead to less copy pasting and make it easier to fix changes later on. In this article, I’m going to talk about why […]
No Comments