0

I've created a new user role(based on shop manager) with user role editor, i need to show a custom plugin for this role.

Thanks

$user = wp_get_current_user();
if ( in_array( 'custom_role', (array) $user->roles ) ) {
    //The user has the "custom" role
  add_action( 'some_menu', 'my_plugin_menu' );
}

function my_plugin_menu() { add_options_page('My Plugin Settings', 'My Plugin', 'manage_options', 'my-plugin-settings', 'my_plugin_admin_page'); }
1
  • you could relaize this kind of behaviour with the help of a plugin aka restrict user access. try one of these (not all are fitting your needs, but the first two and some others should do, what you are looking for)
    – honk31
    Dec 4, 2018 at 17:54

1 Answer 1

0

You can try something like this

if ( is_myrole() ) { add_action( 'some_menu', 'my_plugin_menu' ); }

function my_plugin_menu() { add_options_page('My Plugin Settings', 'My Plugin', 'manage_options', 'my-plugin-settings', 'my_plugin_admin_page'); }

6
  • Inside the functions.php ? Dec 3, 2018 at 17:20
  • Yes, just change values to what they should be.
    – dado
    Dec 3, 2018 at 17:22
  • Ok so i've to check the user role and use the boolean. Dec 3, 2018 at 20:15
  • If answer is correct please marked it, so other people having similar problems. Thanks
    – dado
    Dec 3, 2018 at 20:36
  • Doesn't appear the menu Dec 3, 2018 at 21:07

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.