Software Engineering in WordPress, PHP, and Backend Development

Tag: Procedural Programming

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

Procedural Programming: Private Functions in WordPress

One of the things that I’ve been criticized for (for lack of a better term, I suppose) is that I push object-oriented techniques over procedural programming  in WordPress.

To some degree this is true: I do prefer object-oriented programming, but I don’t think it’s the end-all-be-all of programming paradigms. After all, when building, say, a theme, there’s actually little room for writing object-oriented code.

On top of that, because of the minimum requirements of WordPress, there are a lot of advanced features in PHP that I avoid because I can’t be guaranteed that the end user will have them available on his or her system when they install the plugin.

So, sure, I prefer object-oriented programming, but I certainly don’t aim to make it the utopian programming practice.

That said, there is one aspect of procedural programming that requires some type of convention: private functions.

Continue reading

© 2024 Tom McFarlin

Theme by Anders NorenUp ↑