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

Dion Hulse (dd32) wordpress at dd32.id.au
Mon May 28 12:21:27 UTC 2012


I'd suggest one of 2 things:
 1. Use admin-post.php for callbacks, and redirect back to the plugin
page afterwards
or
 2. Register the pages you need, and use the load-<pagehook> action to
process form events from that page. The load hook is run before any
admin template code is run.

I'm not sure if I'm missing something here though :)

On 28 May 2012 21:20, Mike Walsh <mpwalsh8 at gmail.com> wrote:
> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list