Using the Registry Pattern in WordPress

I’ve had a few conversations with various friends and others on Twitter about the notion of global variables in programming languages. For those who are new to programming or who are unsure as to why they are bad:

The use of global variables makes software harder to read and understand. Since any code anywhere in the program can change the value of the variable at any time, understanding the use of the variable may entail understanding a large portion of the program.

This isn’t to say they don’t have their use, but if you’re interested in object-oriented programming (especially in a WordPress setting where you’re going to be using PHP), then it’s important to understand some better alternatives than global variables.

That is, there are ways to work with passing data around your application without the need for global variables. And one such way is the repository pattern.

Read More

Native WordPress Debugging Tools That Don’t Require an IDE

If you’ve just happened to join up on the membership of the site and are pursuing content specifically for The Independent WordPress Developer, I recommend reading the previous post – at the very least – to prepare for content in this post.

If, however, you’re looking to catch up on the previous article, here’s a short list of everything that’s been written thus far:

  1. Local Development for the Indie WordPress Developer
  2. Databases and Tools for the Indie WordPress Developer
  3. Installing WordPress for Local Development

As we prepare to move into talking about more advanced topics such as debugging and IDEs, it’s first worth noting the tools we have tools available that we can install within WordPress that will help us with debugging issues during development.

Native WordPress Debugging Tools: WordPress

Further, these issues are not related to strictly PHP issues. These also include JavaScript issues. And to take it one step further, there are ways in which we can configure WordPress natively so that it outputs errors directly to our browser.

So before we look into error logs, IDEs, Xdebug, and so on, we’ll take a look at what we can do within WordPress itself.

Read More

Musing on Modern Package Managers

I was recently talking with a friend about all of the available tools that are on the market for us today (some free, some open source) that help us with our development needs.

Modern Package Managers: Yarn

These include things like:

Of course, each of the above is not necessarily comparable because some are front-end tools, others are backend tools, and there are some that offer a hybrid of sorts.

Further, some are premium, some are open source, some appear to be abandoned, and some have even lead to broken build processes.

This leads to a series of questions several of which I’d like to cover. So here, if nothing else but musings on modern package managers, are the things about which I’ve been thinking.

Read More

Split Strings and Integers in PHP Using Regular Expressions

Working with strings, numbers, and regular expressions in PHP is relatively easy given the vast number of functions the language provides.

There are times, though, where figuring out how to split on certain criteria may not be immediately clear, or it may be clear what you need to do but not how to best do it.

Split Strings and Integers in PHP Using Regular Expressions

Photo by Agê Barros on Unsplash

For example, let’s say that you have a string that’s mixed with both numbers and digits. For this post, let’s say that a given string:

  • includes hours and minutes,
  • when the minutes are at 60,
  • the string should increase the value of the of the hours by one
  • the value of the minutes is reset to zero.

An example, problematic string, then, may be of the form T3H60M. How then might we split the string into strings and integers and properly rebuild it?

Read More

Installing WordPress for Local Development

So far, we’ve covered some things all of which lead us in setting up our local development environment. If you’ve not yet caught up, I recommend reading the previous articles:

  1. Local Development for the Indie WordPress Developer
  2. Databases and Tools for the Indie WordPress Developer

In the final article, I state the following:

Next, it’s time to get WordPress installed. It’s extremely easy, so if you’ve come this far, I’d state with confidence that the toughest part is over.

This is usually the easiest part (really), but there are two ways in which you can manage this, and I’m going to cover both. For those curious, it breaks down like this:

  • installing the latest stable version of WordPress,
  • installing the most recent nightly build of WordPress

There are reasons that you may want to use one versus the other. I tend to favor the latter when building out my own solutions for reasons I’ll cover later in the article but note that both of the above are covered in this post.

So with that said, let’s get started.

Read More