Search code examples
phpoopwordpressplugins

wordpress plugin : Call to undefined function add_menu_page()


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 I 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();


Solution

  • 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'));