Forums

Fatal error: Call to undefined function: add_management_page().... (5 posts)

  1. nathan3192
    Member
    Posted 4 years ago #

    I'm trying to develop my own plugin but when I try to activate it it's telling me add_management_page() is an undefined function the full error is "Fatal error: Call to undefined function: add_management_page() in /home/techjaws/public_html/wp-demo/wp-content/plugins/download_hits/download_hits.php on line 30"

  2. moshu
    Member
    Posted 4 years ago #

    So, the obvious question is: where is that function defined?
    In the stable WP version it is in wp-admin/includes/plugin.php
    But your other thread says you are on a beta version... where big changes have been made in the admin area.

    If you are working with code, you should keep in mind all this stuff.

  3. nathan3192
    Member
    Posted 4 years ago #

    I'm using the latest stablest version of WordPress, I read on the codex about making a plugin with a manage page, and copied the code which they used.
    I'll try to include the file you mentioned above though, thanks

  4. nathan3192
    Member
    Posted 4 years ago #

    hmm.. I did a require_once on the file you said above but It just gave this error
    Warning: main(../../../wp-admin/includes/plugin.php) [function.main]: failed to open stream: No such file or directory in /home/techjaws/public_html/wp-demo/wp-content/plugins/download_hits/download_hits.php on line 10

  5. jsdalton
    Member
    Posted 3 years ago #

    I had this same problem. Even though this thread is eight months old, I figured I'd update it to help anyone who stumbles upon it so they don't have to figure it out for themselves like I did.

    So, my guess is you had a plugin page, e.g. foo.php, in which you tried to do:

    <?php
    add_management_page('Test Manage', 'Test Manage', 8, 'testmanage', 'mt_manage_page');

    // mt_manage_page() displays the page content for the Test Manage submenu
    function mt_manage_page() {
    echo "<h2>Test Manage</h2>";
    }

    ?>

    Which gives the error:

    Fatal error: Call to undefined function add_management_page() in /Library/WebServer/htdocs/jsdalton.www.ere.net/wp-content/plugins/ere-live/ere-live.php on line 11

    So what you have to do to make this work is wrap the add_management_page in a "callback" function, which is then attached to the add_action() function, as follows:


    <?php
    add_action('admin_menu', 'mt_add_pages');

    function mt_add_pages(){
    add_management_page('Test Manage', 'Test Manage', 8, 'testmanage', 'mt_manage_page');
    }

    // mt_manage_page() displays the page content for the Test Manage submenu
    function mt_manage_page() {
    echo "<h2>Test Manage</h2>";
    }
    ?>

    See how I just created a new function mt_add_pages() which I wrapped around the original call to add_management_page()? And then I just referenced that function in the add_action() call above.

    I didn't spend any time looking at the internals, but I assume add_action grabs all the necessary include files etc. in order to allow your call to add_management_page() to work.

    Anyhow, this should do the trick for you.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.