This week: Full Site Editing, the power of Block Patterns, working in XWP, DevRel, and much more.
A decade ago, Leon created the WP2Static plugin to solve the security and performance issues inherent with a dynamic web app like WordPress.
This experience led to recruitment into the expert team at Strattic, leaders in the WordPress static publishing space.
WordPress developers aren’t famous for their code quality and we’re all paying for it!
The extensibility of WordPress and low barrier of entry for developers to build with it have led to the mass adoption we see today. What we don’t see when we visit a typical WordPress site, is the low quality code in some of the 50+ installed plugins or the site’s theme. We don’t see it, but we can often feel it in slow loading or buggy pages. The site owner may feel it in their wallet, paying for more powerful servers to run their increasingly bloated sites.
It is thus, up to us, as WordPress developers, to adopt code quality measures in our plugins and themes. Not only for the great performance and security benefits it provides our users, but by also catching bugs early in development. This gives us confidence that our software behaves as we expect. So, we’ll have less support requests, more sales and a better night’s sleep!
PHP Code Sniffer can be run manually, in a build process or automatically within your code editor to alert you of coding standard violations. There are a bunch of popular coding standard rulesets defined which you can choose to adhere to, such as the official WordPress Coding Standards. I prefer the standard in Viktor’s PSR 12 Neutron Hybrid Ruleset.
Where PHPCS analyses each file individually, for obvious syntactical issues, PHPStan goes much deeper. PHPStan will load your classes and report things like namespace violations, trying to call functions with incorrect arguments and many more useful tests. PHPStan can be run with varying levels of strictness. While I started with something midway, I almost immediately set it to the strictest checking – I mean, who wants OK quality when you can have great quality, amirite? PHPStan will look at your PHPDocs to see what a function’s argument type is, then alert you if anywhere in your code, you could possibly call it with an unsupported type of variable. This is so powerful and can shut down a whole range of bugs and security issues before they have a chance to do damage!
PHPUnit is a unit testing framework, which, like many others, derives structure and behaviour from the Smalltalk languages’s SUnit framework (TIL!). Unlike PHPCS and PHPStan, you can’t just install it, set some config options and immediately benefit from it telling you all the coding mistakes you’ve made. With PHPUnit, you’ll need to write your own tests. Yeah, so the least appealing to the lazy developer in us!
Once you get started with unit testing though, you won’t want to write code without it. Or you will, then curse yourself when a bug is reported that you know you could have avoided, had you written unit tests!
Stéphane Boisvert lists ten reasons why working at XWP is worthwhile. His article could also serve as a benchmark for other companies as everyone would prefer to work in one that lives up to these expectations.