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.
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.
Share Improve this question asked May 29, 2020 at 12:32 InfocurciInfocurci 1 5 |1 Answer
Reset to default 0I 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 ] );
view_webinar
capability? Keep in mind that when you calladd_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 ♦ Commented May 29, 2020 at 12:41null
? – Tom J Nowell ♦ Commented May 29, 2020 at 14:03aggiungi_ruolo
, you should not be adding the capability on every single request, it should only happen once – Tom J Nowell ♦ Commented Jun 1, 2020 at 8:54