Custom Capability – show plugin menu to these users and admins only
-
Hi,
I have created a plugin which has custom menu pages.
The plugin creates two roles upon activation (let’s say role 1 and role 2).role 1 is used for some coding and works fine, WordPress users are assigned this role and the code works correctly.
Where I am struggling is that I would the plugin menu’s to only be displayed to Administrators and users who have role 2 assigned to them.
I am running the following from a function called by my activation hook…
add_role( 'role 1', 'Role 1', array( 'read' => true, 'level_0' => true ) ); add_role( 'role 2', 'role 2', array( 'read' => true, 'level_0' => true ) ); add_action( 'admin_init', 'f_mdjm_caps');
the function f_mdjm_caps contains the following
function f_mdjm_caps() { /* Capabilities */ $role = get_role( 'role 2' ); $role->add_cap( 'manage_myplugin' ); }
I tried adjusting my menu code to be
add_menu_page( 'My Menu', 'My Menu', 'manage_myplugin', 'mdjm-dashboard', 'f_mdjm_admin_dashboard' );
but the menu disappears.
Any help appreciated
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Capability – show plugin menu to these users and admins only’ is closed to new replies.