And for anyone who has read Coding Horror within the last decade or so, you’re likely familiar with Atwood’s Law:
But it’s been four years since that post was originally written and, in that time, a lot can change in terms of how we write code.
Four years is roughly an Internet Age, isn’t it?
Anyway, the basic points of that article still stand, but if you’re working on a variety of projects and some of them require different configurations, settings, and standards, then the way you go about installing and configuring PHP CodeSniffer may be different than how you configure it on a system-level.
So if you’re in that position, here’s how you can configure PHP CodeSniffer on a per project basis using Visual Studio Code.
One of the more challenging aspects of working with WordPress is working the fragmented nature of documentation. And I don’t necessarily mean the Codex nor do I mean the Developer Resources.
But I mean the fact that there’s a ton of information spread across blogs (mine not exempt), subreddits, questions and answers on Stack Exchange, and shares via Twitter, and so on.
I’m not making a case that this is inherently bad or good but I am making the case that when given the opportunity to provide a central repository of information for a feature, set of APIs, or tools that it can be extremely helpful especially if it’s written an maintained by the author of something like one of the aforementioned issues.
Remember that WordPress uses the event-driven design pattern and although we often refer to actions and filters, the concept comes down to hooks. The flow of control through the program goes something like this:
Execute the program,
Whenever the program comes upon a hook (in WordPress, we’ll see do_action or apply_filters), iterate through all of the registered hooks,
Return control back to the program,
Execute until the end.
This isn’t completely different from the Publisher/Subscriber Pattern (or PubSub, for short) but there’s a key difference: The Event-Driven Pattern simply signals that something has happened and if there are hooks, they will fire. The PubSub Pattern will tell a registered subscriber to do something.
Anyway, back to hooks in WordPress. Keeping the two concepts of hooks that we have may be most easily done by thinking of them like this:
Actions are for doing something,
Filters are for processing data.
If you’re looking to approach WordPress development in an object-oriented fashion, tightly coupling your code to WordPress core by registering your classes via hooks to the core application is not a good idea.
In other words, don’t register your business logic with WordPress. Keep them separate. Here’s a litmus test for if your work is tightly coupled with WordPress: If you can’t run a unit test against your class without loading WordPress, it’s tightly coupled.