我编写了一个简单的测试代码,用于测试使用设置API保存数据,但它似乎不起作用。这真的快把我逼疯了。请帮我指出问题所在,谢谢!
function test_add_options_page() {
add_menu_page(
\'Test Save Option\',
\'Test Save\',
\'manage_options\',
\'testpage\',
\'test_save_page\'
);
}
add_action(\'admin_menu\', \'test_add_options_page\');
function test_save_page() {
?>
<form action="options.php" method="post">
<?php
settings_errors();
settings_fields(\'testpage\');
do_settings_sections(\'testpage\');
submit_button();
?>
</form>
<?php
}
function test_add_settings() {
add_settings_section(
\'section_1\',
\'Section 1\',
\'output_section_desc\',
\'testpage\'
);
add_settings_field(
\'field_id\',
\'Field Title\',
\'add_field_callback\',
\'testpage\',
\'section_1\'
);
register_setting(\'testpage\', \'testpage\');
}
add_action(\'admin_init\', \'test_add_settings\');
function output_section_desc() {
echo \'Section Description...\';
}
function add_field_callback() {
echo \'<input type="test" id="field_id" />\';
}