Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 56 of 219)

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

Avoiding class_exists in Object-Oriented WordPress Code

If you write object-oriented code for WordPress (usually within the context of plugins), you’re likely to come across a class_exists check before initializing a class. But we should start avoiding class_exists in much of our code at this point (with a few exceptions that I’ll outline below).

Avoiding class_exists

Depending on the version of PHP you’re using, this makes sense. Or it did at one time. As of PHP 5.3.0, this isn’t necessary. Instead, it’s a better practice to use namespaces.

Continue reading

How to Display Recent Custom Post Types (Excluding the Current Post)

Let’s say you’re working on a page template and it’s going to include a partial that’s going to display recent custom post types (or maybe even the standard post type) of the post type you’re viewing.

For example, say you’re looking at the example of stories or something like that. And you’re looking at a single page for a given author. Then, perhaps in the sidebar, it reads Read More From Other Authors, and it retrieves stories from up to five other authors.

Display Recent Custom Post Types

Where additional custom post types may appear.

Writing a custom WP_Query, pulling back the five most recent posts, and dropping them into the selected area seems easy enough, right?

And it is. But there’s a gotcha.

Continue reading

Using Xdebug with Valet and WordPress

Though I’m not a fan of strictly using var_dump or echo statements as a way to debug code, that doesn’t mean there aren’t times in which they are useful (otherwise, they wouldn’t be part of the language, right?).

But what if you’re using Laravel Valet (which is easy enough to setup for WordPress) and you’re trying to display some multidimensional array and rather than getting some nicely formatted output, you end up getting one long line of text in Times New Roman? Odds are this is because you don’t have Xdebug.

Using Xdebug with Valet and WordPress: Valet

It’s easy enough to do, but it’s predicated on a few different things. Plus, once you get Xdebug installed, then you’re able to use a debugger with your code, as well. That’s not the point of this post, though.

Continue reading

Adding Featured Mobile Images via CMB2

The other day, I shared how to add your WordPress plugin to Packagist. In the post, I mention that I did this with a recent project though I didn’t go into any detail about it. In short, the purpose of the plugin is to make it easy to add featured mobile images to WordPress.

For those who are familiar with CMB2, then you know it’s often used as a way (if not the way) for many developers to incorporate custom meta boxes into WordPress. And for the requirements on a project, I needed to introduce the ability to have a mobile featured imaged.

So to gain experience with creating a CMB2-based plugin and to learn how to use Packagist, I thought I’d use the project as an opportunity to do both.

Continue reading

Adding Your WordPress Plugin To Packagist

When you start adding your WordPress plugins to GitHub, one of the next things you’re likely going to want to do is make it easy for other developers to begin incorporating those packages into their composer.json file.

That is, they don’t have to download your plugin, include it in your project, watch for updates, or anything like that. Instead, they add the file then run:

$ composer update

…whenever they are ready to get the latest version of your work.

But simply contributing your work to GitHub is not enough. You have to submit your WordPress plugin to Packagist (of course, this works with other projects, too, but that’s outside the scope of this blog, really).

And here’s how to do it.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑