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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 4 years ago Admin.php 4 years ago Ajax.php 4 years ago Assets.php 4 years ago Course.php 4 years ago Course_Filter.php 4 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 Email.php 5 years ago FormHandler.php 5 years ago Frontend.php 5 years ago Gutenberg.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options.php 4 years ago Post_types.php 4 years ago Private_Course_Access.php 5 years ago Q_and_A.php 5 years ago Question_Answers_List.php 4 years ago Quiz.php 4 years ago Quiz_Attempts_List.php 4 years ago RestAPI.php 5 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 5 years ago Template.php 4 years ago Theme_Compatibility.php 5 years ago Tools.php 5 years ago Tutor.php 4 years ago TutorEDD.php 5 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 4 years ago Tutor_Setup.php 4 years ago Upgrader.php 5 years ago User.php 4 years ago Utils.php 4 years ago Video_Stream.php 5 years ago Withdraw.php 5 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 4 years ago
User.php
185 lines
1 <?php
2
3 namespace TUTOR;
4
5 if ( ! defined( 'ABSPATH' ) )
6 exit;
7
8
9 class User {
10
11 private static $hide_registration_notice = false;
12
13 public function __construct() {
14 add_action('edit_user_profile', array($this, 'edit_user_profile'));
15 add_action('show_user_profile', array($this, 'edit_user_profile'), 10, 1);
16
17 add_action('profile_update', array($this, 'profile_update'));
18 add_action('set_user_role', array($this, 'set_user_role'), 10, 3);
19
20 add_action('wp_ajax_tutor_user_photo_remove', array($this, 'tutor_user_photo_remove'));
21 add_action('wp_ajax_tutor_user_photo_upload', array($this, 'update_user_photo'));
22
23 add_action('tutor_options_after_instructors', array($this, 'tutor_instructor_profile_layout'));
24 // add_action('tutor_options_after_students', array($this, 'tutor_student_profile_layout'));
25
26 add_action( 'admin_notices', array( $this, 'show_registration_disabled' ) );
27 add_action( 'admin_init', array( $this, 'hide_notices' ) );
28 }
29
30 private $profile_layout = array(
31 'pp-circle',
32 'pp-rectangle',
33 'no-cp'
34 );
35
36 /**
37 * Show layout selection dashboard in instructor and student setting
38 */
39 public function tutor_instructor_profile_layout(){
40 tutor_load_template('public-profile-setting', array('profile_templates'=>$this->profile_layout, 'layout_option_name'=>'instructor'));
41 }
42 public function tutor_student_profile_layout(){
43 tutor_load_template('public-profile-setting', array('profile_templates'=>$this->profile_layout, 'layout_option_name'=>'student'));
44 }
45
46 public function edit_user_profile($user){
47 include tutor()->path.'views/metabox/user-profile-fields.php';
48 }
49
50 private function delete_existing_user_photo($user_id, $type){
51 $meta_key = $type=='cover_photo' ? '_tutor_cover_photo' : '_tutor_profile_photo';
52 $photo_id = get_user_meta($user_id, $meta_key, true);
53 is_numeric($photo_id) ? wp_delete_attachment( $photo_id, true) : 0;
54 delete_user_meta( $user_id, $meta_key);
55 }
56
57 public function tutor_user_photo_remove(){
58 tutils()->checking_nonce();
59
60 $this->delete_existing_user_photo(get_current_user_id(), $_POST['photo_type']);
61 }
62
63 public function update_user_photo(){
64 tutils()->checking_nonce();
65
66 $user_id = get_current_user_id();
67 $meta_key = $_POST['photo_type']=='cover_photo' ? '_tutor_cover_photo' : '_tutor_profile_photo';
68
69 /**
70 * Photo Update from profile
71 *
72 */
73 $photo = tutils()->array_get('photo_file', $_FILES);
74 $photo_size = tutils()->array_get('size', $photo);
75 $photo_type = tutils()->array_get('type', $photo);
76
77 if ($photo_size && strpos($photo_type, 'image') !== false) {
78 if ( ! function_exists( 'wp_handle_upload' ) ) {
79 require_once( ABSPATH . 'wp-admin/includes/file.php' );
80 }
81
82 $upload_overrides = array( 'test_form' => false );
83 $movefile = wp_handle_upload( $photo, $upload_overrides );
84
85 if ( $movefile && ! isset( $movefile['error'] ) ) {
86 $file_path = tutils()->array_get( 'file', $movefile );
87 $file_url = tutils()->array_get( 'url', $movefile );
88
89 $media_id = wp_insert_attachment( array(
90 'guid' => $file_path,
91 'post_mime_type' => mime_content_type( $file_path ),
92 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_url ) ),
93 'post_content' => '',
94 'post_status' => 'inherit'
95 ), $file_path, 0 );
96
97 if ($media_id) {
98 // wp_generate_attachment_metadata() won't work if you do not include this file
99 require_once( ABSPATH . 'wp-admin/includes/image.php' );
100
101 // Generate and save the attachment metas into the database
102 wp_update_attachment_metadata( $media_id, wp_generate_attachment_metadata( $media_id, $file_path ) );
103
104 //Update it to user profile
105 $this->delete_existing_user_photo($user_id, $_POST['photo_type']);
106 update_user_meta($user_id, $meta_key, $media_id );
107
108 exit(json_encode(array('status'=>'success')));
109 }
110 }
111 }
112 }
113
114 public function profile_update($user_id){
115 if (tutils()->array_get('tutor_action', $_POST) !== 'tutor_profile_update_by_wp' ){
116 return;
117 }
118
119 $_tutor_profile_job_title = sanitize_text_field(tutor_utils()->avalue_dot('_tutor_profile_job_title', $_POST));
120 $_tutor_profile_bio = wp_kses_post(tutor_utils()->avalue_dot('_tutor_profile_bio', $_POST));
121 $_tutor_profile_image = wp_kses_post(tutor_utils()->avalue_dot('_tutor_profile_photo', $_POST));
122
123 update_user_meta($user_id, '_tutor_profile_job_title', $_tutor_profile_job_title);
124 update_user_meta($user_id, '_tutor_profile_bio', $_tutor_profile_bio);
125 update_user_meta($user_id, '_tutor_profile_photo', $_tutor_profile_image);
126 }
127
128 public function set_user_role($user_id, $role, $old_roles ){
129 $instructor_role = tutor()->instructor_role;
130
131 if (in_array($instructor_role, $old_roles)){
132 // tutor_utils()->remove_instructor_role($user_id);
133 }
134
135 // if ($role === $instructor_role){
136 if ($role === $instructor_role || in_array($instructor_role, $old_roles)){
137 tutor_utils()->add_instructor_role($user_id);
138 }
139 }
140
141 public function hide_notices() {
142 if(is_admin() && isset( $_GET['tutor-hide-notice'] ) && $_GET['tutor-hide-notice']=='registration') {
143 tutils()->checking_nonce('get');
144
145 if(isset($_GET['tutor-registration']) && $_GET['tutor-registration']==='enable') {
146 update_option( 'users_can_register', 1 );
147 } else {
148 self::$hide_registration_notice = true;
149 setcookie('tutor_notice_hide_registration', 1, time() + (86400 * 30), tutor()->basepath);
150 }
151 }
152 }
153
154 public function show_registration_disabled() {
155
156 if(
157 self::$hide_registration_notice ||
158 !tutils()->is_tutor_dashboard() ||
159 get_option( 'users_can_register' ) ||
160 isset( $_COOKIE['tutor_notice_hide_registration'] ) ||
161 !current_user_can( 'manage_options' )
162 ) {
163 return;
164 }
165
166 $hide_url = wp_nonce_url( add_query_arg( 'tutor-hide-notice', 'registration' ), tutor()->nonce_action, tutor()->nonce );
167 ?>
168 <div class="wrap tutor-user-registration-notice-wrapper">
169 <div class="tutor-user-registration-notice">
170 <div>
171 <img src="<?php echo tutor()->url; ?>assets/images/icon-info-round.svg"/>
172 </div>
173 <div>
174 <?php _e('As membership is turned off, students and instructors will not be able to sign up. <strong>Press Enable</strong> or go to <strong>Settings > General > Membership</strong> and enable "Anyone can register".'); ?>
175 </div>
176 <div>
177 <a href="<?php echo esc_url( add_query_arg( 'tutor-registration', 'enable', $hide_url ) ); ?>"><?php _e('Enable', 'tutor'); ?></a>
178 <hr/>
179 <a href="<?php echo esc_url( $hide_url ); ?>"><?php _e('Dismiss', 'tutor'); ?></a>
180 </div>
181 </div>
182 </div>
183 <?php
184 }
185 }