- Access To All eBooks
- Request New Code Samples
- Early Access To Content
Join Plugin Machine
Request new code samples
Get early access to content
Refactoring WordPress Plugins
Part 1: PHP
For experienced WordPress developers who are looking to improve the PHP in their plugins, use new modern best practices and adopt test-driven development.
Latest From The Blog
Read my WordPress plugins, and learn how they work with first-party APIs — Laravel and NodeJS applications I develop — and third-party APIs.
Using The useEffect React Hook In WordPress
This post explains how to use the useEffect hook in WordPress.
Creating Reusable React Hooks For The WordPress Block Editor or Whatever
The new React documentation site is live and looks great. This section on creating custom hooks to encapsulate logic that needs to be used in multiple places in a React application is quite good. This is an important strategy to learn, and can help a lot when developing multiple blocks for a WordPress site. In […]
How To Use WordPress Data Package To Get The Current Post Being Edited In The Post Editor
How to use the WordPress data module to get the current state of the post being editted in the WordPress block editor.
How To Insert Blocks In WordPress Block Editor
Members Only Tutorials
If you’re a member, you get access to completed and in-progress tutorials. Leave comments and ask for code examples.
Testing WordPress Hooks
Testing WordPress hooks is always a challenge. Using depenency injection helps. This section covers how to structure hooks and callback functions and how to write unit and integration tests for them.
Using “Action” Classes In WordPress Plugins To Encapsulate Logic
How to refactor WordPress plugins to make the code more reusable and easier to test using action classes. Also, how to test WordPress plugins that make HTTP requests to third-party APIs using phpunit.
Refactoring A Class To Make It Reusable Using Dependency Injection
A walk through of how to refactor a PHP class that works and does one thing in order to make it reusable. This is achived with dependency injection and hooks.
Refactoring A WordPress Plugin To Use A Container
WordPress plugins used to use one big class, which was a singleton, and exposed instances of all of the plugin’s classes. This worked, but singletons have a lot of downsides. It was the best solution in PHP 5.2, which we used to have to support. In the previous section, I wrote about singletons and their […]
Singletons & Dependency Injection In WordPress
Singletons used to be very common in WordPress plugins. It used to be that singletons were the only way, besides global variables to have a globally available instance of a class in a WordPress plugin. This section covers why Singletons are not great and when it’s not a big deal. It will cover some ways to refactor plugins so they don’t have singletons.
eBook: Refactoring WordPress Plugins Part 1