| 1 |
<?php |
| 2 |
|
| 3 |
namespace TUTOR; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) |
| 6 |
exit; |
| 7 |
|
| 8 |
|
| 9 |
class User { |
| 10 |
|
| 11 |
public function __construct() { |
| 12 |
add_action('edit_user_profile', array($this, 'edit_user_profile')); |
| 13 |
add_action('show_user_profile', array($this, 'edit_user_profile'), 10, 1); |
| 14 |
|
| 15 |
add_action('profile_update', array($this, 'profile_update')); |
| 16 |
add_action('set_user_role', array($this, 'set_user_role'), 10, 3); |
| 17 |
} |
| 18 |
|
| 19 |
public function edit_user_profile($user){ |
| 20 |
include tutor()->path.'views/metabox/user-profile-fields.php'; |
| 21 |
} |
| 22 |
|
| 23 |
public function profile_update($user_id){ |
| 24 |
$_tutor_profile_job_title = sanitize_text_field(tutor_utils()->avalue_dot('_tutor_profile_job_title', $_POST)); |
| 25 |
$_tutor_profile_bio = wp_kses_post(tutor_utils()->avalue_dot('_tutor_profile_bio', $_POST)); |
| 26 |
$_tutor_profile_photo = sanitize_text_field(tutor_utils()->avalue_dot('_tutor_profile_photo', $_POST)); |
| 27 |
|
| 28 |
update_user_meta($user_id, '_tutor_profile_job_title', $_tutor_profile_job_title); |
| 29 |
update_user_meta($user_id, '_tutor_profile_bio', $_tutor_profile_bio); |
| 30 |
update_user_meta($user_id, '_tutor_profile_photo', $_tutor_profile_photo); |
| 31 |
} |
| 32 |
|
| 33 |
public function set_user_role($user_id, $role, $old_roles ){ |
| 34 |
$instructor_role = tutor()->instructor_role; |
| 35 |
|
| 36 |
if (in_array($instructor_role, $old_roles)){ |
| 37 |
tutor_utils()->remove_instructor_role($user_id); |
| 38 |
} |
| 39 |
|
| 40 |
if ($role === $instructor_role){ |
| 41 |
tutor_utils()->add_instructor_role($user_id); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
} |