Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 92 of 219)

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

Saving Empty Radio Button Values in WordPress

One of the projects I’ve been working on recently presents the user with a comprehensive set of options. As usual, the options take the form of a variety of different elements:

  • input text fields,
  • radio buttons,
  • select elements,
  • and more.

In most cases, you should be familiar with initializing default values for all of these element types. Radio buttons may be the exception. And if they are, then you’ve no doubt run into a PHP notice when saving empty radio button values.

And having PHP notices is no good, right?

Regardless of if you’re using the WordPress Settings API or some custom serialization code, these notices can still show up. If you use Query Monitor, then you’ve likely seen this show up in your menu. Similarly, if you use the Console (or another application) to monitor your PHP logs, you’ve probably seen the error as well.

OS X Console

One place in which this can be tricky to deal with is when you’re working with radio buttons without an initial value.

Continue reading

What Should I Build? Ideas for WordPress Projects.

Anyone who writes regardless of if it’s prose, creative writing, code, a blog post, or more is familiar with writer’s block in some form or fashion. And when it comes to programming, I think some experience the same type of thing (programmer’s block, perhaps?).

Case in point: I remember when I was younger, and was learning to program, I had this insatiable desire to want to create something to use, or others would use. The problem was that I didn’t know what to try to write.

Granted, I was young at the time, and I lacked several skills that were needed to build something like that, but – as they say – I didn’t know what I didn’t know.

Now, much of my work is spent building things for others. That is, they have a problem that needs solving, and I have the desire and means by which to provide said solution.

And I love it.

There are times, though, that I still bump up against a particular problem that I wish I could solve. The only difference between now and two decades ago is that I have the means by which I can do that.

Clearly, it’s taken a while to get to that point. But the point remains: People are learning to program and want to build something, but they don’t know what to build or how to discover what to create.

It’s easy to spout off “well just scratch your itch.” But that doesn’t do much to get the creativity flowing, does it?

So in my latest article for Envato, I try to provide some practical advice on how to determine what to build when using WordPress.

Continue reading

Single Responsibility Principle: Option Pages

Assuming you’ve read the following two posts (on the single responsibility principle and WordPress submenus), then this is a good place to tear apart the code and start trying to apply the principle.

Single Responsibility: One Reason to Change

If on the other hand, you haven’t read the posts, there are two things to note. First, the single responsibility principle says the following:

A class should have only one reason to change.

Secondly, review the code in this gist as this is the basis for the rest of the content of this article. Specifically, I’m going to be taking the above principle and try to apply it to the code.

Continue reading

Single Responsibility Principle: WordPress Menus

The single responsibility principle, as mentioned in the previous post, should be thought of as nothing more than asking the following question:

A class should have only one reason to change.

The question is far simpler than the answer, though. And through this post and the next, I’m hoping to demonstrate exactly that.

But first, I want to mention that the context for this particular question is with a relatively simple API. This doesn’t mean that the result isn’t as beneficial. It does, however, make for quicker reading and more time to talk about the application of the principle.

Continue reading

The Single Responsibility Principle in WordPress

Every time I work on a project for a client (or a side project for myself), I try to keep in mind each of the five SOLID principles.

These are often talked about by developers on numerous blogs (and I’ve done so myself on this site), so I’m not about to teach of them in this post.

Single Responsibility: One Reason to Change

Instead, I’ve been looking at how the Single Responsible Principle applies with working with various aspects of the WordPress API. And what I’ve found is that, in my experience, using this principle consistently results is far smaller classes.

My most recent experience has been in a very simple use case: Working with the WordPress API to create a submenu item and a corresponding submenu page.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑