WordPress settings API error when checkbox unchecked

Your problem is that you haven’t included a sanitization function as the third parameter to register_settings on line 111. When no sanitization provided WordPress deletes the value of the option and creates a new one based only on what is passed in $_POST. Since unchecked checkboxes are not sent by the browser at all you end up with $options['show_admin_dev'] being not set.

You should try to add sanitization which adds the value if it is not in the option

register_setting(
  'ccms_developer_options',
  'ccms_developer_options',
  'ccms_developer_sanit' 
);

function ccms_developer_sanit($newval) {
  if (!isset($newval['show_admin_dev'])) 
    $newval['show_admin_dev'] = 0;

  return $newval;
}

Leave a Comment