plugins - How do I restrict a second admin certain access?

admin2025-01-08  6

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?

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?

Share Improve this question asked Jul 13, 2018 at 20:11 Terrell AndersonTerrell Anderson 656 bronze badges 3
  • 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 Commented Jul 13, 2018 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 Commented Jul 13, 2018 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 Commented Jul 13, 2018 at 23:32
Add a comment  | 

1 Answer 1

Reset to default 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 = '[email protected]';  // 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736267754a1220.html

最新回复(0)