Skip to content

Using PHP Standards in WordPress

Aug 2022·8:16·181 views·Matt Knighton

Walkthrough Overview

About This Video Guide

WordPress is the dominant CMS in 2022
It's a long lived platform
How can you make your plugins more maintainable?
How can you ensure what you are looking at today will work into the future for PHP?

Use PHP standards.

At MRK we have gone from various setups over the years to moving our code to standards.

Why we started using PSR standards

Our commercial plugins were using a pimple container that's not a standard
The CSS and Javascript made use of jquery and other libraries. Often messy.
These plugins have become hard to maintain and hard to fix bugs.
Lack of comments and clear structure in these plugins means its hard to work out why something is broken and work fast for adding necessary features.
A container class and overall code was confusing.

The results of the code:

Hard to maintain
Hard to add developers to the team
Hard to add new features without breaking code

Its was HARD

Answer is a better developer experience

Rewrite our commercial plugins with standards
Improve developer experience
Have proven design patterns
Have a documentation standard.

How do we do this?
Use PSR Standards
The PSR4 Autoloader
The PSR5 Documentation standard.
Composer for Libraries

Materials
https://torquemag.io/2018/01/dont-follow-wordpress-coding-standards/
https://www.smashingmagazine.com/2019/02/wordpress-modern-php/
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/
https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md
https://www.php-fig.org/psr/psr-4/
The WordPress Standard
The WordPress standard is a guideline for how to code your plugins.

WordPress was written for PHP 5

PHP 8.0 and higher is our current target for WordPress and Optimized Plugins

You can read more about this in these articles written by Josh Pollock and Leonardo Losoviz
Important Features of the WordPress Standard
Opening and Closing PHP Tags
No shorthand PHP Tags
Class Names should be separated by Underscores (Not PSR4 friendly)
Closures should not be used for Actions or Filters
What is a PSR?
PSR’s are a coding standard for PHP
They are not directly implemented by WordPress
A PSR allows libraries to be used together

Example PSR’s
Our most used PSRs at MRK WP are:
PSR-4 - The autoloader

Benefits :
Can load classes using composer.
Has namespaces.
Means you no longer need to require or include files in your directory structure.

PSR-5 - Documentations standard

Benefits :
Auto complete for docs in VS Code
Comments work with intellisense
Can be used to autocomplete documentation

PSR-5 is a draft standard
Outcomes
By using these standards we get a core style of code
Most of our plugins are easy to understand
Using these standards we get easier to maintain and longer life of code.

Core Focus Areas

  • 1Practical, production-tested techniques tailored for WordPress and modern tooling.
  • 2Stripping away fragile dependencies so your site stays fast and resilient.
  • 3Workflows structured so your internal team can maintain and own them long-term.

More Practical Walkthroughs

Explore step-by-step video tutorials and technical walkthroughs.

View all videos ↗
Using Gemini Nano Banana to Match a colour profile without degredation.
4:31
Apr 2026 · 38 views

Using Gemini Nano Banana to Match a colour profile without degredation.

4:31Watch Video
Fix ChatGPT Emoji not saving in WordPress
3:22
Mar 2025 · 510 views

Fix ChatGPT Emoji not saving in WordPress

3:22Watch Video
Have Multiple Sidebars in WordPress with Elements and Kadence Pro
8:27
Feb 2025 · 555 views

Have Multiple Sidebars in WordPress with Elements and Kadence Pro

8:27Watch Video

Let’s figure it out together

You don’t have to build alone.

A little guidance. A good conversation. A better next step.

Work with me

Start with a 20-minute call. I read every enquiry myself.