| @@ -9,10 +9,8 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace TUTOR; |
| 12 | 12 | |
| 13 | -use Tutor\GDPR\Controllers\LegalConsent; | |
| 14 | - | |
| 15 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | 14 | exit; |
| 17 | 15 | } |
| 18 | 16 | |
| @@ -39,9 +37,9 @@ | ||
| 39 | 37 | */ |
| 40 | 38 | public function __construct() { |
| 41 | 39 | add_action( 'template_redirect', array( $this, 'register_student' ) ); |
| 42 | 40 | add_filter( 'get_avatar_url', array( $this, 'filter_avatar' ), 10, 3 ); |
| 43 | - add_action( 'wp_ajax_tutor_social_profile', array( $this, 'tutor_social_profile' ) ); | |
| 41 | + add_action( 'tutor_action_tutor_social_profile', array( $this, 'tutor_social_profile' ) ); | |
| 44 | 42 | add_action( 'wp_ajax_tutor_profile_password_reset', array( $this, 'tutor_reset_password' ) ); |
| 45 | 43 | add_action( 'wp_ajax_tutor_update_profile', array( $this, 'update_profile' ) ); |
| 46 | 44 | } |
| 47 | 45 | |
| @@ -59,8 +57,9 @@ | ||
| 59 | 57 | } |
| 60 | 58 | |
| 61 | 59 | // Checking nonce. |
| 62 | 60 | tutor_utils()->checking_nonce(); |
| 61 | + | |
| 63 | 62 | $required_fields = apply_filters( |
| 64 | 63 | 'tutor_student_registration_required_fields', |
| 65 | 64 | array( |
| 66 | 65 | 'first_name' => __( 'First name field is required', 'tutor' ), |
| @@ -77,8 +76,9 @@ | ||
| 77 | 76 | // Registration error push into validation_errors. |
| 78 | 77 | $errors = apply_filters( 'registration_errors', new \WP_Error(), '', '' ); |
| 79 | 78 | foreach ( $errors->errors as $key => $value ) { |
| 80 | 79 | $validation_errors[ $key ] = $value[0]; |
| 80 | + | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | foreach ( $required_fields as $required_key => $required_value ) { |
| 84 | 84 | if ( empty( Input::post( $required_key, '' ) ) ) { |
| @@ -85,18 +85,11 @@ | ||
| 85 | 85 | $validation_errors[ $required_key ] = $required_value; |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - // @since 4.0.0 legal consent added. | |
| 90 | - $validate_consent = LegalConsent::validate_consent( LegalConsent::DISPLAY_ON_STD_REG, $_POST ); | |
| 91 | - if ( is_wp_error( $validate_consent ) ) { | |
| 92 | - $validation_errors[ $validate_consent->get_error_code() ] = $validate_consent->get_error_message(); | |
| 93 | - } | |
| 94 | - | |
| 95 | 89 | if ( ! filter_var( tutor_utils()->input_old( 'email' ), FILTER_VALIDATE_EMAIL ) ) { |
| 96 | 90 | $validation_errors['email'] = __( 'Valid E-Mail is required', 'tutor' ); |
| 97 | 91 | } |
| 98 | - | |
| 99 | 92 | if ( tutor_utils()->input_old( 'password' ) !== tutor_utils()->input_old( 'password_confirmation' ) ) { |
| 100 | 93 | $validation_errors['password_confirmation'] = __( 'Your passwords should match each other. Please recheck.', 'tutor' ); |
| 101 | 94 | } |
| 102 | 95 | |
| @@ -110,9 +103,10 @@ | ||
| 110 | 103 | $last_name = sanitize_text_field( tutor_utils()->input_old( 'last_name' ) ); |
| 111 | 104 | $email = sanitize_text_field( tutor_utils()->input_old( 'email' ) ); |
| 112 | 105 | $user_login = sanitize_text_field( tutor_utils()->input_old( 'user_login' ) ); |
| 113 | 106 | $password = sanitize_text_field( tutor_utils()->input_old( 'password' ) ); |
| 114 | - $userdata = array( | |
| 107 | + | |
| 108 | + $userdata = array( | |
| 115 | 109 | 'user_login' => $user_login, |
| 116 | 110 | 'user_email' => $email, |
| 117 | 111 | 'first_name' => $first_name, |
| 118 | 112 | 'last_name' => $last_name, |
| @@ -120,10 +114,12 @@ | ||
| 120 | 114 | ); |
| 121 | 115 | |
| 122 | 116 | global $wpdb; |
| 123 | 117 | $wpdb->query( 'START TRANSACTION' ); |
| 118 | + | |
| 124 | 119 | $user_id = wp_insert_user( $userdata ); |
| 125 | 120 | $enroll_attempt = Input::post( 'tutor_course_enroll_attempt', '' ); |
| 121 | + | |
| 126 | 122 | if ( is_wp_error( $user_id ) ) { |
| 127 | 123 | $this->error_msgs = $user_id->get_error_messages(); |
| 128 | 124 | add_filter( 'tutor_student_register_validation_errors', array( $this, 'tutor_student_form_validation_errors' ) ); |
| 129 | 125 | return; |
| @@ -130,14 +126,10 @@ | ||
| 130 | 126 | } |
| 131 | 127 | |
| 132 | 128 | $user = get_user_by( 'id', $user_id ); |
| 133 | 129 | |
| 134 | - $redirect_url = ''; | |
| 135 | - | |
| 136 | 130 | $is_req_email_verification = apply_filters( 'tutor_require_email_verification', false ); |
| 137 | 131 | if ( $is_req_email_verification ) { |
| 138 | - $redirect_url = tutor_utils()->student_register_url(); | |
| 139 | - | |
| 140 | 132 | do_action( 'tutor_send_verification_mail', $user, $enroll_attempt ); |
| 141 | 133 | $reg_done = apply_filters( 'tutor_registration_done', true ); |
| 142 | 134 | if ( ! $reg_done ) { |
| 143 | 135 | $wpdb->query( 'ROLLBACK' ); |
| @@ -143,9 +135,8 @@ | ||
| 143 | 135 | $wpdb->query( 'ROLLBACK' ); |
| 144 | 136 | return; |
| 145 | 137 | } else { |
| 146 | 138 | $wpdb->query( 'COMMIT' ); |
| 147 | - | |
| 148 | 139 | } |
| 149 | 140 | } else { |
| 150 | 141 | /** |
| 151 | 142 | * Tutor Free - reqular student reg process. |
| @@ -153,10 +144,10 @@ | ||
| 153 | 144 | $wpdb->query( 'COMMIT' ); |
| 154 | 145 | |
| 155 | 146 | wp_set_current_user( $user_id, $user->user_login ); |
| 156 | 147 | wp_set_auth_cookie( $user_id ); |
| 148 | + | |
| 157 | 149 | do_action( 'tutor_after_student_signup', $user_id ); |
| 158 | - | |
| 159 | 150 | // since 1.9.8 do enroll if guest attempt to enroll. |
| 160 | 151 | if ( ! empty( $enroll_attempt ) ) { |
| 161 | 152 | do_action( 'tutor_do_enroll_after_login_if_attempt', $enroll_attempt, $user_id ); |
| 162 | 153 | } |
| @@ -161,16 +152,18 @@ | ||
| 161 | 152 | do_action( 'tutor_do_enroll_after_login_if_attempt', $enroll_attempt, $user_id ); |
| 162 | 153 | } |
| 163 | 154 | |
| 164 | 155 | // Redirect page. |
| 165 | - $redirect_url = tutor_utils()->array_get( 'redirect_to', $_REQUEST ); //phpcs:ignore | |
| 166 | - if ( ! $redirect_url ) { | |
| 167 | - $redirect_url = tutor_utils()->tutor_dashboard_url(); | |
| 156 | + $redirect_page = tutor_utils()->array_get( 'redirect_to', $_REQUEST ); //phpcs:ignore | |
| 157 | + if ( ! $redirect_page ) { | |
| 158 | + $redirect_page = tutor_utils()->tutor_dashboard_url(); | |
| 168 | 159 | } |
| 160 | + wp_safe_redirect( apply_filters( 'tutor_student_register_redirect_url', $redirect_page, $user ) ); | |
| 161 | + die(); | |
| 169 | 162 | } |
| 170 | 163 | |
| 171 | - do_action( 'tutor_new_user_registered', $user, $validate_consent ); | |
| 172 | - wp_safe_redirect( apply_filters( 'tutor_student_register_redirect_url', tutor_utils()->get_nocache_url( $redirect_url ), $user ) ); | |
| 164 | + $registration_page = tutor_utils()->student_register_url(); | |
| 165 | + wp_safe_redirect( $registration_page ); | |
| 173 | 166 | die(); |
| 174 | 167 | } |
| 175 | 168 | |
| 176 | 169 | /** |
| @@ -200,11 +193,10 @@ | ||
| 200 | 193 | |
| 201 | 194 | $first_name = sanitize_text_field( tutor_utils()->input_old( 'first_name' ) ); |
| 202 | 195 | $last_name = sanitize_text_field( tutor_utils()->input_old( 'last_name' ) ); |
| 203 | 196 | $phone_number = sanitize_text_field( tutor_utils()->input_old( 'phone_number' ) ); |
| 204 | - $tutor_profile_bio = wp_kses( Input::post( 'tutor_profile_bio', '', Input::TYPE_KSES_POST ), tutor_utils()->allowed_profile_bio_tags() ); | |
| 197 | + $tutor_profile_bio = wp_kses_post( tutor_utils()->input_old( 'tutor_profile_bio' ) ); | |
| 205 | 198 | $tutor_profile_job_title = sanitize_text_field( tutor_utils()->input_old( 'tutor_profile_job_title' ) ); |
| 206 | - $timezone = Input::post( 'timezone', '' ); | |
| 207 | 199 | |
| 208 | 200 | $display_name = sanitize_text_field( tutor_utils()->input_old( 'display_name' ) ); |
| 209 | 201 | |
| 210 | 202 | $userdata = array( |
| @@ -212,18 +204,25 @@ | ||
| 212 | 204 | 'first_name' => $first_name, |
| 213 | 205 | 'last_name' => $last_name, |
| 214 | 206 | 'display_name' => $display_name, |
| 215 | 207 | ); |
| 208 | + $user_id = wp_update_user( $userdata ); | |
| 216 | 209 | |
| 217 | - $user_id = wp_update_user( $userdata ); | |
| 210 | + if ( ! is_wp_error( $user_id ) ) { | |
| 211 | + update_user_meta( $user_id, 'phone_number', $phone_number ); | |
| 212 | + update_user_meta( $user_id, '_tutor_profile_bio', $tutor_profile_bio ); | |
| 213 | + update_user_meta( $user_id, '_tutor_profile_job_title', $tutor_profile_job_title ); | |
| 218 | 214 | |
| 219 | - if ( ! is_wp_error( $user_id ) ) { | |
| 220 | - update_user_meta( $user_id, User::PHONE_NUMBER_META, $phone_number ); | |
| 221 | - update_user_meta( $user_id, User::PROFILE_BIO_META, $tutor_profile_bio ); | |
| 222 | - update_user_meta( $user_id, User::PROFILE_JOB_TITLE_META, $tutor_profile_job_title ); | |
| 223 | - update_user_meta( $user_id, User::TIMEZONE_META, $timezone ); | |
| 215 | + $tutor_user_social = tutor_utils()->tutor_user_social_icons(); | |
| 216 | + foreach ( $tutor_user_social as $key => $social ) { | |
| 217 | + $user_social_value = sanitize_text_field( tutor_utils()->input_old( $key ) ); | |
| 218 | + if ( $user_social_value ) { | |
| 219 | + update_user_meta( $user_id, $key, $user_social_value ); | |
| 220 | + } else { | |
| 221 | + delete_user_meta( $user_id, $key ); | |
| 222 | + } | |
| 223 | + } | |
| 224 | 224 | } |
| 225 | - | |
| 226 | 225 | do_action( 'tutor_profile_update_after', $user_id ); |
| 227 | 226 | |
| 228 | 227 | wp_send_json_success( array( 'message' => __( 'Profile Updated', 'tutor' ) ) ); |
| 229 | 228 | } |
| @@ -336,73 +335,8 @@ | ||
| 336 | 335 | } else { |
| 337 | 336 | delete_user_meta( $user_id, $key ); |
| 338 | 337 | } |
| 339 | 338 | } |
| 340 | - | |
| 341 | - wp_send_json_success( array( 'message' => __( 'Social Profile Updated', 'tutor' ) ) ); | |
| 339 | + wp_safe_redirect( wp_get_raw_referer() ); | |
| 342 | 340 | die(); |
| 343 | - } | |
| 344 | - | |
| 345 | - /** | |
| 346 | - * Get courses tab configuration for student dashboard | |
| 347 | - * | |
| 348 | - * Generates the tab structure for displaying student courses with dropdown options | |
| 349 | - * for enrolled, active, and completed courses including counts and navigation URLs. | |
| 350 | - * | |
| 351 | - * @since 4.0.0 | |
| 352 | - * | |
| 353 | - * @param string $active_tab The currently active tab identifier. | |
| 354 | - * @param array $post_type_args Query arguments for post type filtering. | |
| 355 | - * @param int $enrolled_course_count Number of enrolled courses. | |
| 356 | - * @param int $active_course_count Number of active courses. | |
| 357 | - * @param int $completed_course_count Number of completed courses. | |
| 358 | - * | |
| 359 | - * @return array Array containing tab configuration with dropdown options | |
| 360 | - */ | |
| 361 | - public function get_courses_tab( $active_tab, $post_type_args, $enrolled_course_count, $active_course_count, $completed_course_count ) { | |
| 362 | - $courses_tab = array( | |
| 363 | - array( | |
| 364 | - 'type' => 'dropdown', | |
| 365 | - 'active' => ( ( 'courses' === $active_tab ) || ( 'courses/active-courses' === $active_tab ) || ( 'courses/completed-courses' === $active_tab ) ) ? true : false, | |
| 366 | - 'options' => array( | |
| 367 | - array( | |
| 368 | - 'label' => __( 'Enrolled', 'tutor' ), | |
| 369 | - 'icon' => Icon::ENROLLED, | |
| 370 | - 'url' => esc_url( add_query_arg( $post_type_args, tutor_utils()->get_tutor_dashboard_page_permalink( 'courses' ) ) ), | |
| 371 | - 'active' => 'courses' === $active_tab ? true : false, | |
| 372 | - 'count' => $enrolled_course_count, | |
| 373 | - ), | |
| 374 | - array( | |
| 375 | - 'label' => __( 'Active', 'tutor' ), | |
| 376 | - 'icon' => Icon::PLAY_LINE_2, | |
| 377 | - 'url' => esc_url( add_query_arg( $post_type_args, tutor_utils()->get_tutor_dashboard_page_permalink( 'courses/active-courses' ) ) ), | |
| 378 | - 'active' => 'courses/active-courses' === $active_tab ? true : false, | |
| 379 | - 'count' => $active_course_count, | |
| 380 | - ), | |
| 381 | - array( | |
| 382 | - 'label' => __( 'Complete', 'tutor' ), | |
| 383 | - 'icon' => Icon::COMPLETED_CIRCLE, | |
| 384 | - 'url' => esc_url( add_query_arg( $post_type_args, tutor_utils()->get_tutor_dashboard_page_permalink( 'courses/completed-courses' ) ) ), | |
| 385 | - 'active' => 'courses/completed-courses' === $active_tab ? true : false, | |
| 386 | - 'count' => $completed_course_count, | |
| 387 | - ), | |
| 388 | - ), | |
| 389 | - ), | |
| 390 | - array( | |
| 391 | - 'type' => 'link', | |
| 392 | - 'label' => __( 'Wishlist', 'tutor' ), | |
| 393 | - 'icon' => Icon::WISHLIST, | |
| 394 | - 'url' => esc_url( tutor_utils()->tutor_dashboard_url( 'courses/wishlist' ) ), | |
| 395 | - 'active' => 'courses/wishlist' === $active_tab ? true : false, | |
| 396 | - ), | |
| 397 | - array( | |
| 398 | - 'type' => 'link', | |
| 399 | - 'label' => __( 'Quiz Attempts', 'tutor' ), | |
| 400 | - 'icon' => Icon::QUIZ_2, | |
| 401 | - 'url' => esc_url( tutor_utils()->tutor_dashboard_url( 'courses/my-quiz-attempts' ) ), | |
| 402 | - 'active' => 'courses/my-quiz-attempts' === $active_tab ? true : false, | |
| 403 | - ), | |
| 404 | - ); | |
| 405 | - | |
| 406 | - return $courses_tab; | |
| 407 | 341 | } |
| 408 | 342 | } |