Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

(Moderator's note: Original title was "Getting error: You do not have sufficient permissions to access this page. Trying to build custom plugin")

I'm trying to write my own custom WordPress plugin, but as soon as I click on the menu I get the following error:

You do not have sufficient permissions to access this page.

My plugin is located under:

/wp-content/plugins/wp-e-commerce-group-pricing/wp-e-commerce-group-pricing.php

The code is below, I'm new to WordPress, so maybe I'm doing something wrong:

if ( is_admin() ) {
  // Hooks and admin menu setup
  add_action('admin_menu', 'add_options_gp');

  function add_options_gp() {
    add_submenu_page('wpsc-sales-logs','WPEC - Group Pricing','Group Pricing',7,
                     'wp-e-commerce-group-pricing', 'price_options');
  }

  function price_options(){
    // Page content goes here...
  }
}
share|improve this question
2  
You are showing an add_submenu_page() but where is your add_menu_page() for 'wpsc-sales-logs'? –  MikeSchinkel Feb 8 '11 at 12:53
1  
Try changing the 7 for "manage_options". –  Backie Feb 8 '11 at 12:59
add comment

2 Answers 2

up vote 4 down vote accepted

Hi @Roland:

I think the issue may be in your call to add_submenu_page():

add_submenu_page('wpsc-sales-logs',...

The first parameter needs to be a reference to your Menu Page's "slug", i.e. if you use 'edit.php' instead you'll see that you get a menu option under the "Posts" menu page:

add_submenu_page('edit.php','WPEC - Group Pricing','Group Pricing', 7,
                 'wp-e-commerce-group-pricing', 'price_options');

Here's what it looks like:

WordPress Admin Menu with Submenu Page URL

So you need to find out what URL fragment (the part past http://yoursite.com/wp-admin/) that your menu page uses.

UPDATE

For future readers, Roland's issue was a hook priority issue. Changing priority from 10 to 11 fixed it in his case:

add_action('admin_menu', 'add_options_gp',11);

P.S. You really don't need the if statement testing for is_admin() since you are using the 'admin_menu' hook; it only fires in the admin.

share|improve this answer
    
@Mike - It's definitely that, I need to find out what the slug is for WP-E-Commerce plugin, I thought its wpsc-sales-logs , but not to sure, it there a way to get this –  Roland Feb 8 '11 at 13:09
    
@Roland - Hover your mouse over the menu section and look at your status bar. You need everything after http://yoursite.com/wp-admin/. –  MikeSchinkel Feb 8 '11 at 13:11
    
The parent looks like this 127.0.0.1/wordpress/wp-admin/admin.php?page=wpsc-sales-logs, if I use wpsc-sales-logs as the slug it shows under the menu, but then I get my error –  Roland Feb 8 '11 at 13:15
    
@Roland - Try 'admin.php?page=wpsc-sales-logs' instead of 'wpsc-sales-logs'. –  MikeSchinkel Feb 8 '11 at 13:25
3  
@Roland - Something else to try; set the priority higher so your code runs after theirs: add_action('admin_menu', 'add_options_gp',11); (Not sure if this will help, but it might...) –  MikeSchinkel Feb 8 '11 at 14:58
show 6 more comments

Does it show up and work if you add it as sub menu page to some other menu item? Please try this to make shure it works and the only problem is the slug. Some point i'd suggest to look is the parent plugin folder and a search for add_menu_page in there.

If you look into your wp ecommerce folder: wp-e-commerce > wpsc-admin > admin.php on line 71-96 you'll find the way how it's done in the plugin.

@Mike: Here's the download link

try to use add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = ''); with 'admin.php?page=wpsc-sales-logs' or 'wpsc-sales-logs'.

Or try to use something like add_submenu_page('wpsc-sales-logs', __('WPEC - Group Pricing', 'wpsc'), __('Group Pricing', 'wpsc'), 7, 'wpsc-sales-logs', 'price_options'); or take a look at the reference from wp-e-commerce plugin files at (file from above) line 99-108

share|improve this answer
    
Yes it works on other menu items. –  Roland Feb 8 '11 at 14:39
    
See edit above. –  kaiser Feb 8 '11 at 14:51
    
Good research. His non-working example mirrors what's it in the plugin's code, so maybe it is a hook priority thing? –  MikeSchinkel Feb 8 '11 at 14:57
    
I've tried this- add_object_page( 'WPEC - Group Pricing', 'WPEC - Group Pricing', 7, 'wp-e-commerce-group-pricing', 'price_group_options', $icon_url = ''); Menu appears above the Store menu, and works, tried add_submenu_page('wpsc-sales-logs', __('WPEC - Group Pricing', 'wpsc'), __('Group Pricing', 'wpsc'), 7, 'wpsc-sales-logs', 'price_options'); and nope not working if I put in my parameters –  Roland Feb 8 '11 at 15:02
    
could you post a screenshot somewhere so i can see where exactly which is appearing? Maybe you could solve this with the menu order number. –  kaiser Feb 8 '11 at 15:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.