This post is part of a series on Sanitization with the WordPress Settings API. Here is Part 2.

Whenever we’re in the process of teaching a new idea to someone – be it if you’re a teacher, a TA, maybe a professor (I have no idea what this is like) – I’ve found that it always helps to take the approach from the absolute base case and then work up to something more advanced.

In the series on the WordPress Settings API that I’m currently working through, that was the plan; however, after last week’s final set of comments, I think the series is either going to be a little bit longer than expected, or is going to result in more questions than expected.

This is a good thing – the comments I received thus far ended up pre-empting some of the material that I was going to cover.

Pausing WordPress Settings API Validation

Pause on the WordPress Settings API

For example:

  1. Danny left a great comment about the redundancy of what we’re doing in terms of the redundancy for the `foreach` loop. If you’re looking to shortcut you’re learning of PHP, then read this comment and maybe take a look at the PHP manual.
  2. David left another great comment regarding the `array_map` PHP function that utilizes PHP closures (of course, this isn’t eligible for all versions of PHP) but it’s worth a read for those of you who are using compatible versions.
  3. Rick left a comment about the work he’s done in prior work and how it’s applicable to what we’re doing in the WordPress Settings API.

To be clear: These comments are fantastic and I love seeing them. The only thing that the adds to the series is that some of the upcoming content maybe redundant for those of you who are looking to learn as much as you can about the data sanitization aspect.

But that’s okay! I asked for this, right?

That said, this is one method that I’ve found to be very effective. If other people chime in with their own comments linking to other code, be sure to review it – you (and I!) may learn something even better.

And that’s the great thing about having smart, engaged readers who offer up suggestions before you even get through all of the content.

So What’s Next?

Right now, the plan is still to continue as normal:

  • We’re going to look at some of the redundancies in code
  • How we can handle required cases and error messages
  • How to prevent data from being saved until the user has entered all required information

So this is a bit of a weird, unplanned post and it doesn’t really contained a lot of educational material on it’s own, but I do ask that you read what the previous commenters shared as it’s valuable material that, at the very least, will help us move along as we continue to work through this series.

Thanks to those who are reading, comments, and so on. And so while I’m hitting pause (until tomorrow, that is), if there is anything confusing up to this point, feel free to leave a comment so that I can try to address it in future posts.

Until Part 4.

Series Posts

  1. Sanitizing Multiple Values with the WordPress Settings API
  2. Sanitizing Arrays: The WordPress Settings API
  3. On Pause: The WordPress Settings API
  4. Refactoring Input Sanitization with The WordPress Settings API
  5. Validating Input via the WordPress Settings API
  6. Validation and Sanitization in the WordPress Settings API
Share:

Leave a Reply