Learn Code, From My Code

I’m writing updated WordPress tutorials, and collecting the best resources for PHP and JavaScript development.

I’m writing updated WordPress tutorials, and collecting the best resources for PHP and JavaScript development.

Membership Benefits

  • Access To All eBooks
  • Request New Code Samples
  • Early Access To Content

Join Plugin Machine

Site Membership



Request new code samples

Get early access to content

New eBook

Refactoring WordPress Plugins

The PHP Parts

 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 WordPress env For Docker-Based Local Development

I have been using Docker Compose for local development for years now. While I am comfortable writing or debugging a docker-compose.yml file, if I can avoid doing so, I will. Luckily, the WordPress open-source platform has a zero-config tool for Docker-based local development that is built on top of Docker Compose. If you run this […]

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.

Members Only Tutorials

If you’re a member, you get access to completed and in-progress tutorials. Leave comments and ask for code examples.

Separating Concerns And Decoupling

In this final chapter of part 1, I will walk through a refactor in order to review all of the concepts covered in earlier chapters. I will discuss how I decided where to draw the lines between concerns and show how that guided my decisions around refactoring. In addition, I show how to use integration […]

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: The PHP Parts

The WordPress open-source project is now 20 years old. In that time, PHP and JavaScript have changed a lot. There is still some old code from back then running and it works. That’s great, but if you’re writing PHP and JavaScript for WordPress now, we can do better. Using dependency injection in PHP. In this […]