• Resolved AgilityJeff

    (@agilityjeff)


    My client has purchased a poorly written Plugin which meets their needs pretty well, but leaves me with needing to do so additional coding.

    I have had difficulty finding an answer in the documentation – so I thought I’d just ask the “smart people” here for help. Thanks in advance for your assistance with this!

    The plugin was hard-coded to only appear as a menu option for WP users with the “Administrator” role. My clients never get a role higher than Editor as there are a lot of things I don’t want them touching. I’m the only Administrator!

    So the key to my being able to modify the code is to grab the user’s role, then IF ( the role is editor or administrator ) … include the plugin in to the menu.

    They’re using:
    add_menu_page(‘PrayBox’,’PrayBox+’,’administrator’,’pb_settings’,’pb_settings_page’,plugins_url().’/praybox-plus/images/favicon.png’);

    … to display the plugin on the menu. I would like to substitute the user’s role for a hard-coded ‘administrator’ when passing the parameters to this function.

    How do I obtain the current user’s role?

    PLEASE DON’T TELL ME ABOUT A PLUGIN TO ASSIGN USER ROLES / CAPABILITIES. I have already tried several of those without success – the way to fix this is in the plugin code … period. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The third parameter in add_menu_page should not check for a role, but rather a capability held by the current user. You can check out Roles and Capabilities for more info.

    I would suggest replacing administrator with moderate_comments, which is a capability held by both Administrators and Editors. Note that if any plugin has given other roles the capability of moderate_comments, then that role would also be granted access.

    Thread Starter AgilityJeff

    (@agilityjeff)

    That worked perfectly – thanks so much UaMV!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Find a user's ROLE’ is closed to new replies.