humanmade/Custom-Meta-Boxes — pull request #229 by mattheu (2014-07-31 23:02:06+00:00)
Title: Inverse checkbox

I have had a few situations recently where I have required a default value of 'checked' for a checkbox field, but to allow users to uncheck. Mainly for UX issues - but I understand the rationale.

eg "Show breadcrumbs"

But this is really impossible to do. If the defalult value is used, it causes the checkbox never to appear unchecked. This is because we only store `checked` values rather than save a `false` value. An unchecked box means `no value` and the default of true is used, which shows as checked. Confusing!

The way I have dealt with this in the past is to store the inverse - but keep the label text the same. For the above example the label would still read "show breadcrumbs" but the meta key would really be "hide_breadcrumbs" and we would only show as checked if breadcrumbs were **not** hidden. It would also requre similar logic on saving - save if **not** checked - instead of save if **is** checked.

This pull request implements this inverse logic if an `inverse` arg is passed.

Any thoughts?

Is this overly complex?