Single Responsibility Principle and WP Classes

WordPress itself is not very object oriented – it has objects (like WP_User, for example), but most interactions with the core API take place through plain function calls. It also depends widely on global state, though it does a good job of managing this through the abstractions of actions and filters.

In my experience there is a sweet spot between sticking to vanilla WP function calls and building classes. Go too far towards OO and you’ll end up reimplementing things that are already quite convenient. This is almost certainly the road you’re heading down if you are instantiating a new class for post creation.

But if you’re really doing something else – an API interface, a complicated accounts system, payments etc – then your points of contact with WP will be minimal and you can be as SOLID as you like within the realm of the problem you’re dealing with.

Leave a Comment