Client Work: The TOFU Plugin

Some WordPress projects only need the tiniest of tweaks to finish. Some things you’ve probably heard from clients:

  • “Can you change this plugin I installed to do $something_slightly_different?
  • “I’d like to get more/different information from $third_party_api
  • “Can we add a new content area to my theme?”


Why are you sad, programmer?

Because the fix might be a few lines of code, but finding where to fix it can take 10x longer than the code itself. You like to get things done efficiently.

For quick fixes, it’s tempting to make changes directly in existing plugins or themes. FTP in, open wp-content/plugins/$plugin_name.php, drop in a few lines, and send an invoice, ’cause you’re saddling up for the next project, cowboy!

But what happens when the client updates their plugins or themes? Or what if you get a call from the client a month later: Can they get one more tweak?

Sure – but you’re back where you started. More detective work. More re-orientation.

There must be a better way

I used to make this mistake; especially when I was less familiar with WordPress. Then, I tried a new way of handling tiny changes: The tiny, one-file update (TOFU) plugin.

When I start work on a small change, the first thing I do is drop in a new plugin: /plugins/site-name-tweaks/tofu.php

Then, I make all of my changes in that plugin – even if they’re unrelated tweaks that don’t particularly go together.

This has some obvious benefits:

  • All changes are in one place for easy reference
  • The changes can be deactivated if they’re causing issues
  • Other plugins and themes can be updated without fear

Let’s walk through an example I recently dealt with. Maybe parts of it will sound familiar to you!

Just a few small things, please!

A client was using Memberful to sell subscriptions to their content. They needed three things tweaked that the existing plugin didn’t handle:

  1. They still had members paying in PayPal (outside of Memberful) so they needed a way to cancel members when they cancelled via PayPal.
  2. They needed to display a welcome message after someone signed up.
  3. They needed to update 3rd-party software with information on members when they placed orders.

TOFU in action

First, I fought the urge to open up the Memberful WordPress plugin and make my changes there. How easy it would have been (especially for item #3)! But I knew better. I avoided the temptation.

Yes, the first thing I did was create a new TOFU plugin client-memberful-tweaks. I wrote the code for #1 and #2 pretty easily, but #3 (update a 3rd-party when members changed) was tricky. There was a place in the Memberful plugin where I needed to hook – but there was no do_action available!

No do_action? No problem! I added it myself.

This would work. If the Memberful plugin is updated, my code won’t execute, but all I need to do is hook back into the updated version.

However, I took TOFU one step further: I looked at the code above my hook, where // Memberful doing stuff was, and I realized I could easily replicate it. I extracted (a.k.a. copy/pasted) the Memberful code, removed my hook, and moved it all to a new function in my TOFU plugin:

Now my code is safe from future updates to Memberful and is all self-contained in a single plugin.

When TOFU makes sense

The TOFU plugin works primarily for small changes touching one or two points in the existing site’s code.

It’s particularly useful for non-critical changes: connecting to 3rd-party services, backend tasks, and other non-user-facing changes. Things that can survive plugin updates without crippling the site.

For example: If my client’s visitors aren’t given a welcome message, no biggie. We can fix it, in time.

When TOFU doesn’t make sense

This won’t work well for user-facing or big, substantial changes. A concrete example: If you’re using a TOFU plugin to add a login form to the theme, and that login form is the only way for users to sign in, then it needs to be update-proof. Otherwise, expect an angry call from the client after they run ‘update theme’.

In these cases, you’re going to need to take control over your client’s codebase: restricting updates, checking the whole site into version control, etc.

Also, if you’re making lots of changes to a theme’s HTML structure, you’re better off using a child theme or “locking down” their existing theme to prevent updates overwriting your changes.

Try it yourself

The next time you need to make a small change to a WordPress site, try the TOFU methodology instead of making changes to existing code. It’s a smidge more work to extract your code cleanly (vs. making changes right where you need it), but it pays dividends when you need to return to your changes.

Have you tried something similar for small changes? Have any suggestions or improvements? I’m all ears!

Freelancer? Me too!

Join my newsletter and I'll send you some emails about the business of freelancing and software, for free.

I won't send you spam. Unsubscribe at any time. Powered by ConvertKit

Leave a Reply

Close Menu