PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/class-lp-forms-handler.php +50 -14 4.2.04.4.8 View file →
@@ -1,5 +1,8 @@
1 1 <?php
2 +
3 +use LearnPress\Background\LPBackgroundAjax;
4 +
2 5 /**
3 6 * Class LP_Forms_Handler
4 7 *
5 8 * Process action for submitting forms
@@ -52,8 +55,19 @@
52 55 $result['message'][] = learn_press_get_message( __( 'Thank you! Your message has been sent.', 'learnpress' ), 'success' );
53 56 $user = get_user_by( 'email', $args['bat_email'] );
54 57
55 58 update_user_meta( $user->ID, '_requested_become_teacher', 'yes' );
59 +
60 + /**
61 + * Send email to admin when user request to become a teacher
62 + * @use SendEmailAjax::send_mail_become_a_teacher_request
63 + */
64 + $data_send = [
65 + 'params' => [ $args ],
66 + 'lp-load-ajax' => 'send_mail_become_a_teacher_request',
67 + ];
68 + LPBackgroundAjax::handle( $data_send );
69 +
56 70 do_action( 'learn-press/become-a-teacher-sent', $args );
57 71 }
58 72
59 73 learn_press_maybe_send_json( $result );
@@ -104,14 +118,15 @@
104 118 if ( is_wp_error( $user ) ) {
105 119 throw new Exception( $user->get_error_message() );
106 120 } else {
107 121 if ( ! empty( $_POST['redirect'] ) ) {
108 - $redirect = LP_Helper::sanitize_params_submitted( $_POST['redirect'] );
122 + $url_redirect = LP_Helper::sanitize_params_submitted( $_POST['redirect'] );
109 123 } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
110 - $redirect = LP_Helper::sanitize_params_submitted( $_REQUEST['_wp_http_referer'] );
124 + $url_redirect = LP_Request::get_param( '_wp_http_referer' );
111 125 } else {
112 - $redirect = LP_Request::get_redirect( learn_press_get_page_link( 'profile' ) );
126 + $url_redirect = LP_Request::get_redirect( learn_press_get_page_link( 'profile' ) );
113 127 }
128 + $url_redirect = apply_filters( 'learn-press/login-redirect', $url_redirect, $user );
114 129
115 130 $message_data = [
116 131 'status' => 'success',
117 132 'content' => __( 'Login successfully!', 'learnpress' ),
@@ -116,9 +131,9 @@
116 131 'status' => 'success',
117 132 'content' => __( 'Login successfully!', 'learnpress' ),
118 133 ];
119 134 learn_press_set_message( $message_data );
120 - wp_redirect( wp_validate_redirect( $redirect, learn_press_get_current_url() ) );
135 + wp_redirect( wp_validate_redirect( $url_redirect, LP_Helper::getUrlCurrent() ) );
121 136 exit();
122 137 }
123 138 } catch ( Exception $e ) {
124 139 $message_data = [
@@ -204,16 +219,16 @@
204 219 ];
205 220 learn_press_set_message( $message_data );
206 221
207 222 if ( ! empty( $_POST['redirect'] ) ) {
208 - $redirect = wp_sanitize_redirect( wp_unslash( $_POST['redirect'] ) );
223 + $url_redirect = wp_sanitize_redirect( wp_unslash( $_POST['redirect'] ) );
209 224 } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
210 - $redirect = wp_unslash( $_REQUEST['_wp_http_referer'] );
225 + $url_redirect = wp_unslash( $_REQUEST['_wp_http_referer'] );
211 226 } else {
212 - $redirect = LP_Request::get_redirect( learn_press_get_page_link( 'profile' ) );
227 + $url_redirect = LP_Request::get_redirect( learn_press_get_page_link( 'profile' ) );
213 228 }
214 -
215 - wp_redirect( wp_validate_redirect( $redirect, learn_press_get_current_url() ) );
229 + $url_redirect = apply_filters( 'learn-press/register-redirect', $url_redirect, $new_customer );
230 + wp_redirect( wp_validate_redirect( $url_redirect, LP_Helper::getUrlCurrent() ) );
216 231 exit();
217 232
218 233 } catch ( Throwable $e ) {
219 234 $message_data = [
@@ -232,8 +247,13 @@
232 247 * @since 4.0.0
233 248 */
234 249 public static function learnpress_create_new_customer( $email = '', $username = '', $password = '', $confirm_password = '', $args = array(), $update_meta = array() ) {
235 250 try {
251 + $user_can_register = get_option( 'users_can_register' );
252 + if ( ! $user_can_register ) {
253 + throw new Exception( __( 'System WordPress does not allow register.', 'learnpress' ), 110 );
254 + }
255 +
236 256 if ( empty( $email ) || ! is_email( $email ) ) {
237 257 throw new Exception( __( 'Please provide a valid email address.', 'learnpress' ), 101 );
238 258 }
239 259
@@ -278,9 +298,9 @@
278 298 throw new Exception( __( 'Password and Confirm Password does not match!', 'learnpress' ), 108 );
279 299 }
280 300
281 301 $custom_fields = LP_Settings::get_option( 'register_profile_fields', [] );
282 - if ( $custom_fields && ! empty( $update_meta ) ) {
302 + if ( ! empty( $custom_fields ) ) {
283 303 foreach ( $custom_fields as $field ) {
284 304 if ( $field['required'] === 'yes' && empty( $update_meta[ $field['id'] ] ) ) {
285 305 throw new Exception( $field['name'] . __( ' is required field.', 'learnpress' ), 109 );
286 306 }
@@ -300,8 +320,15 @@
300 320 )
301 321 )
302 322 );
303 323
324 + // Add hook registration_errors of WordPress
325 + $errors = null;
326 + $errors = apply_filters( 'registration_errors', $errors, $username, $email );
327 + if ( is_wp_error( $errors ) ) {
328 + throw new Exception( $errors->get_error_message() );
329 + }
330 +
304 331 $customer_id = wp_insert_user( $new_customer_data );
305 332
306 333 do_action( 'lp/after_create_new_customer', $email, $username, $password, $confirm_password, $args, $update_meta );
307 334
@@ -344,11 +371,16 @@
344 371 break;
345 372 case 109:
346 373 $code_str = 'registration-custom-required-field';
347 374 break;
375 + case 110:
376 + $code_str = 'registration-not-allow';
377 + break;
348 378 default:
379 + $code_str = $e->getMessage();
349 380 break;
350 381 }
382 +
351 383 return new WP_Error( $code_str, $e->getMessage() );
352 384 }
353 385
354 386 return $customer_id;
@@ -375,13 +407,18 @@
375 407 } elseif ( email_exists( $update_data['user_email'] ) && $update_data['user_email'] !== $current_user->user_email ) {
376 408 return new WP_Error( 'error_email', esc_html__( 'This email address is already registered.', 'learnpress' ) );
377 409 }
378 410
379 - $custom_fields = LP_Settings::instance()->get( 'register_profile_fields' );
380 -
411 + $custom_fields = LP_Profile::get_register_fields_custom();
381 412 if ( $custom_fields && ! empty( $update_meta ) ) {
382 413 foreach ( $custom_fields as $field ) {
383 - if ( $field['required'] === 'yes' && empty( $update_meta[ $field['id'] ] ) ) {
414 + if ( $field['required'] !== 'yes' ) {
415 + continue;
416 + }
417 +
418 + $is_empty = empty( $update_meta[ $field['id'] ] );
419 + $is_empty = apply_filters( 'learn-press/profile/update-register-custom-field/is-require', $is_empty, $field );
420 + if ( $is_empty ) {
384 421 return new WP_Error( 'registration-custom-exists', $field['name'] . __( ' is required field.', 'learnpress' ) );
385 422 }
386 423 }
387 424 }
@@ -465,5 +502,4 @@
465 502 self::process_login();
466 503 self::process_register();
467 504 }
468 505 }
469 -