Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 85 of 219)

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

WordPress Unit Tests Included With Your Plugins

WordPress Unit Tests naturally play a big part in making sure that new features introduced into core work as expected and that previous features do not break. And pushing forward with more test coverage is a Good Thing™.

In the last couple of plugins, I’ve released into the WordPress Plugin Repository, I’ve included unit tests with the plugin. Of course, these aren’t for the users benefit (why would they be?).

The way I see it if we’re working with open source, why not include these tests for those who may download, run, fork, test, or explore the code base?

But there’s a thing about these unit tests: They inherit from WP_UnitTestCase. And the more I work with creating plugins for fun, for profit, and for others, the more I think that unit tests we ship with our plugins don’t necessarily need to inherit from that class.

WordPress Unit Tests: The Source Code on Trac

Instead, they should inherit from the standard set of classes provided by PHPUnit.

Continue reading

Delete All Files of a Certain Type (Using PHP)

In the previous post, I shared a way to process all of the files in a given directory. Specifically, it covers how to read all of the files that have a particular naming convention.

There’s a second part, though:

What if you want to delete all files?

That is, let’s say you’ve processed all of the individual files, and then you want to delete all files that are in the directory from which you were reading them.

Continue reading

Read All Files of a Certain Type (Using PHP)

Let’s say you’re working on a WordPress file that has to import data from a very large file. To avoid PHP timeouts, it helps to separate the files and then import then in pieces (or in chunks, because that word is more fun :).

But to do that, it implies you’re capable of taking a file and splitting it into some smaller files.

When you do this, I assume that each smaller file will follow a particular naming convention (like file_0.txt, file_1.txt, and so on).

Read All Files of a Certain Type

So when it comes time to read each file, how do you do it?

Continue reading

HTML Data Attributes, JavaScript, and Databases

HTML data attributes are one of the neat features of HTML5 that give us a lot of flexibility.

HTML Data Attributes to save information to the database

We can use them for a variety of things (and abused for just as much), but the general idea behind the attribute, according to MDN, is this:

HTML5 is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined meaning. data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, extra properties on DOM, or setUserData.

Yes, it reads a bit long. Consider it like this, though:

Data attributes provide a way to save extra information about an element in a semantic way without using conventional hacks (that so many of us are used to using).

Though there are a variety of ways in which this attribute can be used, I’ve found it to be useful when working with a front-end element that’s part of a dynamic set of larger elements.

Further, any one of these elements will be used via JavaScript to send data to the server via Ajax.

Here’s a simple example of how to use the HTML data attributes and Ajax.

Continue reading

WordPress Tools and Our Responsibility

Once you’ve worked in the WordPress economy long enough, you become familiar with the larger players, smaller players, and everyone in between. You also gain a level of awareness with the various things people use as their WordPress tools.

The thing about “tools” is that it’s such a generic term, it depends on what it is you do with WordPress that defines what your tools may be.

  • If you’re someone who creates sites for others through the use of off-the-shelf products like themes and plugins, then your tools may include a suite of various themes, plugins, and preferred hosts.
  • If you’re a developer, then you may have a preferred piece of software for your local development environment, version control, staging environments, preprocessors, and so on.
  • If you’re a designer, then you may have your sources of inspiration, your tools for editing photographs, designing collateral, and so on.

Regardless of what you do within the WordPress economy, it’s important to make sure that you know with whom you’re doing business.

And this sounds a bit like obvious advice, but hang with me for a few paragraphs.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑