Introduction to the command-line interface

Someone once asked me, “What’s the thing that used to scare you the most as a developer?” And, without even hesitating, I answered, “Linux and the command-line interface.” We both laughed at the answer.

That’s because I’m hardly the only one to think this. There are few things early in your career as a developer that you’ll dread touching more than a command-line interface. And, even later in your career, you might still try to avoid it at all costs.

That’s why there are so many developer tools that are nothing more than abstractions over the command-line. We’d rather pay and use these tools than have to deal with a command-line interface. This isn’t a bad thing per say either.

If you get the job done faster with those tools and are more comfortable with them, you should use them. But, that doesn’t mean that you shouldn’t be comfortable with a command-line interface either. There are situations (like when you’re connecting to a server) where you won’t have access to your favourite tool, but you’ll have access to a command-line interface.

Continue reading Introduction to the command-line interface

How do you start unit testing existing WordPress code?

A lot of us have heard about unit testing. Out of all the different types of testing (and there are a few!), it’s probably the better-known one. It’s also the most common form of testing used with WordPress.

In the past, we’ve looked at how unit testing works with WordPress. That said, knowing how unit testing works is one thing. This knowledge doesn’t necessarily make it any easier to get started with it in your projects.

Some of us work with existing code bases. It could be a plugin, a theme or a whole WordPress site. How do you take the fundamentals of unit testing and apply them in that context?

This is a tricky question to answer, but it’s also an important one. Most of us will not start using unit testing in a vacuum. We’re going to start using it with one of those existing code bases.

This brings with it its own unique sets of challenges. It also means that you need to have a strategy for them. This will help make this transition smoother for you.

Continue reading How do you start unit testing existing WordPress code?

Continuous deployment to the WordPress directory with CircleCI

Note: This article focuses on how to continuously deploy a plugin using CircleCI. But you can also use everything discussed here with a theme as well.

As developers, we all have our preferred tools and distinct way of working. That’s why it’s not uncommon for us to write about it or create scripts to set up our work computers. But the one tool that most of us tend to agree on is using git for version control.

That said, if you’ve ever had a plugin or theme on the WordPress directory, you know that it doesn’t use git. It uses subversion. That’s a problem for a lot of us because we don’t want to have to deal with both.

While there are a lot of resources out there to deal with this problem, it also presents us with an opportunity. We can use this problem to build a continuous deployment workflow for the WordPress directory. This will allow us to not worry about this aspect of WordPress plugin development anymore.

Continue reading Continuous deployment to the WordPress directory with CircleCI

PHP reflection API fundamentals

Do you ever take the time to read the code of your favourite PHP framework or library? If you have, there’s a good chance that you might have seen them use PHP’s reflection API. And, if you don’t read other people’s code, you should start doing it! (It’s a great learning tool.)

Now, let’s get back to the reflection API. This is an API that gets used quite a lot by framework and library developers. But the funny thing is that it’s almost never talked about when you’re looking at resources to learn PHP. (Or even advanced PHP resources for that matter.)

This is unfortunate. That’s because PHP’s reflection API serves a unique and important purpose. That’s why developers that build our frameworks and libraries use it so much.

Continue reading PHP reflection API fundamentals

Designing entities using WordPress custom post types

Custom post types are one the most powerful features of WordPress. You can use them to save any type of data that you want in the wp_posts table. Most plugins that build complex features on top of WordPress (e.g. WooCommerce) rely on them.

But custom post types aren’t just useful for developing new features on top of WordPress. They also allow us to rethink how we use object-oriented programming with WordPress. And, as we’ll see, this is an important step in your journey learning object-oriented programming with WordPress.

That’s because having a different view of custom post types will expand your object-oriented design horizons. They’ll help you build new types of classes that you might not have considered before. And this can be a game-changer when creating larger object-oriented plugins or themes.

Continue reading Designing entities using WordPress custom post types

Getting started with continuous integration and WordPress

I gave an introduction to continuous integration with WordPress at WordCamp San Diego 2018. This is the companion article that I wrote for it. If you’re just looking for the slides, click here.

Writing high-quality WordPress code is hard to do. It requires constant effort on our part and good self-awareness to know when we slipped up. But, if your business has any sort of success (which we all want!), you’re going to work with more and more people. And many of them are likely to touch with your code.

This is going to put a strain on your development processes. It becomes harder to maintain a certain level of code quality. And you’re no longer the only person making code changes. You’re now part of a team, and you need a way to standardize all of the things you once did on your own.

That’s goal of continuous integration. It lets you automate your different development workflows. This ensures that the quality of your code stays consistent.

Continue reading Getting started with continuous integration and WordPress

Designing a class to represent a WordPress meta box

In a previous article, we discussed how to design a class representing a WordPress admin page. This was important because almost every plugin or theme needs an admin page. But this isn’t the only common thing that plugins or themes add to the WordPress admin.

Another one of those is the meta box. If you’re not familiar with meta boxes, they’re the draggable boxes that you see on the post editing screen. It’s quite common for plugins and themes to add post-specific functionality through them.

This makes them a good topic to discuss with object-oriented programming. (Is there really a bad topic to discuss with object-oriented programming!?) And, as we’ll see, meta boxes have a lot of in common with admin pages. This means that designing a class to represent them will be a lot like what we did for admin pages.

Continue reading Designing a class to represent a WordPress meta box

What is software complexity and how can you manage it?

I spoke at LoopConf 2018 on software complexity and how to manage it. This is the companion article that I wrote for it. If you’re just looking for the slides, click here.

As developers, we spend a lot of time writing code. But we spend even more time maintaining that code. How often do we go back find that that code has become this tangled mess that we almost can’t understand? It’s probably more often than we want to admit!

We wonder, “How did this happen? How did this code get so messy?” Well, the most likely culprit is software complexity. Our code became so complex that it became hard to know what it did.

Now, software complexity isn’t a topic that developers are often familiar with when they start coding. We have other things to worry about. We’re trying to learn a new programming language or a new framework.

We don’t stop and think that software complexity could be making that job harder for us. But it is doing precisely that. We’re creating code that works, but that’s also hard to maintain and understand. That’s why we often come back and ask ourselves, “What was I thinking!? This makes no sense.”

That’s why learning about software complexity is important. It’ll help you increase the quality of your code so that these situations don’t happen as often. And this also has the added benefit of making your code less prone to bugs. (That’s a good thing even if debugging is a great learning tool!)

Continue reading What is software complexity and how can you manage it?

Designing a system: WordPress REST API endpoints

Let’s talk about the WordPress REST API. It’s been around for a little while now, and you might have even started using it in your projects. After all, a lot of us are trying to get more into JavaScript. (Zac Gordon has built a great course if you’re looking to get into it.)

But that doesn’t mean that the standard WordPress REST API will be good enough for your project. There’s a good chance that you’ll need to extend it so that you can do more with it. And that’s done using PHP even if you’re working with JavaScript. (Sorry JavaScript lovers!)

That means that this is still a great excuse to use object-oriented programming with WordPress. (Yay!) In fact, it’s an excellent opportunity to piece different object-oriented concepts together. This will let us design a system to extend the WordPress REST API!

Continue reading Designing a system: WordPress REST API endpoints

2017 in review: YOLO

2017 is coming to a close and with it comes the shower of yearly retrospectives. Well, I’m no different from everyone else in that regard! I did my first year in review two years ago covering 2012-2015. And I also did one last year for 2016 only.

If this is the first year in review of mine that you read, you should know that I do them for transparency. I want a historical record of what I’ve done that’s as faithful as I can make it. That means writing it down as close to the time that it happened as possible. I don’t keep a journal (nor do I want to) so this is as close as I’ll get to that.

It’s also a way for me to keep track of my progress towards where I’d like to see myself. I don’t keep a yearly goal list or anything like that. But I definitely have a vision of where I’d like to be and whether I made progress towards it or not.

Needless to say, that this article is more for me than for you. But I think there’s always something to learn from other people’s life experiences. (That’s why I love documentaries like “Abstract” and “Chef’s table“.) I hope that me sharing this helps you through your own journey through life.

Continue reading 2017 in review: YOLO