我正在开发一个插件。。。一切都很好,但突然当我试图保存插件设置时。。。我发现了一个错误,该错误表示找不到页面选项。。
我在寻找一些答案,但没有一个解决我的错误。。。下面是生成设置页面并将选项保存在数据库中的一些代码:
admin.php
<?php
/**
*
* This file contains the necesary functions to display the admin area of the plugin
*
* @author Ezequiel Cattaneo <[email protected]>
*
* @link https://webstower.com.ar/wtdomcheck
* @since 1.0.0
*
**/
require_once WTDOMCHECK_PLUGIN_DIR.\'admin/class/class-admin.php\';
$wtdomadmin = \'\';
//All the magic is done here!
if ( class_exists(\'admin\') ) {
$wtdomadmin = new admin();
$wtdomadmin->WTRegister();
}
?>
class_admin.php
function __construct()
{
//Instantiate the API that will construct our admin pages
$this->settings = new ApiWpadmin();
//Array of pages to create
$this->pages = [
[
\'page_title\' => \'My plugin settings page\',
\'menu_title\' => \'Settings page\',
\'capability\' => \'manage_options\',
\'menu_slug\' => \'wtdomaincheck\',
\'callback\' => array($this, \'WTLoadSettingTemplate\'),
\'icon_url\' => \'dashicons-admin-generic\',
\'position\' => 117
]
];
//Register the settings in the database
add_action(\'admin_init\', array($this, \'WTSaveSettings\'));
}
//
// PARAM
// Register all the actions & filters for wp-admin
//
public function WTRegister()
{
$this->settings->
WTAddPages( $this->pages ) ->
WTWithSubPage( \'Dashboard\' ) ->
WTAddSubPages( $this->subpages ) ->
WTRegister();
}
//
// PARAM
// Register the settings values in the database
//
public function WTSaveSettings()
{
$wt_options = array (
\'display-on-free\' => $_POST[\'display-on-free\'],
\'display-on-registered\' => $_POST[\'display-on-registered\'],
\'display-on-invalid\' => $_POST[\'display-on-invalid\'],
\'before-whois-output\' => $_POST[\'before-whois-output\'],
\'after-whois-output\' => $_POST[\'after-whois-output\'],
\'callurl\' => $_POST[\'callurl\'],
\'varname\' => $_POST[\'varname\'],
\'resp-free-domain\' => $_POST[\'resp-free-domain\'],
\'resp-registered-domain\'=> $_POST[\'resp-registered-domain\'],
\'resp-invalid-domain\' => $_POST[\'resp-invalid-domain\'],
\'custom-css\' => $_POST[\'custom-css\'],
\'license-key\' => $_POST[\'license-key\'],
\'style-box-bgcolor\' => $_POST[\'style-box-bgcolor\'],
\'style-www-color\' => $_POST[\'style-www-color\'],
\'style-button-color\' => $_POST[\'style-button-color\'],
\'style-button-bgcolor\' => $_POST[\'style-button-bgcolor\'],
\'style-result-color\' => $_POST[\'style-result-color\'],
\'style-result-bgcolor\' => $_POST[\'style-result-bgcolor\']
);
if (isset($_POST[\'enable-multiple-search\']))
$wt_options[] = array(\'enable-multiple-search\' => $_POST[\'enable-multiple-search\'] );
if (isset($_POST[\'show-www\']))
$wt_options[] = array(\'show-www\' => $_POST[\'show-www\'] );
if (isset($_POST[\'show-whois-output\']))
$wt_options[] = array(\'show-whois-output\' => $_POST[\'show-whois-output\'] );
update_option( \'wtdomaincheck\', $wt_options );
}
//
// PARAM
// Loads the template that shows the settings page
//
public function WTLoadSettingTemplate()
{
require_once WTDOMCHECK_PLUGIN_DIR.\'admin/html/settings.php\';
}
?>
settings.php
<form method="post" action="options.php">
<?php settings_fields( \'wtdomaincheck\' ); ?>
<div class="row border">
<div class="col-3 border-right pt-3 pb-3">
<div id="pillTabs" class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<?php
//Build Pill Sections
echo $wtdomadmin->WTBuildPillTabs($sections);
?>
</div>
</div>
<div class="col-9 pt-3">
<div class="tab-content" id="v-pills-tabContent">
<?php
//Build Pill Sections
echo $wtdomadmin->WTBuildPillPanes($sections);
?>
</div>
</div>
</div>
<div class=\'form-group row mx-auto mt-3\'>
<div class="col-lg-12 pr-0">
<input type="submit" class="btn btn-primary float-right" value="<?php _e(\'Save Changes\') ?>" />
</div>
</div>
</form>
安装插件时,会在wp\\u options表中创建选项记录。将显示设置页面。。但是当我试图保存更改时。。。是屏幕上显示“找不到选项”页面的位置。。。
任何帮助都将不胜感激。