0

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

3 Answers 3

3

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() );
        }
    }
}
?>
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

0

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

2 Comments

Included, yet the same error,another not, i am calling this class from another class constructor in another file in the same dir....
both, main file and the admin file but yet the same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.