首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:当我试图保存在设置页面中所做的更改时,找不到选项页

错误:当我试图保存在设置页面中所做的更改时,找不到选项页
EN

WordPress Development用户
提问于 2019-02-25 20:16:33
回答 1查看 1.4K关注 0票数 1

我在开发一个插件。一切都很好但突然间当我试图保存插件设置..。我发现的错误是页面选项没有找到。

我在找答案,但没有一个能弥补我的错误.下面是一些生成设置页面并将选项保存在数据库中的代码:

admin.php

代码语言:javascript
复制
 *
 * @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

代码语言:javascript
复制
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';
    }

?>

setings.php

代码语言:javascript
复制
                    WTBuildPillTabs($sections);
                    ?>
                
            

            
                
                    WTBuildPillPanes($sections);
                    ?>

当我安装插件时,选项记录将在wp_options表中创建。将显示“设置”页。但当我试图保存这些变化时..。未找到的选项页出现在屏幕上。

任何帮助都将不胜感激。

EN

回答 1

WordPress Development用户

发布于 2019-02-26 14:38:26

问题在我的文件settings.php (它呈现表单)中。看表格动作。它说action="options.php",然后settings_field()用正确的操作插入一个隐藏字段。但是WordPress优先处理表单操作,所以当提交表单时,WordPress尝试加载options.php,而不是在隐藏字段中加载正确的操作。

解决方案是什么?简单:

在表单action="options.php"中用action=""替换。

这个简单的补丁修复了错误。

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/329905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档