Software Engineering in WordPress, PHP, and Backend Development

Author: Tom (Page 105 of 427)

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

On Improving Content Across the Board

When I last published, it was all about taking a break from social media and why I think it’s useful.

But I ended up not only doing that. Instead, I also took a break from writing (which save for a recent trip is not something I usually do). When you end up taking that kind of time off from writing, you can’t help but build up a backlog of ideas for content that will eventually find its way to be published.

Before getting back into the usual routine, I thought it worth sharing some upcoming plans I have for the site that will impact those of you who read regularly and those of you who may be new readers or who are just stumbling across this post.

Continue reading

Social Media Breaks Are Good for the Soul (I Think)

Not too long ago, I took a break from social media for two reasons (one no more important than the other):

  1. to try to break the habit of compulsively checking social networks whenever I was stuck on a problem,
  2. to cut back on “chatter” during the day.

(I looked through my previous posts to see if I talked about it at length but couldn’t find it.)

https://twitter.com/tommcfarlin/status/880912831922753536

Anyway, it’s something I’ve decided to do again, although this time I have a few different reasons. Maybe it’s social media breaks are something I’ll do a more on the regular, maybe not. I can’t know that right now.

We’ll see in a month.

Nonetheless, this time I thought it worth sharing a little bit more behind the reasons why if for no other reason to make sure I have it documented more so than I did last time.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑