Software Engineering in WordPress, PHP, and Backend Development

Category: Articles (Page 91 of 258)

Personal opinions and how-to’s that I’ve written both here and as contributions to other blogs.

How to Exclude Files From PHP CodeSniffer

When you’re working with PHP CodeSniffer, and you’re doing so in the terminal, you’re likely looking to output errors into something other than your IDE.

I mean, if that were the case, you’d just have it running in your editor, right?

But there are times where you may be interested in finding the problems in other people’s code. Perhaps it’s a dependency, perhaps it’s a third-party piece of software, or perhaps it’s a favor.

Whatever the case, if you’ve set up the project directory in a way that uses Composer to include PHP CodeSniffer and you’re using the WordPress Coding Standards, then you’re likely going to need to exclude files from PHP CodeSniffer when running the program.

And this is how you can do that.

Continue reading

WordPress Plugin Interfaces: Working With Assets

One of the advantages of working with object-oriented programming is the ability to define interfaces so classes that implement those interfaces have a strict set of functions that said classes must implement.

WordPress Plugin Interfaces

That is the definition of a class interface, anyway:

An interface is a contract specifying a set of methods, fields and properties which will be available on any implementing object

But how might this look if we’re aiming to create a namespaced solution for including WordPress plugin interfaces (or an interface) for a class that can be used to enqueue stylesheets or JavaScript files?

Continue reading

Globally Installing WP-CLI for Access Across Your System

When working on WordPress-based projects that utilize Composer, there are times that we’re going to want to have certain dependencies available for our project and there are times where we’re going to want to have tools available throughout our system.

For example, for some projects, we may want to have PHP CodeSniffer with the WordPress Coding Standards available. For others, maybe not.

But having a tool like WP-CLI is something that’s likely better served when it’s available throughout the entire system rather than on a project-by-project basis. Globally installing WP-CLI is a relatively trivial matter.

It does, though, assume you have Composer already installed and available on your system.

Continue reading

Sponsored Posts: They Should Be About the Reader

For as long as I’ve written on this blog, I’ve always approached it with the perspective that this is my content all based on my experience. And given that the blog tied to my name in the domain, it seemed to make sense.

Introducing Sponsored Posts: Never thought I'd be doing something like this back in 2010.

This site, as it were, back in 2010, courtesy the WayBack Machine.

However, the longer I’ve worked within the WordPress economy, the more people I’ve met who are doing some really incredible things with it. Some people are building some really cool plugins and themes for it while others are building tools specifically for those building said plugins and themes.

And as I’ve mentioned numerous times throughout the year, there are some changes coming to this blog – all for the better, of course (at least that’s the goal) – and the first change I’m looking to introduce is to begin offering sponsored posts.

Continue reading

Properly Filtering Post Content (And Understanding apply_filters)

Now and then, whenever I’m working with pre-existing source code or performing a code audit, I’ll see others modifying the post content of a post object like this:

At this point, some will drop in and immediately say you’re doing it wrong. I hate that phrase (and it’s even littered throughout the WordPress codebase, but I digress).

There are ways to use other existing WordPress API functions to sanitize the data before setting it equal to the value of the post_content attribute, using those functions isn’t the best way to go about doing it.

Instead, we all should be using apply_filters. The problem? Some don’t know, some don’t know how it works, and some don’t know how to use it. That is it’s not clear how to go about properly filtering post content.

Properly Filtering Post Content

Raw content filtered by WordPress then written to the database.

But for those who may fall into any of the categories above, then perhaps this can help.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑