stefanbc
2/26/2014 - 8:58 AM

Add Checkbox option to General Settings

Add Checkbox option to General Settings

<?php
$new_general_setting = new new_general_setting();
 
class new_general_setting {
    function new_general_setting( ) {
        add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
    }
    function register_fields() {
        register_setting( 'general', 'OPTION_NAME', 'esc_attr' );
        add_settings_field('OPTION_NAME', '<label for="OPTION_NAME">'.__('OPTION_LABEL_TEXT' , 'OPTION_NAME' ).'</label>' , array(&$this, 'fields_html') , 'general' );
    }
    function fields_html() {
        echo '<input type="checkbox" id="OPTION_NAME" name="OPTION_NAME" value="1" ' . checked(1, get_option('OPTION_NAME'), false) . '/>';
    }
}
?>