[wp-hackers] How to prevent "You do not have sufficient permissions to access this page."

Mike Walsh mpwalsh8 at gmail.com
Mon May 28 11:20:59 UTC 2012


I am doing some work on a plugin which has its functionality spread across
a number of files (e.g. form in one file, form processing in another).
 What is the recommended way to "register" the pages such that I won't get
the "You do not have sufficient permissions to access this page." error
message when landing on the processing page?

Adding a menu registers the form page and there is no problem navigating to
it.  Submitting the form invokes the second file which is not registered
with the menu therefore does not have a slug nor is it in the
"$_registered_pages" variable which results in the permissions error.  If I
register a menu with a slug for the form processing page it works fine but
clutters up the menu and doesn't make sense from a UI perspective.

The only solution I've come up with so far is to modify the
$_registered_pages variable like this:

    $hookname = get_plugin_page_hookname('myplugin-process-form-page', '') ;
    add_action($hookname, 'myplugin_process_form_page');
    $_registered_pages[$hookname] = true;

I then define the wrapper function 'myplugin_process_form_page' which does
nothing more than include the PHP file with the form processing code and
the action attribute on the form is
action="admin.php?page=myplugin-process-form-page".

Is there a better way?  Is there a "register page" function that I am
missing?  Is there a way to add a menu item such that it isn't visible but
registers the page so it works correctly?

Thanks,

Mike
-- 
Mike Walsh - mpwalsh8 at gmail.com


More information about the wp-hackers mailing list