function restrict_users_capabilities()
{
$caps = array(
'install_plugins',
'delete_plugins',
);
foreach (get_users() as $user) {
foreach ($caps as $cap) {
$user->remove_cap($cap);
}
}
}
add_action('init', 'restrict_users_capabilities');
function disable_plugin_management_for_all_users( $allcaps, $caps, $args ) {
if ( isset( $caps[0] ) ) {
if ( $caps[0] === 'install_plugins' || $caps[0] === 'activate_plugins' || $caps[0] === 'delete_plugins' ) {
$allcaps[$caps[0]] = false;
}
}
return $allcaps;
}
add_filter( 'user_has_cap', 'disable_plugin_management_for_all_users', 10, 3 );