WordPress.org

Ready to get started?Download WordPress

Forums

How can I execute php scripts in my plugin folder? (4 posts)

  1. evanscode
    Member
    Posted 5 years ago #

    I created a plugin which requires several screens. Not all of these screens are accessible, or should be accessible from the dropdown menus.

    The URLs I'm trying to access look like this:

    wp-admin/admin.php?page=MyPlugin/Dashboard.php
    wp-admin/admin.php?page=MyPlugin/SubPageOne.php&id=123
    wp-admin/admin.php?page=MyPlugin/SubPageTwo.php&id=456

    MyPlugin/Dashboard.php has a link to it from a custom menu I've added. The two sub-pages do not.

    My problem is this:

    When I try to access the sub-pages I get this error:

    You do not have sufficient permissions to access this page.

    What do I need to do in order to allow access to the sub-pages?

  2. evanscode
    Member
    Posted 5 years ago #

    So it's this code in plugin.php (line 947) that's causing the UI to bomb.

    if ( !isset($_registered_pages[$hookname]) )
        return false;
    }

    $hookname is "admin_page_MyPlugin/SubPageOne."

    So, is it considered bad-form to stash references in $_registered_pages forcefully?

  3. evanscode
    Member
    Posted 5 years ago #

    OK. I got past this by putting the following code in my main plugin file.

    $_registered_pages["admin_page_MyPlugin/SubPageOne"] = true;

  4. Mark Jaquith
    WordPress Lead Dev
    Posted 5 years ago #

    Don't use PHP file names, fake or real, as your admin page slug. Use something like: "my-plugin-name-settings" A lot of old examples use __FILE__ — don't. If you're passing in a function callback, you can just use any string as the slug.

Topic Closed

This topic has been closed to new replies.

About this Topic