Skip to content

Instantly share code, notes, and snippets.

@kimhawleydesign
Created September 20, 2019 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimhawleydesign/6f8825e9144a7374fe277a1436c47c6a to your computer and use it in GitHub Desktop.
Save kimhawleydesign/6f8825e9144a7374fe277a1436c47c6a to your computer and use it in GitHub Desktop.
function uiwc_new_role() {
//add the special customer role
add_role(
'wholesale_customer',
"Wholesale Customer",
array(
'read' => true,
'delete_posts' => false
)
);
}
add_action('admin_init', 'uiwc_new_role');
function uiwc_change_role()
{
// get WP_user object
$user = wp_get_current_user();
$role = $user->roles;
// if the this is a registered user and this user is not an admin
if (is_user_logged_in() && !user_can($user, 'administrator') && !in_array('wholesale_customer', $role)) {
//set the new role to our customer
$user->set_role('wholesale_customer');
}
}
add_action('wp_footer', 'uiwc_change_role');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment