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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 Announcements.php 4 years ago Assets.php 3 years ago Backend_Page_Trait.php 4 years ago Course.php 3 years ago Course_Filter.php 4 years ago Course_List.php 3 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 3 years ago FormHandler.php 4 years ago Frontend.php 3 years ago Gutenberg.php 4 years ago Input.php 3 years ago Instructor.php 4 years ago Instructors_List.php 3 years ago Lesson.php 4 years ago Options_V2.php 3 years ago Post_types.php 4 years ago Private_Course_Access.php 4 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 Reviews.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 3 years ago Theme_Compatibility.php 5 years ago Tools.php 3 years ago Tools_V2.php 4 years ago Tutor.php 3 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 3 years ago Video_Stream.php 4 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 3 years ago
User.php
177 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( 'admin_notices', array( $this, 'show_registration_disabled' ) );
25 add_action( 'admin_init', array( $this, 'hide_notices' ) );
26 }
27
28 private $profile_layout = array(
29 'pp-circle',
30 'pp-rectangle',
31 'no-cp',
32 );
33
34 public function edit_user_profile($user){
35 include tutor()->path.'views/metabox/user-profile-fields.php';
36 }
37
38 private function delete_existing_user_photo( $user_id, $type ) {
39 $meta_key = $type == 'cover_photo' ? '_tutor_cover_photo' : '_tutor_profile_photo';
40 $photo_id = get_user_meta( $user_id, $meta_key, true );
41 is_numeric( $photo_id ) ? wp_delete_attachment( $photo_id, true ) : 0;
42 delete_user_meta( $user_id, $meta_key );
43 }
44
45 public function tutor_user_photo_remove(){
46 tutor_utils()->checking_nonce();
47
48 $this->delete_existing_user_photo(get_current_user_id(), tutor_sanitize_data( $_POST['photo_type'] ));
49 }
50
51 public function update_user_photo(){
52 tutor_utils()->checking_nonce();
53
54 $user_id = get_current_user_id();
55 $meta_key = sanitize_text_field( $_POST['photo_type'] ) == 'cover_photo' ? '_tutor_cover_photo' : '_tutor_profile_photo';
56
57 /**
58 * Photo Update from profile
59 */
60 $photo = tutor_utils()->array_get('photo_file', $_FILES);
61 $photo_size = tutor_utils()->array_get('size', $photo);
62 $photo_type = tutor_utils()->array_get('type', $photo);
63
64 if ( $photo_size && strpos( $photo_type, 'image' ) !== false ) {
65 if ( ! function_exists( 'wp_handle_upload' ) ) {
66 require_once ABSPATH . 'wp-admin/includes/file.php';
67 }
68
69 $upload_overrides = array( 'test_form' => false );
70 $movefile = wp_handle_upload( $photo, $upload_overrides );
71
72 if ( $movefile && ! isset( $movefile['error'] ) ) {
73 $file_path = tutor_utils()->array_get( 'file', $movefile );
74 $file_url = tutor_utils()->array_get( 'url', $movefile );
75
76 $media_id = wp_insert_attachment(
77 array(
78 'guid' => $file_path,
79 'post_mime_type' => mime_content_type( $file_path ),
80 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_url ) ),
81 'post_content' => '',
82 'post_status' => 'inherit',
83 ),
84 $file_path,
85 0
86 );
87
88 if ( $media_id ) {
89 // wp_generate_attachment_metadata() won't work if you do not include this file
90 require_once ABSPATH . 'wp-admin/includes/image.php';
91
92 // Generate and save the attachment metas into the database
93 wp_update_attachment_metadata( $media_id, wp_generate_attachment_metadata( $media_id, $file_path ) );
94
95 // Update it to user profile
96 $this->delete_existing_user_photo( $user_id, tutor_sanitize_data($_POST['photo_type']) );
97 update_user_meta( $user_id, $meta_key, $media_id );
98
99 exit( json_encode( array( 'status' => 'success' ) ) );
100 }
101 }
102 }
103 }
104
105 public function profile_update($user_id){
106 if (tutor_utils()->array_get('tutor_action', $_POST) !== 'tutor_profile_update_by_wp' ){
107 return;
108 }
109
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 $_tutor_profile_image = wp_kses_post( tutor_utils()->avalue_dot( '_tutor_profile_photo', $_POST ) );
113
114 update_user_meta( $user_id, '_tutor_profile_job_title', $_tutor_profile_job_title );
115 update_user_meta( $user_id, '_tutor_profile_bio', $_tutor_profile_bio );
116 update_user_meta( $user_id, '_tutor_profile_photo', $_tutor_profile_image );
117 }
118
119 public function set_user_role( $user_id, $role, $old_roles ) {
120 $instructor_role = tutor()->instructor_role;
121
122 if ( in_array( $instructor_role, $old_roles ) ) {
123 // tutor_utils()->remove_instructor_role($user_id);
124 }
125
126 // if ($role === $instructor_role){
127 if ( $role === $instructor_role || in_array( $instructor_role, $old_roles ) ) {
128 tutor_utils()->add_instructor_role( $user_id );
129 }
130 }
131
132 public function hide_notices() {
133 if(is_admin() && isset( $_GET['tutor-hide-notice'] ) && $_GET['tutor-hide-notice']=='registration') {
134 tutor_utils()->checking_nonce('get');
135
136 if ( isset( $_GET['tutor-registration'] ) && $_GET['tutor-registration'] === 'enable' ) {
137 update_option( 'users_can_register', 1 );
138 } else {
139 self::$hide_registration_notice = true;
140 setcookie( 'tutor_notice_hide_registration', 1, time() + ( 86400 * 30 ), tutor()->basepath );
141 }
142 }
143 }
144
145 public function show_registration_disabled() {
146
147 if (
148 self::$hide_registration_notice ||
149 !tutor_utils()->is_tutor_dashboard() ||
150 get_option( 'users_can_register' ) ||
151 isset( $_COOKIE['tutor_notice_hide_registration'] ) ||
152 ! current_user_can( 'manage_options' )
153 ) {
154 return;
155 }
156
157 $hide_url = wp_nonce_url( add_query_arg( 'tutor-hide-notice', 'registration' ), tutor()->nonce_action, tutor()->nonce );
158 ?>
159 <div class="wrap tutor-user-registration-notice-wrapper">
160 <div class="tutor-user-registration-notice">
161 <div>
162 <img src="<?php echo esc_url( tutor()->url . 'assets/images/icon-info-round.svg' ); ?>"/>
163 </div>
164 <div>
165 <?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".' ); ?>
166 </div>
167 <div>
168 <a href="<?php echo esc_url( add_query_arg( 'tutor-registration', 'enable', $hide_url ) ); ?>"><?php _e( 'Enable', 'tutor' ); ?></a>
169 <hr/>
170 <a href="<?php echo esc_url( $hide_url ); ?>"><?php _e( 'Dismiss', 'tutor' ); ?></a>
171 </div>
172 </div>
173 </div>
174 <?php
175 }
176 }
177