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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / User.php
tutor / classes Last commit date
Addons.php 5 years ago Admin.php 5 years ago Ajax.php 5 years ago Assets.php 5 years ago Course.php 5 years ago Course_Filter.php 5 years ago Course_Settings_Tabs.php 5 years ago Course_Widget.php 5 years ago Custom_Validation.php 5 years ago Dashboard.php 5 years ago Delete_Enrollment_With_Order.php 5 years ago Email.php 5 years ago FormHandler.php 5 years ago Frontend.php 5 years ago Gutenberg.php 5 years ago Instructor.php 5 years ago Instructors_List.php 5 years ago Lesson.php 5 years ago Options.php 5 years ago Post_types.php 5 years ago Private_Course_Access.php 5 years ago Q_and_A.php 5 years ago Question_Answers_List.php 5 years ago Quiz.php 5 years ago Quiz_Attempts_List.php 5 years ago RestAPI.php 5 years ago Rewrite_Rules.php 5 years ago Shortcode.php 5 years ago Student.php 5 years ago Students_List.php 5 years ago Taxonomies.php 5 years ago Template.php 5 years ago Theme_Compatibility.php 5 years ago Tools.php 5 years ago Tutor.php 5 years ago TutorEDD.php 5 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 5 years ago Tutor_Setup.php 5 years ago Upgrader.php 5 years ago User.php 5 years ago Utils.php 5 years ago Video_Stream.php 5 years ago Withdraw.php 5 years ago Withdraw_Requests_List.php 5 years ago WooCommerce.php 5 years ago
User.php
129 lines
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 add_action('wp_ajax_tutor_user_photo_remove', array($this, 'tutor_user_photo_remove'));
19 add_action('wp_ajax_tutor_user_photo_upload', array($this, 'update_user_photo'));
20
21 add_action('tutor_options_after_instructors', array($this, 'tutor_instructor_profile_layout'));
22 // add_action('tutor_options_after_students', array($this, 'tutor_student_profile_layout'));
23 }
24
25 private $profile_layout = array(
26 'pp-circle',
27 'pp-rectangle',
28 'no-cp'
29 );
30
31 /**
32 * Show layout selection dashboard in instructor and student setting
33 */
34 public function tutor_instructor_profile_layout(){
35 tutor_load_template('public-profile-setting', array('profile_templates'=>$this->profile_layout, 'layout_option_name'=>'instructor'));
36 }
37 public function tutor_student_profile_layout(){
38 tutor_load_template('public-profile-setting', array('profile_templates'=>$this->profile_layout, 'layout_option_name'=>'student'));
39 }
40
41 public function edit_user_profile($user){
42 include tutor()->path.'views/metabox/user-profile-fields.php';
43 }
44
45 private function delete_existing_user_photo($user_id, $type){
46 $meta_key = $type=='cover_photo' ? '_tutor_cover_photo' : '_tutor_profile_photo';
47 $photo_id = get_user_meta($user_id, $meta_key, true);
48 is_numeric($photo_id) ? wp_delete_attachment( $photo_id, true) : 0;
49 delete_user_meta( $user_id, $meta_key);
50 }
51
52 public function tutor_user_photo_remove(){
53 tutils()->checking_nonce();
54
55 $this->delete_existing_user_photo(get_current_user_id(), $_POST['photo_type']);
56 }
57
58 public function update_user_photo(){
59 tutils()->checking_nonce();
60
61 $user_id = get_current_user_id();
62 $meta_key = $_POST['photo_type']=='cover_photo' ? '_tutor_cover_photo' : '_tutor_profile_photo';
63
64 /**
65 * Photo Update from profile
66 *
67 */
68 $photo = tutils()->array_get('photo_file', $_FILES);
69 $photo_size = tutils()->array_get('size', $photo);
70 $photo_type = tutils()->array_get('type', $photo);
71
72 if ($photo_size && strpos($photo_type, 'image') !== false) {
73 if ( ! function_exists( 'wp_handle_upload' ) ) {
74 require_once( ABSPATH . 'wp-admin/includes/file.php' );
75 }
76
77 $upload_overrides = array( 'test_form' => false );
78 $movefile = wp_handle_upload( $photo, $upload_overrides );
79
80 if ( $movefile && ! isset( $movefile['error'] ) ) {
81 $file_path = tutils()->array_get( 'file', $movefile );
82 $file_url = tutils()->array_get( 'url', $movefile );
83
84 $media_id = wp_insert_attachment( array(
85 'guid' => $file_path,
86 'post_mime_type' => mime_content_type( $file_path ),
87 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_url ) ),
88 'post_content' => '',
89 'post_status' => 'inherit'
90 ), $file_path, 0 );
91
92 if ($media_id) {
93 // wp_generate_attachment_metadata() won't work if you do not include this file
94 require_once( ABSPATH . 'wp-admin/includes/image.php' );
95
96 // Generate and save the attachment metas into the database
97 wp_update_attachment_metadata( $media_id, wp_generate_attachment_metadata( $media_id, $file_path ) );
98
99 //Update it to user profile
100 $this->delete_existing_user_photo($user_id, $_POST['photo_type']);
101 update_user_meta($user_id, $meta_key, $media_id );
102
103 exit(json_encode(array('status'=>'success')));
104 }
105 }
106 }
107 }
108
109 public function profile_update($user_id){
110 $_tutor_profile_job_title = sanitize_text_field(tutor_utils()->avalue_dot('_tutor_profile_job_title', $_POST));
111 $_tutor_profile_bio = wp_kses_post(tutor_utils()->avalue_dot('_tutor_profile_bio', $_POST));
112
113 update_user_meta($user_id, '_tutor_profile_job_title', $_tutor_profile_job_title);
114 update_user_meta($user_id, '_tutor_profile_bio', $_tutor_profile_bio);
115 }
116
117 public function set_user_role($user_id, $role, $old_roles ){
118 $instructor_role = tutor()->instructor_role;
119
120 if (in_array($instructor_role, $old_roles)){
121 // tutor_utils()->remove_instructor_role($user_id);
122 }
123
124 // if ($role === $instructor_role){
125 if ($role === $instructor_role || in_array($instructor_role, $old_roles)){
126 tutor_utils()->add_instructor_role($user_id);
127 }
128 }
129 }