How to change user role using hook

Please edit your function and add code used below for adding user role in functions.php This is basic idea how roles can be added and removed and how you can check your filed values. Please use according to your requirements. add_action( ‘profile_update’, ‘my_profile_update’, 10, 2 ); function my_profile_update( $user_id, $old_user_data ) { // here you … Read more

Undo User Role Name Change

Rename Existing Role Name : function wps_change_role_name() { global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); if($wp_roles->roles[‘contributor’][‘name’] = ‘Owner’) { $wp_roles->roles[‘contributor’][‘name’] = ‘Contributor’ $wp_roles->role_names[‘contributor’] = ‘Contributor’; } } add_action(‘init’, ‘wps_change_role_name’); From database you can see role : I see a table called “wp_options” with a row named “wp_user_roles”. It contains: … Read more