Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 18 of 219)

Articles, tips, and resources for WordPress-based development.

Awesome WP-CLI: A First-Rate Starting Place

One of the more challenging aspects of working with WordPress is working the fragmented nature of documentation. And I don’t necessarily mean the Codex nor do I mean the Developer Resources.

But I mean the fact that there’s a ton of information spread across blogs (mine not exempt), subreddits, questions and answers on Stack Exchange, and shares via Twitter, and so on.

I’m not making a case that this is inherently bad or good but I am making the case that when given the opportunity to provide a central repository of information for a feature, set of APIs, or tools that it can be extremely helpful especially if it’s written an maintained by the author of something like one of the aforementioned issues.

Case in point: WP-CLI and Alain Schlesser.

Continue reading

De-coupling Domain Logic in WordPress

Remember that WordPress uses the event-driven design pattern and although we often refer to actions and filters, the concept comes down to hooks. The flow of control through the program goes something like this:

  1. Execute the program,
  2. Whenever the program comes upon a hook (in WordPress, we’ll see do_action or apply_filters), iterate through all of the registered hooks,
  3. Return control back to the program,
  4. Execute until the end.

This isn’t completely different from the Publisher/Subscriber Pattern (or PubSub, for short) but there’s a key difference: The Event-Driven Pattern simply signals that something has happened and if there are hooks, they will fire. The PubSub Pattern will tell a registered subscriber to do something.

Anyway, back to hooks in WordPress. Keeping the two concepts of hooks that we have may be most easily done by thinking of them like this:

  • Actions are for doing something,
  • Filters are for processing data.

If you’re looking to approach WordPress development in an object-oriented fashion, tightly coupling your code to WordPress core by registering your classes via hooks to the core application is not a good idea.

In other words, don’t register your business logic with WordPress. Keep them separate. Here’s a litmus test for if your work is tightly coupled with WordPress: If you can’t run a unit test against your class without loading WordPress, it’s tightly coupled.

So what’s the solution? Delegation.

Continue reading

On Functions and Must-Use Plugins

I’ve been working on a small project, more of a web application than a site, that’s required the development of both a custom-theme and tightly coupled, but very specific functionality.

This is a very narrowly focused project (about which I’ll likely talk about at some point in the future) but in working on it, it’s forced me to get back into the theme development aspect of WordPress development a little bit.

No, I’m not doing any design – thankfully – but I am having to work on theme customizations from a functional perspective. In doing this, though, it’s had me revisit the required functions.php and some considerations I’ve never had before.

Furthermore, it’s caused me to look more deeply at the use of mu-plugins and ask when they are necessary and why I haven’t used them more in the past (or even when one would truly need to use them).

So I’m going to wax poetic about that a bit.

TL;DR
Functionality tied directly to the theme and WordPress core goes into functions.php. Domain-logic that required by the entire solution to work goes in a must-use plugin.
Continue reading

Deactivating WordPress Plugins with SQL

If you inherit a WordPress codebase, regardless of the age of the project, there may be a lot of context that you don’t have as to why certain decisions were made or how things were implemented.

This may include the server, infrastructure used to help power the site or the app, and other contextual information about the environment in which it was running.

This type of information can be server-related information, PHP version, database type, information that’s actually stored in the database especially if you do a database import, and so on.

This image has an empty alt attribute; its file name is table-plus.png

Ideally, all of this is handed over but that’s not always the case. Anyway, say you attempt to start it up and then when you attempt to start up the application, not only does it not work but it either shows a white screen or displays a message about technical problems with your installation.

Continue reading

How To Fix the Referenced PHPCompatibility Sniff Error

There are a lot of nice packages that we can use in our PHP-based projects and if you’re using Composer or GrumPHP, PHPCompatibility is one that I recommend including your projects especially if you’re writing code for something that’s going to run across multiple versions of PHP (that is, on hosts that offer different versions).

This is a set of sniffs for PHP CodeSniffer that checks for PHP cross-version compatibility. It will allow you to analyse your code for compatibility with higher and lower versions of PHP.

PHPCompatibility Repository

This is something that be installed within composer and it’s something that I recommend for people writing code for WordPress because of how much variation exists within our hosts.

Occasionally, though, you may see a problem like this:

And if you run $ phpcs -i you may get a message that’s unclear.

Continue reading
« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑