“You do not have sufficient permissions to access this page” plugin errors after upgrading to Wordpress 3
techie tipsIf, like me you develop websites using Wordpress and also write your own plugins you may well come across this problem.
I recently wrote a bespoke plugin to store and manage e-news subscriptions within the admin panel (I haven’t yet released it). I had written this plugin prior to the release of Wordpress 3 and everything worked perfectly. I then upgraded the website that was using it to Wordpress 3. The upgrade worked without a problem, however, when I tried to access the admin area for the enews subscriptions I now got this error:
You do not have sufficient permissions to access this page
Frustrating. After many fruitless Google searches that told me my table prefix was wrong, or I needed to change the code
add_action('admin_head', 'enews');
to:
add_action('admin_menu', 'enews');
(unfortunately my code was already using the latter) I finally got to the bottom of it.
The fix:
The issue for me was this line:
add_options_page('Enews Signups', 'Enews Signups', '1', 'Enews Signups', 'my_plugin_options');
Its actually a much simpler fix than going through your database to make sure the prefix is always the same case (although it really should be anyway). Change the above line to:
add_options_page('Enews Signups', 'Enews Signups', '1', 'Enews-Signups', 'my_plugin_options');
Notice the difference?
All I’ve done is changed the ’slug’ parameter to include a ‘-’ instead of a space. It appears that Wordpress 3 has much stricter rules when creating plugins. The problem is the function ‘get_plugin_page_hookname’ in wp-admin/includes/plugins.php removes all spaces from the slug name. So my slug would be ‘EnewsSignups’ instead but because I have specified it to have spaces the wrong ’slug’ name is being registered. This fails the plugin validation and what causes the “You do not have sufficient permissions to access this page” error.
Removing the spaces between the words in the slug fixes this.
Simples
Tags: bug, plugin development, wordpress, Wordpress 3






Leave a Reply