听起来您的一些设置API调用有误。您的下拉输入是在add\\u settings\\u field()的回调中创建的。需要告知每个设置字段它是哪个设置部分的一部分,然后您的选项页面通过do\\u settings()函数告知它需要显示哪些设置部分。下面是一个使用复选框的简短代码示例(省略了一些回调函数,但所有回调函数都必须是有效函数,即使将其设为空函数):
function plugin_admin_init()
{
//Register your plugin\'s options with the Settings API, this will be important when you write your options page callback, sanitizing callback omitted
register_setting( \'plugin_options_group\', \'plugin_options_name\', \'sanitizing_callback\' );
//Add a new settings section, section callback omitted
add_settings_section( \'section_id\', \'Plugin Settings\', \'section_callback\', \'section_options_page_type\' );
//Add a new settings field
add_settings_field( \'plugin_checkbox\', \'Send automated emails?\', \'field_callback\', \'section_options_page_type\', \'section_id\' );
}
add_action(\'admin_init\', \'plugin_admin_init\');
function field_callback()
{
//The key thing that makes it a checkbox or textbox is the input type attribute. The thing that links it to my plugin option is the name I pass it.
echo "<input id=\'plugin_checkbox\' name=\'plugin_options_name[plugin_checkbox]\' type=\'checkbox\' value=\'true\' />"
}
function setup_menu()
{
add_menu_page(\'Page Name\', \'Page Name\', \'user_capability_level\', \'page_slug\', \'page_callback\');
}
add_action(\'admin_menu\', \'setup_menu\');
function page_callback()
{
?>
<div class=\'wrap\'>
<h2>Page Name</h2>
<form method=\'post\' action=\'options.php\'>
<?php
//Must be same name as the name you registered with register_setting()
settings_fields(\'plugin_options_group\');
//Must match the type of the section you want to display
do_settings_section(\'section_options_page_type\');
?>
<p class=\'submit\'>
<input name=\'submit\' type=\'submit\' id=\'submit\' class=\'button-primary\' value=\'<?php _e("Save Changes") ?>\' />
</p>
</form>
</div>
<?php
}
?>