0

I want to add new options page ONLY for those users whose role is vendor. How can I do that? This is my current code.

add_action('admin_menu', 'business_settings_menu');

function business_settings_menu() {
    add_menu_page('Business Settings', 'Business Settings', 'administrator', 'business_settings', 'business_settings_page', 'dashicons-arrow-right-alt', '31.6');
    add_action('admin_init', 'business_settings');
}

The problem that I am facing is that when administrator logins, he can see this page. But when I login from my vendor account, I am unable to see this link. Can anyone guide me? I have woocommerce installed on my wordpress.

  • Can you please update your question with a code which you used to register 'Vendor' user role? That will provide sufficient details to provide solution. – Prasad Nevase Dec 29 '15 at 14:04
0

The third argument to add_menu_page() is $capability.

add_menu_page( 
  $page_title, 
  $menu_title, 
  $capability, 
  $menu_slug, 
  $function, 
  $icon_url, 
  $position 
);

That governs who can see the page. You've registered yours as "administrator", which is a user role. Presumably your vendors are not of that role. To fix this, you will need to change that argument to a capability (preferably not a role) that your vendors have. You can create custom capabilities for this, which is probably what I'd do.

  • When I add a new user, There is a dropdown for roles. In that role, I have chose vendor. What should I write in capability so that the settings menu appear only when vendors login through their admin panel? – Ali Zia Dec 30 '15 at 4:33
  • Depends on how you've registered the role. You can probably use the role name but that is known to be a bit buggy (wish that would be fixed). That is why I suggest you add a specific capabability. – s_ha_dum Dec 30 '15 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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