我有两个选项页:General Options > MyOptionPage1
和CustomPostType > MyOptionPage2
两者都有一个表单,但单击后Save
在第二个选项页中,我进入404页。
这是我的代码(文件customposttype-options.php
包含在我的插件中):
<?php
function customposttype_options_menu()
{
add_submenu_page( "edit.php?post_type=customposttype", "Impostazioni customposttype", "Impostazioni customposttype", "manage_options", "impostazioni_customposttype_page", \'customposttype_options\');
}
function customposttype_options()
{
?>
<div class="wrap">
<h2>Impostazioni customposttype</h2>
<form method="post" action="customposttype-options.php">
<?php settings_fields( \'impostazioni_customposttype\' ); ?>
<?php do_settings_sections( \'impostazioni_customposttype\' ); ?>
<label for="colore_sfondo">Colore sfondo</label>
<input type="text" id="colore_sfondo" name="colore_sfondo" value="<?php echo esc_attr( get_option(\'colore_sfondo\') ); ?>">
<?php submit_button(); ?>
</form>
</div>
<?php
}
function register_customposttype_options() { // whitelist options
register_setting("impostazioni_customposttype", "colore_sfondo");
}
add_action( \'admin_menu\', \'customposttype_options_menu\' );
add_action( \'admin_menu\', \'register_customposttype_options\');
我试图改变
action
表单的属性,但没有更改(
action=""
, 无操作,
admin_url(\'customposttype-options.php\')
, ...).第一个工作选项页完全相同,但名称空间已更改(因此,
settings_fields( \'impostazioni_generaloptions\' );
).