我正在制作一个Wordpress插件,我从管理设置页面开始,我有页面设置,在菜单栏中,我还向页面中添加了部分和字段,它们都工作正常,当我更改字段值并保存页面并刷新设置时,它们都是相同的,这告诉我它们正在保存。对的
现在,当我尝试调用设置时,我无法获得正确的值!在设置页面上,我有1个复选框和一个文本字段,我无法获取其中任何一个的值!
我用来获取值的代码如下:
<?php
if(get_option( \'main_dashboard_check\' ) ? get_option( \'main_dashboard_check\' ) : \'no\'){echo \'yes\';}else{echo \'no\';};
?>
当我将其用于任一字段时,得到相同的值:
var_dump(get_option(\'main_text\'));
这将为复选框和文本字段显示“bool(false)”。
在管理页面上,以下是字段:
<?php
function admin_init() {
register_setting( $this->settings_field, $this->settings_field, array($this, \'sanitize_theme_options\') );
add_option( $this->settings_field, Media_Press_Settings::$default_settings );
add_settings_section(\'mediapress_main\', \'\',
array($this, \'main_section_text\'), \'main_settings_page\');
add_settings_field(\'main_text\', \'Main Text\',
array($this, \'render_main_text\'), \'main_settings_page\', \'mediapress_main\');
add_settings_field(\'main_dashboard_check\', \'Title\',
array($this, \'render_main_checkbox\'), \'main_settings_page\', \'mediapress_main\',
array(\'id\' => \'main_dashboard_check\', \'value\' => \'yes\', \'text\' => \'Test Checkbox\') );
}
function render_main_checkbox($args) {
$id = \'mediapress_options[\'.$args[\'id\'].\']\';
?>
<input name="<?php echo $id;?>" type="checkbox" value="<?php echo $args[\'value\'];?>" <?php echo isset($this->options[$args[\'id\']]) ? \'checked\' : \'\';?> /> <?php echo " {$args[\'text\']}"; ?>
<?php
}
?>
这是呈现管理页面的一些代码,它是复选框和文本字段,当我尝试获取其中一个的值时,什么都没有发生,这是我用来获取值的代码
<?php
if(get_option( \'main_dashboard_check\' ) ? get_option( \'main_dashboard_check\' ) : \'yes\'){echo \'yes\';}else{echo \'no\';};
?>
什么都没发生!它总是打印出文本“否”。var转储刚刚显示
bool(false)有人能帮我吗?非常感谢
非常感谢和抱歉,如果我听起来很笨,我是PHP新手!