Created
February 26, 2014 08:58
-
-
Save stefanbc/9226102 to your computer and use it in GitHub Desktop.
Add Checkbox option to General Settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) . '/>'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Stefan, this is great, but, do you know how to choose where the checkbox option sits on the page. For example how would I make it appear between New User Default Role and Timezone?