Support » Plugins » Hacks » register plugin page to avoid "do not have permission" error

  • Resolved mophilly


    I have built a plugin. The menu items appears, and when I select the menu item, the appropriate page displays.

    In this case, the page is a list view of the database table. Clicking on a line in the list invokes a table editor. The php file for the table editor is in same directory as the other files, and it has the same system permissions.

    WP complains that “You do not have sufficient permissions to access this page.”

    How do I register this page with the plugin so it loads correctly?

Viewing 1 replies (of 1 total)
  • Although this post is unanswered and rather old, here is the solution I used. It may not be the best way but it works here. YMMV.

    In the plugin init area, declare an action for “admin_menu” with a function to do the bulk of the work.

    // administration page
    	add_action('admin_menu', 'my_admin_actions');

    The function adds a line to the admin side, and most importantly, adds a sub menu item that is associated with a call to admin

    function my_admin_actions() {
      // user registration
      // help: add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position )
      // application administration Menu
      // help: add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position )
      add_menu_page('My Administration', 'Administration', 'activate_plugins', 'my-admin', 'my_admin_main');
      // help: add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
      // help: the function parameter refers to the functions defined in this file. Note that each function name here also is defined in the next section
    // location based class list and editor
      add_submenu_page('admin.php?page=', 'Administration', 'Editor', 'activate_plugins', 'my_admin_editor', 'function_my_admin_editor');

    By using “admin.php?page=” as the first parameter of add_submenu_page, you asking WordPress to look for a page name (my_admin_editor) instead of a menu slug in the normal way.

Viewing 1 replies (of 1 total)
  • The topic ‘register plugin page to avoid "do not have permission" error’ is closed to new replies.