Software Engineering in WordPress, PHP, and Backend Development

Author: Tom (Page 24 of 426)

Writing Helper Functions in Procedural Programming in WordPress

TL;DR: Here’s how you can write domain-specific, testable helper functions in procedural programming in WordPress.


If you decide to use procedural code when writing plugins or extensions for WordPress, this doesn’t mean that everything has to be in a monolithic function. That is, it’s still possible – and a good idea – keep domain-specific work contained within its own function.

So even if you’re using a weird mix of namespaces and autoloading along with procedural programming, you can still take advantage of functions that do one thing and one thing well to help keep the code a bit cleaner. I will say, though, this is where docblocks come in handy.

In this article, I’ll share an example of how to simultaneously using procedural programming, anonymous functions, and utility functions (or helper functions) to make sure that you’re writing code that’s well-documented and easy to follow.

Continue reading

Install Ray Per Project at an Application Level

TL;DR: Here’s an easy way to incorporate Ray into all of your WordPress projects without needing to add use at the top of your project files. Thanks to my friend Aubrey for sharing this.


You know about Ray, right? I’ve talked about it twice already:

  1. Debugging WordPress with Ray, Part 1
  2. Debugging WordPress with Ray, Part 2

If you’ve been using Ray in your WordPress projects and have been including it in your composer.json file, then you’ve likely set up the top of your files like this:

use WP_Post;
use WP_Term;
use Spatie\Ray;

defined('WPINC') || die;
require_once __DIR__ . '/vendor/autoload.php';

Notice that the namespace for Ray is included in this. But if this is a utility meant for printing out error messages for debugging purposes, much like we’re used to seeing with Xdebug, then why would we include it in every file? That is, why would we include a use statement for a dependency that’s not sent to production?

We don’t have to do so.

Continue reading

Don’t Forget Procedural Programming in WordPress

TL;DR: As much as I like using object-oriented programming for writing code, it’s not the only way to write code. The same goes for WordPress-centric code, too. When writing solutions for WordPress, don’t set out to write everything in an object-oriented way. Don’t forget procedural programming in WordPress.


For the last few months, I’ve been writing a handful of small utility plugins (for lack of a better word) for WordPress. These are things that are designed to do at least one of the following:

  • add a feature that I wish exists but doesn’t,
  • improve functionality of the administration area to make achieving a given task easier,
  • introduce functionality that’s easier for a sites that have a large database of users,
  • and more.

As someone who’s historically been one to go on and on about why we should be using object-oriented programming, I’ve not been doing much of that in these plugins.

Instead, I’ve been using some features of PHP, like namespaces and autoloading, to keep the code running in its own area to prevent potential conflicts with other plugins. I’ve also been using PSR12 with procedural programming.

For as much as I’ve written about object-oriented programming, I don’t think I’ve written enough (and I certainly won’t do so in a single post 🙂) about procedural programming.

But that doesn’t mean now isn’t as good as time as any.

Continue reading

Installing, Configuring, and Setting Up Xdebug in Visual Studio Code

TL;DR: This is everything that needs to be done to install Xdebug with a Homebrew-based environment and to work with the software within Visual Studio Code.


Though I’ve recently become a fan of using Ray (1, 2) for much of my lightweight debugging, this doesn’t mean I don’t think it’s important to have Xdebug installed and configured in Visual Studio Code.

If you follow the steps I’ve outlined starting in the previous post, it’s relatively easy though it still requires a little bit of manual work to get started.

This is how you can set up Xdebug with a Homebrew-based configuration and Visual Studio Code.

Continue reading

Installing PHP 7.4 and PHP Monitor for WordPress Development

TL;DR: How to uninstall PHP 8.1, install PHP 7.4, why you should do so, and one extra utility to helps manage PHP packages and modules.


When I wrote about how to fix WordPress, PHP, MariaDB, and Homebrew, I didn’t cover some of the other larger issues that I experienced when working backwards into the solution.

I need to give Ihor a hat tip here because he and I spoke about this more on Twitter regarding the relationship between WordPress, PHP 7.4, 8.0, and 8.1.

I’d be remiss if I didn’t clarify the following:

  1. I was running PHP 8.1.
  2. WordPress is not compatible with PHP 8.1
  3. WordPress is [allegedly] compatible with PHP 8.0 but I’ve not tested it or my tools against this version because I wanted to have full compatibility.
  4. I downgraded my system to PHP 7.4.27 until I get my entire set up configured as I like. Then I’ll start upgrading components.

So if you’ve followed the aforementioned post, here’s a more complete set of things I’ve set up to make sure everything is working well together – including things I’m working on writing about 🙂.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑