I write a custom plugin, with one link for administration purpose. This is my code:

add_action('admin_menu', 'tb_instructor_menu');
add_action( 'init', 'aggiungi_ruolo', 11 );
function aggiungi_ruolo() 
$role = get_role( 'wdm_instructor' );
$role->add_cap( 'view_webinar', true );
function tb_instructor_menu()
add_menu_page('My code', 'My code', 'view_webinar', 'my-code', null, 'dashicons-businessman' , 61);

If I am logged in as Admin, I see the link.

If I'm logged in as "wdm_instructor", I don't see the link.

I have already verified that the "wdm_instructor" role has the "view_webinar" capability flagged.

  • How did you confirm that role has the view_webinar capability? Keep in mind that when you call add_cap it makes changes to the database, your code as it is will make an unnecessary database write on every single request/page/ajax/RSS/REST etc This might be related to your problem
    – Tom J Nowell
    May 29, 2020 at 12:41
  • Whe I'm logged as wdm_instructor, with wp_get_current_user() I see that my role is "wdm_instructor". With get_role( 'wdm_instructor' )->capabilities; I see that I have [view_webinar] => 1.
    – Infocurci
    May 29, 2020 at 13:52
  • and the page works if you visit it directly? It just doesn't show in the admin menu for that specific role? Is your administrator an administrator or is it a super admin on a multisite? Why is your callback for rendering the page set to null?
    – Tom J Nowell
    May 29, 2020 at 14:03
  • I had disabled the callback to make sure that wasn't the problem. Even with the callback, I don't see the link in the menu when I'm logged in as wdm_instructor. I only see the link if I'm a wordpress administrator. If I copy / paste the link into a browser where I am logged in as "wdm_instructor", the page works correctly. Only the link in the menu is missing.
    – Infocurci
    Jun 1, 2020 at 6:40
  • So the callback works, it's just that the menu does not appear in the sidebar of WP Admin. I still think that by adding the capability to the role each, and, every, single, page, request, you're actually causing problems. Try unhooking aggiungi_ruolo, you should not be adding the capability on every single request, it should only happen once
    – Tom J Nowell
    Jun 1, 2020 at 8:54

1 Answer 1


I understand the problem. My customer had purchased a paid plugin that, on the action "admin_menu", scrolled through the entire global variable $menu and eliminated all the items that were not allowed by their plugin

unset( $menu[ $key ] );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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