Found this code to remove a plugin based on user role – but it is not working?
add_action(‘admin_init’, ‘my_filter_the_plugins’);
function my_filter_the_plugins()
{
global $current_user;
if (in_array(‘wholesale_customer’, $current_user->roles)) {
deactivate_plugins( // deactivate for wholesale_customer
array(
‘/woocommerce-bulk-discount/woocommerce-bulk-discount.php’
),
true, // silent mode (no deactivation hooks fired)
false // network wide
);
} else { // activate for those than can use it
activate_plugins(
array(
‘/woocommerce-bulk-discount/woocommerce-bulk-discount.php’
),
”, // redirect url, does not matter (default is ”)
false, // network wise
true // silent mode (no activation hooks fired)
);
}
}
Suggestions?