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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 / Instructor.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 4 years ago Backend_Page_Trait.php 4 years ago Course.php 4 years ago Course_Filter.php 4 years ago Course_List.php 4 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 4 years ago FormHandler.php 4 years ago Frontend.php 4 years ago Gutenberg.php 4 years ago Input.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options_V2.php 4 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 4 years ago Theme_Compatibility.php 5 years ago Tools.php 4 years ago Tools_V2.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
Instructor.php
333 lines
1 <?php
2
3 /**
4 * Class Instructor
5 *
6 * @package TUTOR
7 *
8 * @since v.1.0.0
9 */
10
11 namespace TUTOR;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17
18 class Instructor {
19
20
21 protected $error_msgs = '';
22 public function __construct() {
23 add_action( 'template_redirect', array( $this, 'register_instructor' ) );
24 add_action( 'template_redirect', array( $this, 'apply_instructor' ) );
25
26 // Add instructor from admin panel.
27 add_action( 'wp_ajax_tutor_add_instructor', array( $this, 'add_new_instructor' ) );
28
29 /**
30 * Instructor Approval
31 * Block Unblock
32 *
33 * @since v.1.5.3
34 */
35 add_action( 'wp_ajax_instructor_approval_action', array( $this, 'instructor_approval_action' ) );
36
37 /**
38 * Check if instructor can publish courses
39 *
40 * @since v.1.5.9
41 */
42 add_action( 'tutor_option_save_after', array( $this, 'can_publish_tutor_courses' ) );
43
44 /**
45 * Hide instructor rejection message
46 *
47 * @since v1.9.2
48 */
49 add_action( 'wp_loaded', array( $this, 'hide_instructor_notice' ) );
50 }
51
52 /**
53 * Register new user and mark him as instructor
54 *
55 * @since v.1.0.0
56 */
57 public function register_instructor() {
58 if ( ! isset( $_POST['tutor_action'] ) || $_POST['tutor_action'] !== 'tutor_register_instructor' ) {
59 return;
60 }
61 // Checking nonce
62 tutor_utils()->checking_nonce();
63
64 $required_fields = apply_filters(
65 'tutor_instructor_registration_required_fields',
66 array(
67 'first_name' => __( 'First name field is required', 'tutor' ),
68 'last_name' => __( 'Last name field is required', 'tutor' ),
69 'email' => __( 'E-Mail field is required', 'tutor' ),
70 'user_login' => __( 'User Name field is required', 'tutor' ),
71 'password' => __( 'Password field is required', 'tutor' ),
72 'password_confirmation' => __( 'Password Confirmation field is required', 'tutor' ),
73 )
74 );
75
76 $validation_errors = array();
77
78 /*
79 *registration_errors
80 *push into validation_errors
81 */
82 $errors = apply_filters( 'registration_errors', new \WP_Error(), '', '' );
83 foreach ( $errors->errors as $key => $value ) {
84 $validation_errors[ $key ] = $value[0];
85 }
86
87 foreach ( $required_fields as $required_key => $required_value ) {
88 if ( empty( $_POST[ $required_key ] ) ) {
89 $validation_errors[ $required_key ] = $required_value;
90 }
91 }
92
93 if ( ! filter_var( tutor_utils()->input_old( 'email' ), FILTER_VALIDATE_EMAIL ) ) {
94 $validation_errors['email'] = __( 'Valid E-Mail is required', 'tutor' );
95 }
96 if ( tutor_utils()->input_old( 'password' ) !== tutor_utils()->input_old( 'password_confirmation' ) ) {
97 $validation_errors['password_confirmation'] = __( 'Your passwords should match each other. Please recheck.', 'tutor' );
98 }
99
100 if ( count( $validation_errors ) ) {
101 $this->error_msgs = $validation_errors;
102 add_filter( 'tutor_instructor_register_validation_errors', array( $this, 'tutor_instructor_form_validation_errors' ) );
103 return;
104 }
105
106 $first_name = sanitize_text_field( tutor_utils()->input_old( 'first_name' ) );
107 $last_name = sanitize_text_field( tutor_utils()->input_old( 'last_name' ) );
108 $email = sanitize_text_field( tutor_utils()->input_old( 'email' ) );
109 $user_login = sanitize_text_field( tutor_utils()->input_old( 'user_login' ) );
110 $password = sanitize_text_field( tutor_utils()->input_old( 'password' ) );
111
112 $userdata = array(
113 'user_login' => $user_login,
114 'user_email' => $email,
115 'first_name' => $first_name,
116 'last_name' => $last_name,
117 // 'role' => tutor()->instructor_role,
118 'user_pass' => $password,
119 );
120
121 $user_id = wp_insert_user( $userdata );
122 if ( ! is_wp_error( $user_id ) ) {
123 update_user_meta( $user_id, '_is_tutor_instructor', tutor_time() );
124 update_user_meta( $user_id, '_tutor_instructor_status', apply_filters( 'tutor_initial_instructor_status', 'pending' ) );
125
126 do_action( 'tutor_new_instructor_after', $user_id );
127
128 $user = get_user_by( 'id', $user_id );
129 if ( $user ) {
130 wp_set_current_user( $user_id, $user->user_login );
131 wp_set_auth_cookie( $user_id );
132 }
133 } else {
134 $this->error_msgs = $user_id->get_error_messages();
135 add_filter( 'tutor_instructor_register_validation_errors', array( $this, 'tutor_instructor_form_validation_errors' ) );
136 return;
137 }
138
139 wp_redirect( tutor_utils()->input_old( '_wp_http_referer' ) );
140 die();
141 }
142
143 public function tutor_instructor_form_validation_errors() {
144 return $this->error_msgs;
145 }
146
147 /**
148 *
149 * Usage for instructor applying when a user already logged in
150 *
151 * @since v.1.0.0
152 */
153 public function apply_instructor() {
154 if ( ! isset( $_POST['tutor_action'] ) || $_POST['tutor_action'] !== 'tutor_apply_instructor' ) {
155 return;
156 }
157 // Checking nonce
158 tutor_utils()->checking_nonce();
159
160 $user_id = get_current_user_id();
161 if ( $user_id ) {
162 if ( tutor_utils()->is_instructor() ) {
163 die( __( 'Already applied for instructor', 'tutor' ) );
164 } else {
165 update_user_meta( $user_id, '_is_tutor_instructor', tutor_time() );
166 update_user_meta( $user_id, '_tutor_instructor_status', apply_filters( 'tutor_initial_instructor_status', 'pending' ) );
167
168 do_action( 'tutor_new_instructor_after', $user_id );
169 }
170 } else {
171 die( __( 'Permission denied', 'tutor' ) );
172 }
173
174 wp_redirect( tutor_utils()->input_old( '_wp_http_referer' ) );
175 die();
176 }
177
178
179 public function add_new_instructor() {
180 tutor_utils()->checking_nonce();
181
182 // Only admin should be able to add instructor
183 if ( ! current_user_can( 'manage_options' ) || ! get_option( 'users_can_register', false ) ) {
184 wp_send_json_error();
185 }
186
187 $required_fields = apply_filters(
188 'tutor_instructor_registration_required_fields',
189 array(
190 'first_name' => __( 'First name field is required', 'tutor' ),
191 'last_name' => __( 'Last name field is required', 'tutor' ),
192 'email' => __( 'E-Mail field is required', 'tutor' ),
193 'user_login' => __( 'User Name field is required', 'tutor' ),
194 'phone_number' => __( 'Phone Number field is required', 'tutor' ),
195 'password' => __( 'Password field is required', 'tutor' ),
196 'password_confirmation' => __( 'Your passwords should match each other. Please recheck.', 'tutor' ),
197 )
198 );
199
200 $validation_errors = array();
201 foreach ( $required_fields as $required_key => $required_value ) {
202 if ( empty( $_POST[ $required_key ] ) ) {
203 $validation_errors[ $required_key ] = $required_value;
204 }
205 }
206
207 if ( ! filter_var( tutor_utils()->input_old( 'email' ), FILTER_VALIDATE_EMAIL ) ) {
208 $validation_errors['email'] = __( 'Valid E-Mail is required', 'tutor' );
209 }
210 if ( tutor_utils()->input_old( 'password' ) !== tutor_utils()->input_old( 'password_confirmation' ) ) {
211 $validation_errors['password_confirmation'] = __( 'Your passwords should match each other. Please recheck.', 'tutor' );
212 }
213
214 if ( count( $validation_errors ) ) {
215 wp_send_json_error( array( 'errors' => $validation_errors ) );
216 }
217
218 $first_name = sanitize_text_field( tutor_utils()->input_old( 'first_name' ) );
219 $last_name = sanitize_text_field( tutor_utils()->input_old( 'last_name' ) );
220 $email = sanitize_text_field( tutor_utils()->input_old( 'email' ) );
221 $user_login = sanitize_text_field( tutor_utils()->input_old( 'user_login' ) );
222 $phone_number = sanitize_text_field( tutor_utils()->input_old( 'phone_number' ) );
223 $password = sanitize_text_field( tutor_utils()->input_old( 'password' ) );
224 $tutor_profile_bio = wp_kses_post( tutor_utils()->input_old( 'tutor_profile_bio' ) );
225 $tutor_profile_job_title = sanitize_text_field( tutor_utils()->input_old( 'tutor_profile_job_title' ) );
226
227 $userdata = apply_filters(
228 'add_new_instructor_data',
229 array(
230 'user_login' => $user_login,
231 'user_email' => $email,
232 'first_name' => $first_name,
233 'last_name' => $last_name,
234 'role' => tutor()->instructor_role,
235 'user_pass' => $password,
236 )
237 );
238
239 do_action( 'tutor_add_new_instructor_before' );
240
241 $user_id = wp_insert_user( $userdata );
242 if ( ! is_wp_error( $user_id ) ) {
243 update_user_meta( $user_id, 'phone_number', $phone_number );
244 update_user_meta( $user_id, 'description', $tutor_profile_bio );
245 update_user_meta( $user_id, '_tutor_profile_bio', $tutor_profile_bio );
246 update_user_meta( $user_id, '_tutor_profile_job_title', $tutor_profile_job_title );
247 update_user_meta( $user_id, '_is_tutor_instructor', tutor_time() );
248 update_user_meta( $user_id, '_tutor_instructor_status', apply_filters( 'tutor_initial_instructor_status', 'approved' ) );
249
250 do_action( 'tutor_add_new_instructor_after', $user_id );
251
252 wp_send_json_success( array( 'msg' => __( 'Instructor has been added successfully', 'tutor' ) ) );
253 }
254
255 wp_send_json_error( array( 'errors' => $user_id ) );
256 }
257
258 public function instructor_approval_action() {
259 tutor_utils()->checking_nonce();
260
261 if ( ! current_user_can( 'manage_options' ) ) {
262 wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) );
263 }
264
265 $instructor_id = (int) sanitize_text_field( tutor_utils()->array_get( 'instructor_id', $_POST ) );
266 $action = sanitize_text_field( tutor_utils()->array_get( 'action_name', $_POST ) );
267
268 if ( 'approve' === $action ) {
269 do_action( 'tutor_before_approved_instructor', $instructor_id );
270
271 update_user_meta( $instructor_id, '_tutor_instructor_status', 'approved' );
272 update_user_meta( $instructor_id, '_tutor_instructor_approved', tutor_time() );
273
274 $instructor = new \WP_User( $instructor_id );
275 $instructor->add_role( tutor()->instructor_role );
276
277 // Send E-Mail to this user about instructor approval via hook
278 do_action( 'tutor_after_approved_instructor', $instructor_id );
279 }
280
281 if ( 'blocked' === $action ) {
282 do_action( 'tutor_before_blocked_instructor', $instructor_id );
283 update_user_meta( $instructor_id, '_tutor_instructor_status', 'blocked' );
284
285 $instructor = new \WP_User( $instructor_id );
286 $instructor->remove_role( tutor()->instructor_role );
287 do_action( 'tutor_after_blocked_instructor', $instructor_id );
288
289 // TODO: send E-Mail to this user about instructor blocked, should via hook
290 }
291
292 if ( 'remove-instructor' === $action ) {
293 do_action( 'tutor_before_rejected_instructor', $instructor_id );
294
295 $user = new \WP_User( $instructor_id );
296 $user->remove_role( tutor()->instructor_role );
297
298 tutor_utils()->remove_instructor_role( $instructor_id );
299 update_user_meta( $instructor_id, '_is_tutor_instructor_rejected', tutor_time() );
300 update_user_meta( $instructor_id, 'tutor_instructor_show_rejection_message', true );
301
302 // Send E-Mail to this user about instructor rejection via hook
303 do_action( 'tutor_after_rejected_instructor', $instructor_id );
304 }
305
306 wp_send_json_success();
307 }
308
309 public function hide_instructor_notice() {
310 if ( isset( $_GET['tutor_action'] ) && $_GET['tutor_action'] == 'hide_instructor_notice' ) {
311 delete_user_meta( get_current_user_id(), 'tutor_instructor_show_rejection_message' );
312 }
313 }
314
315 /**
316 * Can instructor publish courses directly
317 * Fixed in Gutenberg @since v.1.5.9
318 */
319
320 public function can_publish_tutor_courses() {
321 $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
322
323 $instructor_role = tutor()->instructor_role;
324 $instructor = get_role( $instructor_role );
325
326 if ( $can_publish_course ) {
327 $instructor->add_cap( 'publish_tutor_courses' );
328 } else {
329 $instructor->remove_cap( 'publish_tutor_courses' );
330 }
331 }
332 }
333