无法识别函数SETTINGS_FIELS()(未捕获错误:调用未定义的函数SETINGS_FIELS())

时间:2019-02-03 作者:Ezequiel Cattaneo

我正在开发我的第一个插件,当我尝试访问wp admin时,wordpress显示以下错误:致命错误:未捕获错误:调用中未定义的函数settings\\u fields()/插件/wtdomcheck/admin/html/settings。菲律宾比索:25

插件文件wtdomcheck。php

..
..
define( \'WTDOMCHECK_PLUGIN_DIR\',    plugin_dir_path( __FILE__ ) );
..
..
if ( is_admin() ) {
  require_once( \'admin/wtdomcheck_admin.php\' );
} else {
  require_once( \'public/wtdomcheck_front.php\' );
}
..
..
插件文件wtdomcheck\\u admin。php
..
..
require_once WTDOMCHECK_PLUGIN_DIR.\'admin/class/class-admin.php\';

if ( class_exists(admin) ) {

    $wtdomadmin = new admin();
    $wtdomadmin->register();

}
..
..
插件文件类管理。php
..
..
require_once \'api.php\';


class admin 
{
    public $pluginName;

    public $settings;

    public $pages = array();

    public $subpages = array();


    function __construct() 
    {
        $this->pluginName = plugin_basename( __FILE__ );

        $this->settings = new ApiWpadmin();

        $this->pages = [
            [
                \'page_title\' => \'WT Domain Check\', 
                \'menu_title\' => \'WTDomCheck\', 
                \'capability\' => \'manage_options\', 
                \'menu_slug\'  => \'wtdomaincheck\', 
                \'callback\'   => $this->LoadSettingTemplate(), 
                \'icon_url\'   => \'dashicons-store\', 
                \'position\'   => 117
            ]
        ];

        $this->subpages = [
            /*[
                \'parent_slug\'=> \'wtdomaincheck\',
                \'page_title\' => \'Settings\', 
                \'menu_title\' => \'Settings\', 
                \'capability\' => \'manage_options\', 
                \'menu_slug\'  => \'settings\',
                \'callback\'   => function() { echo \'<h1>Taxonomies Manager</h1>\'; },
            ]*/
        ];

        add_action( \'add_meta_boxes\', array( $this, \'LoadMetabox\') ); 

        add_action(\'edit_form_after_title\', array( $this, \'DelAllMetaboxes\') );

    }



    //
    // PARAM
    // Register all the actions and filters for the Admin area
    //
    public function register() 
    {
        //Call the concatenated API method to contruct the menu, and submenu
        $this->settings->AddPages( $this->pages )->WithSubPage( \'Settings\' )->AddSubPages( $this->subpages )->register();

        add_action(\'admin_init\', array($this, \'SaveSettings\') );

        add_filter( \'plugin_action_links_\'.WTDOMCHECK_PLUGIN_NAME, array($this->settings, \'AddCustomLinks\') );

        add_action("manage_posts_custom_column",  array( $this, \'EditColumns\') );

        add_filter("manage_edit-wt_whoisservers_columns", array( $this, \'FilterColumns\') );
    }


    //
    // PARAM
    // Loads the template that shows the settings page
    //
    public function LoadSettingTemplate()
    {
        include_once WTDOMCHECK_PLUGIN_DIR.\'admin/html/settings.php\';
    }
插件文件设置。php
<?php

//require_once \'/www/lr-webstower.com.ar/htdocs/wp-load.php\';

//array($field_type, $echo_string, $id, $rows)
$fields = array(
    array(\'checkbox\',\'Field 1\',\'fieldname1\',\'1\'),
    array(\'checkbox\',\'Field 2\',\'fieldname2\',\'1\'),
    array(\'textarea\',\'Field 3\',\'fieldname3\',\'3\'),
    array(\'textarea\',\'Field 4\',\'fieldname4\',\'3\'),
    array(\'textarea\',\'Field 5\',\'fieldname5\',\'3\'),
    array(\'text\',\'Field 6\',\'fieldname6\',\'1\'),
    array(\'text\',\'Field 7\',\'fieldname7\',\'1\'),
    array(\'text\',\'Field 8\',\'fieldname8\',\'1\'),
    array(\'text\',\'Field 9\',\'fieldname9\',\'1\'),
    array(\'text\',\'Field 10\',\'fieldname10\',\'1\'),
    array(\'echo\',\'Message 1\',\'\',\'1\')
);

?>
<div class="wrap">
    <h2><?php _e(\'WTDomCheck Setup\', \'wtdomcheck\') ?></h2>
    <form method="post" action="options.php">

        <?php settings_fields( \'wtdomcheck-settings\' ); ?>

        <div id="poststuff">
            <div class="postbox">
            <h3> <?php _e(\'Result Settings\', \'wtdomcheck\') ?></h3>
                <div class="inside">
                    <table class="form-table">

1 个回复
SO网友:Ezequiel Cattaneo

别担心伙计们,

我自己发现了这个问题。。

原始和错误代码:

$this->pages = [
            [
                \'page_title\' => \'WT Domain Check\', 
                \'menu_title\' => \'WTDomCheck\', 
                \'capability\' => \'manage_options\', 
                \'menu_slug\'  => \'wtdomaincheck\', 
                \'callback\'   => $this->LoadSettingTemplate(), 
                \'icon_url\'   => \'dashicons-store\', 
                \'position\'   => 117
            ]
        ];
已更正的行:

\'callback\'   => array($this,\'LoadSettingTemplate\'), 

相关推荐

Testing Plugins for Multisite

我最近发布了一个WordPress插件,它在单个站点上非常有效。我被告知该插件在多站点安装上不能正常工作,我理解其中的一些原因。我已经更新了代码,现在需要一种方法来测试更新后的代码,然后才能转到实时客户的多站点安装。我有一个用于测试的WordPress安装程序的单站点安装,但需要在多站点安装上进行测试。根据我所能找到的唯一方法是在网络上至少有两个站点来安装整个多站点安装,以测试我的插件。设置WordPress的整个多站点安装是插件开发人员的唯一/首选方式,还是有更快的测试环境可用。