Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 38 of 219)

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

The Basics of Action Hooks in WordPress

Anytime sometime starts to get into more advanced programming – be it in WordPress or any other framework, library, foundation, or programming language – there are times in which new concepts can often be more difficult to understand than others.

I generally have found this to be true whenever a person has learned the basics of, say, object-oriented programming but hasn’t been exposed to the nuances of certain things such as design patterns.

Case in point: I’ve written about the event-driven design pattern (or the publish-subscribe or Pub/Sub as some like to refer to it) in other posts.

Yes, there are some differences to each, but the general idea is that something happens and an event is raised and anything listening for that event, or subscribed to that event, will respond.

Action Hooks in WordPress: Pub/Sub

Photo by Claus Grünstäudl on Unsplash

This is the primary pattern that WordPress employs that allows us to quite literally hook into certain points of execution. We can generally conceptualize these as action hooks in WordPress.

Anyway, the application makes certain points available for us to add our own functionality. Once that functionality is registered, WordPress will leave its codebase, so to speak, hop into ours, then return back to ours.

It’s easy enough to understand, but what if you want to expose areas in your code that allow others to hook into your code?

Continue reading

A Quick Note on Unit Testing Code in WordPress Projects

The more work I do in WordPress, the more I try to make unit testing as much a part of my development as building out the actual feature set. (It’s what all the professionals say we need to do, anyway.)

But seriously, it does improve the quality because, if for no other reason, something breaks, you’re able to see which test fails or even if you’ve missed coverage in some area.

I’m not of the mindset of some that you have to have 100% code coverage (and there are reasons for why I think this), but I do think it’s important to have as much code coverage as possible of code that is not directly to WordPress.

Continue reading

Resizing Images Programmatically in WordPress

If you’ve ever had to work with resizing images programmatically in WordPress, then you may have come across the image_resize function.

Resizing Images Programmatically: Deprecated Functions

Further, you may know it’s been deprecated (given that this appears at the top of the screen):

This function has been deprecated. Use wp_get_image_editor() instead.

And with its deprecation, as is true of all those who do a good job deprecating functionality, it’s not without its replacement.

In this case, we’re talking about the WP Image Editor. This is a class in WordPress that we can use to perform the same operations to go about resizing images programmatically that we once could with the original function.

Continue reading

The Demand for Gutenberg Is Not There. Yet.

I’ve been asked, on a few occasions, why I’ve not released anything that’s compatible with Gutenberg or why certain plugins aren’t compatible with the current version of the Gutenberg plugin.

Demand for Gutenberg Is Not There

In the WordPress economy, I’ve seen few things as divisive as this shift in WordPress (though it seems to be finally have chilled a bit). And I’m not interested in entertaining a position on it on this blog.

But when others ask why I’ve not bothered to write anything about it or make certain plugins compatible with it, I find that it’s worth talking about it at least to a certain degree.

Continue reading

Sanitizing URLs in WordPress with Its API and Built-In PHP Functions

Working with user-centric fields in WordPress – such as input elements, textarea elements, or any type of field in which a user can supply their own values is a place that should always be a target of sanitization.

Sanitizing URLs in WordPress with Its API

Fortunately, the WordPress API provides a number of functions to help with this. Depending on your use case, you may need to do one of the following:

And those are all well and good but there are also ways in which you can work to sanitize the data using functions provided by PHP.

Sure, sometimes regular expressions are the way to go but, other times, you may want to use facilities that are built into the language, easier to understand, and easier to follow.

When writing my own code (and when reviewing others) I try to keep that in mind. So with that said, here’s a process that you can use that may make your efforts easier when working with URLs in WordPress.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑