Software Engineering in WordPress, PHP, and Backend Development

Category: Articles (Page 47 of 258)

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

A Helper Function for Admin Notices

If you’re in the business of building plugins, or even themes for that matter, and are incorporating object-oriented practices into your work then you’re likely faced with serialization of some type. And one of the aspects of serialization that it requires some type of feedback for the user.

This can be a success message, a failure message, or a message simply warning the user that some went wrong or perhaps something should be updated.

Whatever the case, WordPress provides all of the facilities that we need; however, we can make it even easier on ourselves by writing a helper function for admin notices. It’s simple, too.

Continue reading

WordPress Widgets: Starting with Standards

The purpose of this series is to start doing a deeper dive into working with object-oriented programming in the context of WordPress.

And since the WordPress Widgets API is one of the APIs that does use object-oriented practices, it’s a logical place to start. Further, it will give us some foundational techniques that we can use to apply to future work as we see how to build more object-oriented projects on WordPress in future series.

So far, we’ve covered the following:

  1. WordPress Widgets: An Object-Oriented Approach. The Widgets API provides a solid litmus test and example of how to get started with object-oriented programming in WordPress.
  2. WordPress Widgets: How to Detect Object-Oriented Programming. The goal is to arm you with everything you need to detect object-oriented practices.

If you’re not caught up, now’s a great time to do so. And if you have, then you’ll recall from the last post, we ended with the following note:

That is, we’ll revisit the WordPress Widget Boilerplate and I’m going to be refactoring it in its current state to adopt more modern PHP standards.

To begin updating the WordPress Widget Boilerplate to follow said standards, we need to do a few things:

  1. create a branch from the existing boilerplate,
  2. install code quality tools,
  3. ensure our IDE is properly set up,
  4. and begin refactoring the code to said standards.

And that’s what we’re going to start doing with this post.

Continue reading

Simply Refactoring WordPress-Based Code

Back in 2011, I was doing a lot of reading on working with legacy code, code quality, and refactoring.

Refactoring WordPress-Based Code

There’s a quote by Martin Fowler (who literally wrote the book on refactoring) attributed to Uncle Bob that’s stuck with me – and I’m sure many, many programmers – ever since:

always leave the code behind in a better state than you found it

The thing about this particular idea is that I think it might sound a bit more idealistic until you really start to try to practice it in everything that you do.

That is, if you take it at face value it sounds like anytime you need to work on a codebase, then you need to leave the entire codebase better than when you found it. But the more I’ve tried to apply this rule in my day-to-day work, the more practical, the cleaner, and the more maintainable WordPress-specific code has become.

So when it comes to refactoring WordPress-based code, what does that look like?

Continue reading

Release Early: A Case for a Strong 1.0

I am not a fan of the “move fast and break things” mantra that Facebook used to hold and I don’t think there’s a reason to have to justify my opinion on that. I’m glad they’ve sense moved away from it (or appear to have – I don’t know what they do internally).

I am, however, a fan of the “Release Early” idea. Sometimes this is also coupled with “Release Often” so we get the near-infamous “Release Early, Release Often” phrase in the software development nomenclature.

I don’t necessarily think they have to go together.

But when it comes to the idea of “Release Early,” it seems that no matter what you release, if it’s not up to a customer’s expectation, then it’s no good.

And I get it. At least from that perspective.

But what if you’re a fellow software developer and have some insight on to how this kind of stuff works?

Continue reading

WordPress Widgets: How to Detect Object-Oriented Programming

If you’ve not read the first post in this series, I recommend it, as we’re starting to get into writing object-oriented code for WordPress through the use of the Widgets API.

The series is going to capture a few things:

  1. show you the basic skeleton of a widget and why it’s object-oriented,
  2. discuss what things you should be able to notice and why
  3. update the Widget Boilerplate directly on this site first and then push it out to GitHub,
  4. build a widget using the API with the boilerplate as the foundation for our work.

But before doing that, I want to make sure that everyone reading this is caught up on the core principles of object-oriented programming and has everything needed to build out an object-oriented solution for WordPress.

To that end, I recommend the following:

  1. Two Pillars of Object-Oriented Programming: Part 1 of 2
  2. Two Pillars of Object-Oriented Programming: Part 2 of 2
  3. Abstract Classes, Part 1 – Abstracting Behavior
  4. Abstract Classes, Part 2 – Abstract Classes and Interfaces
  5. The Independent WordPress Developer

If you’ve read all of that content, great. You’re going to be well-prepared for this post and the upcoming posts. If not, there may be some holes in the rest of what you’re about to read, but the gist of the post should be clear enough.

What’s The Deal, Exactly?

Here’s the thing: Last week, I shared a bit of code along with some information about the Widgets API. I’m going to be revisiting that a little bit more in this post before we get into the more coding intensive part for two reasons:

  1. I want everyone reading this to be on the same page as it relates to writing object-oriented code (at the very least, in this context),
  2. I recognize that people are coming from different backgrounds and I want to make sure we’re all on the same page as much as possible before proceeding.

If you have experience with writing object-oriented code, especially in an advanced capacity, this may seem simpler to you; otherwise, I hope this is going to arm you with everything you need to detect object-oriented practices not only concerning this API but when reading others’ code, too.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑