Created
September 20, 2019 17:16
-
-
Save kimhawleydesign/6f8825e9144a7374fe277a1436c47c6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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