我知道这是一个常见的错误,但我还没有遇到任何行之有效的解决方案。我正在创建一个使用自定义帖子类型的插件,并且在CPT菜单下有一个设置页面。设置页面显示良好,但当我去保存设置时,会出现错误ERROR: options page not found
. 这是我的设置类:
<?php namespace SAW\\Hours;
class Settings {
private $view;
public function __construct( $view ) {
$this->view = $view;
add_action( \'admin_menu\', array( $this, \'submenu\' ) );
add_action( \'admin_init\', function () {
add_settings_section(
\'saw_hours\',
\'Hours Settings\', // Title
array( $this, \'settings\' ),
\'saw_hours_settings\'
);
} );
}
public function submenu()
{
add_submenu_page(
"edit.php?post_type=saw_hours", // Parent slug
"Settings", // Page title
"Settings", // Menu title
"activate_plugins", // Role required
\'saw_hours_settings\', // Menu slug
array($this->view, \'admin\'));
}
public function settings()
{
// API key setting
register_setting(
\'saw_hours\',
\'saw_hours_api_key\'
);
add_settings_field(
\'saw_hours_api_key\',
\'Set API Key:\',
function(){
$clientId = get_option(\'saw_hours_api_key\');
echo \'<input type="text" name="saw_hours_api_key" value="\' . $clientId . \'" >\';
},
\'saw_hours_settings\',
\'saw_hours\'
);
// Client ID setting
register_setting(
\'saw_hours\',
\'saw_hours_client_id\'
);
add_settings_field(
\'saw_hours_client_id\',
\'Set Client ID:\',
function(){
$clientId = get_option(\'saw_hours_client_id\');
echo \'<input type="text" name="saw_hours_client_id" value="\' . $clientId . \'" >\';
},
\'saw_hours_settings\',
\'saw_hours\'
);
}
}
这是表单页:
<form method="POST" action="options.php">
<?php settings_fields( \'saw_hours\' ); ?>
<?php do_settings_sections( \'saw_hours_settings\'); ?>
<?php submit_button(); ?>
</form>
我不知所措,任何帮助都将不胜感激。