开发者

wordpress plugin : Call to undefined function add_menu_page()

开发者 https://www.devze.com 2023-03-28 01:00 出处:网络
I am working on a wordpress plugin and i decided to use OOP instead of functional programming,however;I am receiving this weird error:

I am working on a wordpress plugin and i decided to use OOP instead of functional programming,however;I am receiving this weird error:

Error Message:

Call to undefined function add_menu_page() while am pretty sure everything is working as intended

The Code:

class bdmin{

    public function __construct(){
        add_action('admin_menu', $this->create_admin_menu());
    }

    public function create_admin_menu(){
        // Create NEW top-level menu
        add_menu_page('bdmin Settings', 'bdmin Settings', 'administrator', __FILE__, array( &$this, 'create_admin_page'));

        // Register our Settings
        add_action( 'admin_init', $this->register_admin_settings() );
    }
}

and i initiate the code with $admin = new 开发者_开发知识库bdmin();

Best Regards


This should remove the error:

<?php
    if(!empty($value['id'])) {
    class bdmin{
        public function __construct(){
            add_action('admin_menu', $this->create_admin_menu());
        }
        public function create_admin_menu(){
            // Create NEW top-level menu
            add_menu_page('bdmin Settings', 'bdmin Settings', 'administrator', __FILE__, array( &$this, 'create_admin_page'));
            // Register our Settings
            add_action( 'admin_init', $this->register_admin_settings() );
        }
    }
}
?>


To solve this problem all I needed to do is invoke a function named add_action with these parameters.

add_action('admin_menu', array( &$this , 'create_admin_menu'));


Make sure you include the header file at the top so you can make WP function calls

<?php require('{correct_path}/wp-blog-header.php');
0

精彩评论

暂无评论...
验证码 换一张
取 消