简体   繁体   中英

Class not found in Php when trying to extends a class

I am writing a plugin where i have to extends a class from another php file. But i am getting Fatal error: Class 'EWWL_Admin_Init' not found .

Here is my main file code.

class Eden_Woocommerce_WL_Admin {

    private static $instance = null;

    public static function getInstance() {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function __construct() {
        $this->includes();
        $this->add_menu_page();
    }

    private function includes() {
        include_once( EWCWL_PLUGIN_DIR . '/includes/admin/ewwl-admin-menu.php' );
        include_once( EWCWL_PLUGIN_DIR . '/includes/admin/ewwl-admin-init.php' );
    }

    private function add_menu_page() {
        EWWL_Admin_Init::getInstance();
        EWCWL_Admin_menu::getInstance();
    }
}

here is EWCWL_Admin_menu class

class EWCWL_Admin_menu extends EWWL_Admin_Init {

    private static $instance = null;

    public static function getInstance() {
        if(is_null(self::$instance)){
            self::$instance = new self();
        }
    }

    public function __construct($args = array()) {

        if (!empty($args)) {
            $this->settings = $args;

            if (isset($this->settings['create_menu_page']) && $this->settings['create_menu_page']) {
                add_action('admin_menu', array($this, 'add_ewwl_menu_page'));
            }
        }
    }

    public function add_ewwl_menu_page() {
        $position = apply_filters('ewcwl_plugins_menu_item_position', '62.32');
        add_menu_page('plugin_panel', __('Menu title', 'ed-wcwl'), 'manage_options', 'ed_plugin_panel', NULL, '', $position);
    }

}

Here is EWWL_Admin_Init class

class EWWL_Admin_Init {

    private static $instance = null;

    public static function getInstance() {
        if( is_null(self::$instance) ){
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function __construct() {

    }

}

May be i am missing something. Thanks in advance.

It happened because EWWL_Admin_Init didn't included before EWCWL_Admin_menu . Swapping two lines

include_once( EWCWL_PLUGIN_DIR . '/includes/admin/ewwl-admin-init.php' );
include_once( EWCWL_PLUGIN_DIR . '/includes/admin/ewwl-admin-menu.php' );

from Eden_Woocommerce_WL_Admin class solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM