我正在为主题和get_option()
用于检索设置的仅返回string(0) ""
即使有复选框字段。我想要的是检索设置,以便使用它们来确定是否应使用选中/取消选中复选框checked()
. 以下是相关代码:
function theme_settings_init(){
register_setting(\'theme_settings\', \'theme_settings\', \'sanitize_settings\');
add_settings_section(\'general_settings\', \'General Settings\', \'general_settings\', \'theme_settings.php\');
function general_settings(){}
$home_blocks_args = array(
\'type\' => \'checkbox\',
\'id\' => \'home_blocks_checkbox\',
\'name\' => \'home_blocks_checkbox\',
\'desc\' => \'Toggle the home blocks section on the front page\',
\'std\' => \'\',
\'label_for\' => \'home_blocks_checkbox\',
\'class\' => \'settings_field\'
);
add_settings_field(\'display_home_blocks\', \'Display Home Blocks\', \'display_settings_field\', \'theme_settings.php\', \'general_settings\', $home_blocks_args);
function display_settings_field($args){
extract($args);
$option_name = \'theme_settings\';
$options = get_option($option_name);
switch($type){
case \'checkbox\':
$id = stripslashes($id);
$id = esc_attr($id);
?><input type="checkbox" id="<?php echo $id; ?>" name="<?php echo $option_name; ?>[<?php echo $id; ?>]" value="true" <?php echo $option_name[$id] == "true" ? \'checked\' : \'\'; ?> /><?php
echo ($desc != \'\') ? "<span class=\'description\'>$desc</span>" : "";
break;
}
}
}
add_action(\'admin_init\', \'theme_settings_init\');
function sanitize_settings($input){
return $input;
}
function theme_settings_add_page() {
add_theme_page( __(\'Theme Settings\'), __(\'Theme Settings\'), \'edit_theme_options\', \'theme_settings.php\', \'theme_settings_do_page\');
}
add_action(\'admin_menu\', \'theme_settings_add_page\');
function theme_settings_do_page(){ ?>
<div class="section panel">
<h1>Custom Theme Options</h1>
<form method="post" enctype="multipart/form-data" action="options.php">
<?php
settings_fields(\'theme_settings\');
do_settings_sections(\'theme_settings.php\');
?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e(\'Save Changes\') ?>" />
</p>
</form>