As far as refactoring the WordPress Widget Boilerplate is concerned – especially given how far we’ve come since the project started eight years ago – we’ve done a lot of work.

We’ve brought it up to a far more modern standard and we’re making it far easier to work with it such that building future widgets should be easier. And this is not only from the standard of the boilerplate but from an object-oriented standard so that maintenance and code quality is higher.

In the last post, we wrapped up much of the work for the administration area and are ready to begin our work on code for the front-end.

We said:

Next, we’re going to look at rendering content on the front-end. We’re nearing the end, of the refactoring of the Boilerplate but there’s just a bit more to do before we’re ready to merge it into the master branch of the codebase.

So in this post, we’re going to pick up there. Now if you’ve been following along up to this point then you should have everything you need from the develop branch.

If not, be sure to pull it as that’s where we’re going to pick up in the remainder of the post.

The WordPress Widget Boilerplate: Refactoring Part 12

Now when it comes to the front-end, it’s easy to think of the front-end as anything the user sees before them regardless of if it’s in the administrative area or not.

However, this series has been clear that we’re dividing what the user sees between the administrative area and the public-facing area of the site.

So what we’re going to be doing is working on the area of the code that renders information for the user on the public-facing area of the site. We’re going to start off by simply reading the information and displaying it.

Then in the next post, we’ll look at working with conditional logic regarding some of the options to see if there’s anything we need to do.

With that said, let’s move into the code.

⚠️ Hey, Wait!

Thanks for your interest in this article! Note that it’s available to members only. If you’d like to review this (and have access to all previous and future articles), check out the membership benefits.

Into the Final Refactor

The last thing we’re going to look at after this is tightening up some of the conditional logic along with a word about caching data (since we’re already doing a bit of that in earlier posts).

For now, though, feel free to toy around with what we have here along with the code that we haven’t included (like what can be displayed before or after the widget.

They’ve been deliberately left out of this example but they may not always be left out depending on the work you’re doing.