Software Engineering in WordPress, PHP, and Backend Development

Category: Articles (Page 87 of 258)

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

On Immutable Values in WordPress Plugins

If you’ve done any work – or even any reading – on object-oriented programming, then you’ve likely come across the idea of immutability. That is the idea of something being unchanging.

Sometimes you can have immutable values, and sometimes you can have immutable objects (at least after they are instantiated).

Immutable Values in WordPress Plugins

The opposite of immutable (but he was my favorite ninja turtle, anyway).

The thing is, the more I work with object-oriented code, the less I tend to work with immutable variables. Sure, I’ll use constants as defined in a configuration file, but you’re not likely to find me storing values within a class as a const.

That probably implies something about me and my abilities, but it’s true. Thankfully, code reviews are great at helping you see opportunities on where to leverage strategies you normally wouldn’t. And such is the case with immutable values in WordPress plugins.

Of course, this is one of those things that was brought to my attention by a friend when reviewing my code.

Continue reading

Sending Secure Ajax Requests in WordPress (with Nonces)

I know that the REST API is a huge topic of conversation in WordPress right now, and rightfully so, but there are still times in which we have to use admin-ajax (as its coming to be known) for a variety of reasons.

  • Perhaps it’s an application,
  • Perhaps time doesn’t allow for creating the necessary endpoints,
  • Perhaps you’re more comfortable with admin-ajax,
  • And so on.

Regardless of your reasons for why you use it (which I still do, for whatever that’s work), I think it’s important to make sure we’re sending secure Ajax requests in WordPress using nonces just as you would if you were submitting traditional form data.

Secure Ajax Requests in WordPress

Legitimate, live shot of wires carrying your Ajax request.

If you search the web for results on how to do that, you’ll come up with a variety of answers, and this will be just another drop in the proverbial bucket.

But if you’re curious for a recipe for how to handle it, this is how I do it each time.

Continue reading

So When Do We Update Out-of-Date Blog Posts?

Late last week, a good friend of mine linked me to a post I wrote earlier this year.

Out-of-Date Blog Posts

Do we update out of date blog posts?

If you opt not to read the post, the short of it is this:

  • tt’s about a plugin bootstrap file,
  • and there’s a discussion in the comments about it.

Here’s the thing: The more work you do with a given set of tools, the more you’re going to learn and the greater your skills are going to get.

So the posts that you’ve written become a bit out of date. Are we then recommending bad advice? Ultimately, this raises the question of what do we do with blog posts that may be out of date?

Continue reading

Rapid Prototyping: Introducing Autoloading

Over the last few posts, I’ve walked through the process of taking an idea from concept to prototype.

Granted, there are some things that you might change (and there are some things I’d change regarding organizing classes). But the point of the series isn’t to walk through all of the various object-oriented techniques that can be used to create a solution.

Instead, it’s about taking a prototype and converting it into something a little more professional. There’s still one thing that we need to do, though.

Right now, we include all of our files through require statements. And this works alright for small files, but introducing autoloading in conjunction with namespaces can make the application even cleaner.

And that’s what we’re going to do.

Continue reading

Rapid Prototyping: Prototype To Code, Part 2

The previous post demonstrates a lot of work in taking something that was once a rapid prototype and taking that prototype to code. If you haven’t been following along, we’ve done the following:

  1. talked about and built a prototype for a plugin,
  2. diagrammed out one object-oriented approach may work,
  3. and refactored our prototype to actual code.

At this point, there are a few more things we can do to improve our code. Namely, we can introduce the concept of namespaces. This takes the organization a step further and can pay dividends for larger projects.

So here’s a look at how this plays out in our current project.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑