One of the projects I’ve been working on recently presents the user with a comprehensive set of options. As usual, the options take the form of a variety of different elements:
input
text fields,radio
buttons,select
elements,- and more.
In most cases, you should be familiar with initializing default values for all of these element types. Radio buttons may be the exception. And if they are, then you’ve no doubt run into a PHP notice when saving empty radio button values.
And having PHP notices is no good, right?
Regardless of if you’re using the WordPress Settings API or some custom serialization code, these notices can still show up. If you use Query Monitor, then you’ve likely seen this show up in your menu. Similarly, if you use the Console (or another application) to monitor your PHP logs, you’ve probably seen the error as well.
One place in which this can be tricky to deal with is when you’re working with radio buttons without an initial value.