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