Created
July 22, 2015 19:00
-
-
Save 9ete/2719bf16e86d3e0b74eb to your computer and use it in GitHub Desktop.
WordPress Checkbox Admin Setting Functions
This file contains hidden or 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 | |
// register setting | |
function ma_theme_init() { | |
register_setting( 'ma-settings-group', 'ma_show_setting' ); | |
add_settings_section( 'ma_setting_section', 'MA Settings:', 'ma_setting_section_callback', 'wpsettings' ); | |
add_settings_field( 'ma_setting_checkbox', 'CheckBox', 'ma_setting_checkbox_callback', 'wpsettings', $section = 'ma_setting_section'); | |
} | |
add_action('admin_init', 'ma_theme_init'); | |
function ma_setting_section_callback() { | |
} | |
function ma_setting_checkbox_callback() { | |
$option = get_option( 'ma_show_setting' ); | |
$html = '<input type="checkbox" id="ma_show_setting" name="ma_show_setting" value="1"' . checked( 1, $option, false ) . '/>'; | |
$html .= '<label for="ma_show_setting">Check to check the box.</label>'; | |
echo $html; | |
} | |
// Create Theme Options Page | |
function ma_add_theme_page() { | |
add_theme_page( | |
__('Theme Options', 'wpsettings'),//Page Title | |
__('Theme Options', 'wpsettings'),//Menu Title | |
'edit_theme_options',//Capability | |
'ma-settings',//Slug | |
'ma_theme_options_page'//Callback function | |
); | |
} | |
add_action('admin_menu', 'ma_add_theme_page', $priority = 10, $accepted_args = 1 ); | |
function ma_theme_options_page() { | |
?> | |
<div class="wrap"> | |
<h2>Theme Options - <?php echo wp_get_theme(); ?></h2> | |
<form method="post" action="options.php"> | |
<?php | |
settings_fields( 'ma-settings-group' ); | |
do_settings_sections( 'wpsettings' ); | |
submit_button(); | |
?> | |
</form> | |
</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment