register_setting not save checkbox

Question

To understand the Settings API I’m creating a custom settings page for a custom plugin. I have some trouble to save the settings, I have a single checkbox to test if the code works well, but if I check it and then click save button it will not be saved and didn’t remain checked. What’s wrong with the code? Is possible to use the - caratchers for the ID of a settings field or section?

register_setting(
      'general', // Settings section ID
      'show-countdown' // Settings field ID - maybe the problem?
    );

The code for the checkbox is the following.

<input type="checkbox" class="" id="show-countdown" name="show-countdown" value="1" <?php checked(1, get_option('show-countdown'), false); ?> />
    <label for="show-countdown"><?php echo $args[0]; ?></label>

NB: the register_settings_section() and register_settings_field() are working fine, this is why I omit the code.

0
, , sialfa 2 years 2020-01-14T08:38:52-05:00 0 Answers 70 views 0

Leave an answer

Browse
Browse