Software Engineering in WordPress, PHP, and Backend Development

Author: Tom (Page 71 of 427)

Don’t Over-Engineer the Solution

If you come from an object-oriented background or try to build all of your solutions for WordPress using object-oriented techniques, then there are going to be times where it might feel like you’re hitting a nail with a sledgehammer.

For example, let’s say that someone comes to you and needs a custom plugin developed that works with a third-party plugin but it only needs to do one thing.

Is it worth taking the time to create an interface, implementing the said interface in a concrete class, set up subscribers, write unit tests, and so on?

I can see the appeal, but I generally say no. If the gist of what you need to do has to be including styles or JavaScript files or both, then why not rely on the native WordPress APIs and procedural programming?

Continue reading

Including Custom Fonts in WordPress Plugins

The more you work in web development, the more likely you’re going to see people asking you to incorporate custom fonts into their project.

Sometimes this is easy. For example, if you work with something like a Google Web Font, you can easily copy the code necessary to paste into your stylesheet.

Custom Fonts in WordPress Plugins: Google Fonts

Often, the code looks something like this:

And then you can use it in your stylesheet like this:

But what if someone provides you with a set of fonts that they want to use in their project that are in a file format and that are not hosted on some type of content-delivery network?

Continue reading

Adding Custom Information to a WordPress Category Edit Page

Adding additional meta boxes, fields, and other information to WordPress is easy if you know the right hooks and the proper APIs to follow. But what if you want to add information to a WordPress taxonomy page?

For example, say you want to create a custom WordPress category edit page or, at the very least, add some custom information to a taxonomy page?

It’s still possible to do that, and it’s still relatively easy but, again, you need to know the right hooks to use, and it also depends on if you’re working with the built-in taxonomies or a custom taxonomy.

For this post, I’ll show how to do this using a custom, hierarchical taxonomy (or, in simpler terms, a custom category).

Continue reading

The Why and How of Custom jQuery Events

As far back as 1.0, jQuery has provided a trigger function that allows us to:

Execute all handlers and behaviors attached to the matched elements for the given event type.

But it wasn’t until 1.3 that this particular function became significantly more useful, at least as far as I’m concerned. I say that because that’s when we gained the ability to define custom events and then set handlers for them.

Custom jQuery Events

What, though, is a likely use case in which custom jQuery events are useful in the context of WordPress? Off the top of your head, you may be able to come up with many. Or maybe not.

It hasn’t been until lately that I’ve been using them significantly more than usual. So I thought I’d share how I’m using them if for now other reason than showing you how to wire them up to your work.

Continue reading

Aim to Break Programs into Smaller Components

One of the things that programmers often talk about is the desire to break programs into smaller components, or functions, so that it makes them easier to trace, easier to read, and easier to debug.

But it’s not all that uncommon to see monolithic functions with a lot of code comments to help explain what’s going on in the program.

Breaking Things Into Smaller Components: Monoliths

A monolith ala 2001: A Space Odyssey.

I’m not knocking this, really, because I don’t know the constraints under which a programmer was working. That is:

  • What was the budget s/he had when building the program?
  • How much time was given to complete the project?
  • Were there many people working on the project?
  • Was the programmer given time to write the code so they could unit test it, refactor it, or merely make it easier to read?

In short, there’s a lot of reason – I believe – that we can read “bad code,” and it doesn’t always have to be the fault of the programmer (that’s just the most natural thing we have to throw out when we read something we dislike).

Does this mean, though, that we shouldn’t strive to refactor or write code in such a way that makes it easier to understand? Of course not. Assuming we have the time to do so, how might we do it?

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑