I write a fair amount about coding standards with WordPress and the importance that I believe they have for individuals, teams, and with working with the core application, that being WordPress itself.

Coding Standards with WordPress: The WordPress Coding Standards

In the last year or so, I’ve moved away from working primarily with the WordPress Coding Standards and have begun to use PHP Standard Recommendations for coding.

Coding Standards with WordPress: PSR

Note that I did not say I abandoned the WordPress Coding Standards nor that I elevate the PSR recommendations above them, but I have reasons for when I use each. And for anyone working with WordPress-based projects, I think it’s important to recognize when it’s appropriate to use each.

And that’s the purposes of this post.

Coding Standards with WordPress

Before I discuss each of the variants in coding standards, I want to be clear that nothing I’m saying should be taken as a hard and fast rule. At best, perhaps a rule of thumb. At worst, completely ignored, right? 🙃

Seriously, though, despite the usual efforts and talking points of making a case for one standard over the other, I hold the opinion that there’s a time and a place for when each should be used.

[restrict paid=”true”]

At the time of this writing, I’m working on two projects and one using the WordPress Coding Standards; the others are using the PSR.

Here’s the thing:

The decision isn’t about which set of coding standards are best. People do like to argue this point, and that’s fine for them. I don’t. Instead, I try to take the stance of being as pragmatic as possible.

And to do that, I try to use a set of questions for making the decisions on which coding standards to use

A Filter For Decision Making

Before I even get into talking about the two types of standards, it’s important to recognize that there’s a thought process – filter through which – you can run all of your ideas to make the most informed decision possible given your project.

I’ve done the best I can to capture the order of which I consider which set of standards to use and I’m sharing them here. In no particular order.

  • WordPress. Are you writing something that’s going to need to be compatible with as many WordPress installations (PHP versions not-withstanding)?
  • WordPress Are you working on maintaining a project that was written for an older version of PHP or what written using the WordPress Coding Standards?
  • WordPress. Have you inherited a project or are you maintaining a project that doesn’t have the budget to refactor the codebase?
  • WordPress or PSR. Are you working with a team that uses this as their primary set of coding standards?
  • PSR. Can you convince your client to use PHP7+?
  • PSR. Do you have full control over the environment in which the project is deployed?
  • PSR. Do you have a project that was previously written in an older version of PHP that has the budget for a newer server and refactoring?
  • PSR. Do you want to write to a codebase that will help bring your PHP skills into a more modern era while also bringing WordPress along with it?

And finally, one other question I’d ask is this:

What coding standards do you have on your system, how easy is it to configure your IDE? Let the time to set it up and answers to the above question guide which set of standards you use.

Ultimately, the goal is to make it as easy as possible to determine which standard to use.


A Final Post?

Before wrapping up this series, I want to provide a list of additional resources that I believe are useful for those who are working with WordPress in some capacity.

Maybe you’re ane experienced developer, maybe you’re just getting standard, or maybe you’re somewhere in between.

Regardless, there’s something for all of us, and if I can share as much information as possible to help you become a better independent WordPress development, then I’ll be achieving a portion of the aim that I’ve set out with this particular series.

For now, though, give some thought to the outline of the coding standards above and see if it doesn’t help with managing some of your existing projects.

A Note About Object-Oriented Programming

Note also that earlier this week, I began – or resumed, depending on how long you’ve been reading this material – on object-oriented programming in WordPress. So if you’re interested in jumping into that as well, then you can start with this post (as it also references some of the others, too).