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?
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.