设置API保存的值未显示在下拉框中

时间:2015-07-10 作者:defiant

我正在尝试使用设置API将值保存到选项中。这个东西正在保存,但无论我做什么,它都会重置下拉框。因此,保存的值不会显示在下拉框中。

我使用var\\u dump()来显示选项的内容,它显示以前保存的值,没有任何问题。谁能帮帮我吗?以下是屏幕截图:enter image description here代码如下:

add_action(\'admin_init\', \'twmm_init\');
function twmm_init() {
  register_setting(\'twmm_options_group\', \'twmm_options\', \'twmm_options_validation\');
  add_settings_section(\'twmm_setting_section\', \'TWMM Settings\', \'twmm_section_callback\', \'twmm-settings.php\');
  add_settings_field(\'twmm_on_off\', \'Enable or disable the maintenance mode here:\', \'twmm_status\', \'twmm-settings.php\', \'twmm_setting_section\');
  add_settings_field(\'twmm_permission_lvl\', \'Minimum permission level needed to access the site:\', \'twmm_permission\', \'twmm-settings.php\', \'twmm_setting_section\');
}
function twmm_status() {
  $options = get_option(\'twmm_options\');//check if maintenance mdoe is enabled or disabled
  echo "<select id=\'twmm_on_off\' name=\'twmm_options[twmm_on_off]\'>";
    echo "<option value=\'Enable\'" . selected( $options[\'twmm_on_off\'], \'enabled\') . ">Enable</option>";
    echo "<option value=\'Disable\'" . selected( $options[\'twmm_on_off\'], \'disabled\') . ">Disable</option>";
  echo "</select>";
}
function twmm_permission() { //drop down box for user roles
  $options = get_option(\'twmm_options\');
  echo "<select id=\'twmm_permission_lvl\' name=\'twmm_options[twmm_permission_lvl]\'>";
    echo "<option vaule=\'admin\'". selected( $options[\'twmm_permission_lvl\'], \'admin\')."> Admin </option>";
    echo "<option vaule=\'editor\'". selected( $options[\'twmm_permission_lvl\'], \'editor\')."> Editor </option>";
    echo "<option vaule=\'author\'". selected( $options[\'twmm_permission_lvl\'], \'author\')."> Author </option>";
    echo "<option vaule=\'contributor\'". selected( $options[\'twmm_permission_lvl\'], \'contributor\')."> Contributor </option>";
    echo "<option vaule=\'subscriber\'". selected( $options[\'twmm_permission_lvl\'], \'subscriber\')."> Subscriber </option>";
  echo \'</select>\';
}

1 个回复
最合适的回答,由SO网友:webtoure 整理而成

你拼错了valuevaule:

echo "<option vaule=\'editor\'". selected( $options[\'twmm_permission_lvl\'], \'editor\')."> Editor </option>";

结束