| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | add_action('edit_user_profile', array($this, 'edit_user_profile')); |
| 10 | 10 | add_action('show_user_profile', array($this, 'edit_user_profile'), 10, 1); |
| 11 | 11 | |
| 12 | 12 | add_action('profile_update', array($this, 'profile_update')); |
| 13 | + add_action('set_user_role', array($this, 'set_user_role'), 10, 3); | |
| 13 | 14 | } |
| 14 | 15 | |
| 15 | 16 | public function edit_user_profile($user){ |
| 16 | 17 | include tutor()->path.'views/metabox/user-profile-fields.php'; |
| @@ -23,7 +24,19 @@ | ||
| 23 | 24 | |
| 24 | 25 | update_user_meta($user_id, '_tutor_profile_job_title', $_tutor_profile_job_title); |
| 25 | 26 | update_user_meta($user_id, '_tutor_profile_bio', $_tutor_profile_bio); |
| 26 | 27 | update_user_meta($user_id, '_tutor_profile_photo', $_tutor_profile_photo); |
| 28 | + } | |
| 29 | + | |
| 30 | + public function set_user_role($user_id, $role, $old_roles ){ | |
| 31 | + $instructor_role = tutor()->instructor_role; | |
| 32 | + | |
| 33 | + if (in_array($instructor_role, $old_roles)){ | |
| 34 | + tutor_utils()->remove_instructor_role($user_id); | |
| 35 | + } | |
| 36 | + | |
| 37 | + if ($role === $instructor_role){ | |
| 38 | + tutor_utils()->add_instructor_role($user_id); | |
| 39 | + } | |
| 27 | 40 | } |
| 28 | 41 | |
| 29 | 42 | } |