Years ago, I created the WordPress Widget Boilerplate aiming to be the following:
An organized, maintainable boilerplate for building widgets using WordPress best practices.
Since then, not much has changed regarding the Widgets API (which we’ll look at later in this post), but what I consider to be “best practices” has changed. Further, the degree to which I think this API is a solid example of introductory object-oriented programming in WordPress is high.
It’s not because it uses a lot of object-oriented principles, it’s not because it uses modern standards (at least as far as modern PHP is concerned), but because it does use a few things that help us to recognize a few, say, signals regarding object-oriented programming in WordPress.
And this is something that shouldn’t be understated: If you’re looking for examples of object-oriented programming in WordPress, look for APIs that employ it.
Further, if you’re looking for ways to gauge you’re own level of evaluating a piece of code (let alone a code base) for the use of classes and some of the more advanced features of OOP, then why not have some sort of a litmus test to see how you’re doing?
And the Widgets API does just that.
WordPress Widgets: An Introduction
So in a smaller series than my last, I’m aiming to look at the Widgets API and to do a few things:
- show you the basic skeleton of a widget and why it’s object-oriented,
- discuss what things you should be able to notice and why,
- update the Widget Boilerplate directly on this site first and then push it out to GitHub,
- build a widget using the API with the boilerplate as the foundation for our work.
And in this post, we’re going to start with the first point above.
Before going into this post, I recommend reading the following posts:
- Two Pillars of Object-Oriented Programming: Part 1 of 2
- Two Pillars of Object-Oriented Programming: Part 2 of 2
- Abstract Classes, Part 1 – Abstracting Behavior
- Abstract Classes, Part 2 – Abstract Classes and Interfaces
Once done (or if you feel you already have a grasp on the topics), then we’re ready to go.
In the next post in this series, we’re going to look at the object-oriented nature of the Widgets API and what things you should be able to detect immediately by reading the code.
This is because it’s important to recognize certain object-oriented principles in practice and this is a good way to gauge if you’re able to do that or not. If you are, great! Then it’ll continue to help develop that muscle. If not, no worries – it still helps you develop that muscle.
And it will serve you well as we continue to get move more and more into object-oriented WordPress development through practical means.
The necessary theory has been covered. So let’s get started on actually putting it into practice.