0

Hi I was wondering if there was a way to restrict access to certain plugins for a certain admin.

For example. I want to have a second admin on my site, I want them to be able to access all plugins except for one plugin. Is there a way that I can make this happen?

  • This might not be possible depending on the plugin, but it almost certainly will require code changes to set up the appropriate roles and capabilities. Unless the plugin implements custom capabilities this won't be possible, and a majority of plugins don't – Tom J Nowell Jul 13 '18 at 20:32
  • Couldn't there be some filter code in functions.php that would see if the plugin settings page was loaded, and then check if admin2 = current user, and redirect back to the dashboard if admin2 is logged in? – Rick Hellewell Jul 13 '18 at 21:32
  • This would be a great function for wordpress to have. Being a designer I bought website builder for $200 but I have to install it on clients sites, I kinda don't want them to be able to access the plugin and mess anything up. It also feels like giving away a program I paid for for free. – Terrell Anderson Jul 13 '18 at 23:32
0

I think this code will prevent certain users from getting into any part of the admin area (not tested):

add_filter('admin_menu', 'block_users');

function block_users() {
    $current_user = wp_get_current_user();  // get current user object
    $allowed_user = 'superadmin@here.com';  // change to allowed user email
    if (! $current_user->user_login == $allowed_user) { 
        wp_redirect(admin_url());   // redirect to dashboard
        exit;   // to exit this if redirected
        }
    return;
}

Not sure which hook to use for getting into a plugin settings screen, or other areas of the admin menu (if you want to block all plugins settings).

You could put something similar at the top of your plugin code to prevent access to a specific plugin. Just change the email of the account you want to block. You can adjust the value you want to look for by using other elements of the $current_user array (see https://codex.wordpress.org/wp_get_current_user ).

Perhaps this will help get you started in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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