• Resolved benoitf92

    (@benoitf92)


    Hi,

    I’m trying to ad a checkbox to activate easily my maintenance page plugin.

    I’m trying to put it in Settings -General page.

    I have writted the following code:

    function maintenance_options()
    	{
    		add_settings_section("maintenance_section", "Maintenance Options", "maintenance_options_content", "general");
    		add_settings_field("maintenance_field", "Activate Maintenance Mode", "maintenance_form_element", "general", "maintenance_section");
    		register_setting("maintenance_section", "maintenance_field");
    	}
    
    	function maintenance_options_content()
    	{
    		echo "Maintenance settings section";
    	}
    
        function maintenance_form_element()
        {
            ?>
                <input type="checkbox" id="maintenance_field" name="maintenance_field" value="1" ' . checked(1, get_option('maintenance_field'), false) . '/> Checked to activate maintenance mode
            <?php
        }
    
        add_action("admin_init", "maintenance_options");

    But When I checked it and save saettings this is not saved.

    How can I realy add my new settings into this page ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Two things. The option group when registering your setting should be “general”, the page where your setting resides. The docs aren’t very clear about this.

    The other is you forgot to delimit the PHP portion of the HTML output for the field, and echo out the result of checked(). Try this:
    <input type="checkbox" id="maintenance_field" name="maintenance_field" value="1" <?php echo checked( 1, get_option('maintenance_field'), false ); ?> /> Checked to activate maintenance mode

    Thread Starter benoitf92

    (@benoitf92)

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to add checkbox in existing settings page’ is closed to new replies.