Software Engineering in WordPress, PHP, and Backend Development

Category: Articles (Page 105 of 258)

Personal opinions and how-to’s that I’ve written both here and as contributions to other blogs.

Using Namespacing and Autoloading in WordPress

It’s not hard to find criticism about namespacing and autoloading in WordPress, and lack thereof. As much as I’d like to see it, I think it’s important to take a practical look at the software as a whole, the requirements, and realize that implementing such organization would require a lot.

Specifically, it would require applying object-oriented programming throughout the entire codebase (which would last longer than a release cycle in and of itself).

It would also require that all hosts who support WordPress on any level (yes, even those supporting legacy versions) can handle the new features.

In short, it’s not an easy task and it’s important to recognize the practical challenges that come with doing so in 13 year old software powering approximately 25% of the web.

It’s not that it can’t be done, that it won’t be done, that people don’t want it done. But it’s requires exceptional planning, execution, testing, and support from a wide array of situations that I don’t know if I can even fully grasp.

With all of that said, though, this doesn’t mean that we can’t use namespaces and autoloading in our WordPress projects.

Continue reading

WordCamp US 2016, Post Status Publish, and Instagram

This post is going to be weird:

It’s a deviation from my normal content, it’s going to cover WordCamp US 2016, an event prior to that, and social media.

I said it was weird. But hang with me.

I’m not an avid user of Instagram in that I don’t really, you know, post pictures or anything like that. At least not right now.

I have, however, been using the story feature a little bit (much like Snapchat but without the absolutely terrible UI and pathetic stories shared by “news” outlets).

It’s also fun to follow along with those who do share photos and stories. I just don’t have that much to share given that I work out of my house, live in my house, and generally hang around my house during the week.

Continue reading

Buffering WordPress Content with PHP

I know: If you’ve been working with WordPress for any amount of time creating themes or plugins, then you’re probably familiar with filters. Even if you’re not really sure how they work, you’ve likely worked with something like the_content.

And by that, you’ve likely written a line of code that looks like this:

It’s enough to work with, too. Usually, this is used whenever you want to modify the content before sending it to the browser to render.

But I recently had to work with it in a somewhat unusual way that required the usual of this filter, a template file, and PHP’s output buffer such that I was buffering WordPress content.

Continue reading

Properly Writing WordPress Plugin Constructors

One of the things that many of us see (and are guilty of abusing) are WordPress plugin constructors.

If you’re using object-oriented programming, you’re likely familiar with constructors. However, the purpose they serve isn’t always clear at least in the world of WordPress.

The definition of a constructor well-defined in Wikipedia:

In class-based object-oriented programming, a constructor (abbreviation: ctor) in a class is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.

But here’s the key thing to notice for anyone working with constructors and object-oriented programming in WordPress plugin development:

It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.

And this is where many of us, and WordPress plugin developers, fail. We abuse constructors for a purpose they are not intended.

Continue reading

Initializing Default WordPress Options

Whenever you’re working on a plugin that’s going to have a decent set of options (and I’m not talking about giving users too much to think about because “decisions, not options,” remember?), it’s wise to initialize default WordPress options.

Default WordPress Options in the Options Table

By that, I mean it’s important to set up an array or whatever data structure you like to use (but WordPress does love its arrays) and prepare them to be saved before the user even interacts with the settings page(s).

Think of it this way:

A user installs a plugin; they’ve yet to select any option; we need to drive the UI elements through input fields, checkboxes, radio buttons, etc., so we have functions that make calls into the database. But where they are they going to get their options?

That’s where this come into play.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑