One of the great things about WordPress plugins is that it’s fairly easy to get started and build something functional without a ton of effort. However, once you get beyond a simple concept, have to maintain a growing codebase, or find yourself repeating similar steps, structure becomes essential. A recent discussion on Post Status and some nudging from Nate Wright convinced me to write a bit about my approach to building plugins. In most cases, I prefer to build standalone plugins that don’t rely on external libraries if possible due to the lack of dependency management in WordPress (projects where Composer is available is another story). I value simplicity and the ability to re-use code despite my tendency to over-engineer and abstract more than is always necessary. Autoloading Autoloading classes allows your code to be loaded automatically when it’s needed instead of having to litter your code with a bunch of calls to include() and require(). Basically, when PHP encounters a class it doesn’t know about, it runs through a list of registered autoloaders until it finds one that knows how to load it. An autoloader is just a callback function, similar to a WordPress filter, that takes
Share This