WordPress Widgets: Refactoring, Part 10 And now, we start adding sanitization and serialization functionality into the WordPress Widget Boilerplate.

As far as the WordPress Widget Boilerplate refactoring goes, we’re at a good place. A lot of work has been done such that introducing new classes, features, and functionality should be much easier.

And not only that: It should be easier to follow.

Thanks the work in the last post, we have a lot of work to build off of – namely, an basic administrative interface.

WordPress Widget: UI Improved

Finally, the last post said:

Over the next few articles, this is going to continue to evolve but, as you can see, we’re making sure that we have a single base class of functionality for talking with WordPress and a class specifically for rendering the administrative form.

And that’s where we’re going to pick up in this article. Specifically, we’re going to look at sanitizing and serializing the data as well as retrieving the data saved in the widget.

The WordPress Widget Boilerplate: Refactoring Part 10

Refactoring The UI

Before we get into serialization, there’s some minor work that we’re going to need to do to our administrative view. Recall from previous posts in the series that we’ve built a form that accepts:

  • a title,
  • some content,
  • and a checkbox.

⚠️ 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.

Retrieving Data

Notice that although the functionality seems incomplete for this (since the unsanitized data is still displayed), we’re focused on making sure that we’re writing classes with cohesion, responsibility, and that aren’t tightly coupled.

We’re going to iterate on this a bit more in the next post. So study the code above, implement it if that’s what you’ve been doing, and we’ll go from there in the next post.