0

Im developing my first plugin, and the wordpress shows the following error when I try to access to the wp-admin: Fatal error: Uncaught Error: Call to undefined function settings_fields() in .../plugins/wtdomcheck/admin/html/settings.php:25

plugin file 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' );
}
..
..

plugin file wtdomcheck_admin.php

..
..
require_once WTDOMCHECK_PLUGIN_DIR.'admin/class/class-admin.php';

if ( class_exists(admin) ) {

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

}
..
..

plugin file class-admin.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';
    }

plugin file settings.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">
0

Nevermind guys,

I found the problem by myself..

Original and wrong code:

$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
            ]
        ];

Corrected line:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.