There is a good reason for the legacy code in WordPress: it is backward compatible with over a decade of third-party extensions. Plus, old code does not necessarily equate to bad code. If it ain’t broke — well, you know how the rest goes.
Last year, WordPress bumped the minimum requirement for running the software to PHP 5.6 or newer. Many developers cheered in support of features such as short array syntax, namespacing, and the spread operator. Others wanted to jump to PHP 7+, but PHP 5.6 was a good stepping stone to more modern PHP code.
This change opened some new questions. When will core WordPress begin using new features? What coding standards should the project follow?
WordPress 5.3 made use of the new spread operator, which cleaned up and simplified several functions. It showed a willingness of the core leads to update some outdated code while avoiding backward-compatible issues.
An Updated Set of Standards
To begin using modern PHP features in WordPress, the platform’s coding standards must evolve. On March 20, Juliette Reinders Folmer proposed an extensive set of guidelines. The proposal is a draft and will need to be fine-tuned based on feedback from developers and core contributors.
“While it may still be a while before some of these features will actually be adopted for use in WordPress Core,” wrote Folmer, “defining the coding standards in advance will allow for a consistent code base when they do get adopted and will allow for plugins and themes, which are not necessarily bound to the PHP 5.6 minimum, to safeguard their code consistency when they start using more modern PHP already.”
The proposed standards are broken down into the following topics:
- Namespace declarations
- Traits and interfaces
- Type declarations
- Declare statements / strict typing
- Additional new rules covering various items
Any code that goes directly into WordPress must follow the project’s coding standards. It is strongly recommended that plugin and theme developers adopt the same standards, but it is not a requirement for inclusion in the official plugin and theme directories. Coding standards across an ecosystem make it easier for one developer to pick up code from other developers without having to learn unique styles between extensions.
On the whole, the update look solid. There is a lot to like about this proposal, and it would
This article was written by Justin Tadlock and originally published on WordPress Tavern.