| @@ -1,425 +1,322 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | - * Manage Instructor | |
| 4 | + * Class Instructor | |
| 5 | + * @package TUTOR | |
| 4 | 6 | * |
| 5 | - * @package Tutor | |
| 6 | - * @author Themeum <support@themeum.com> | |
| 7 | - * @link https://themeum.com | |
| 8 | - * @since 1.0.0 | |
| 7 | + * @since v.1.0.0 | |
| 9 | 8 | */ |
| 10 | 9 | |
| 11 | 10 | namespace TUTOR; |
| 12 | 11 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) | |
| 14 | 13 | exit; |
| 15 | -} | |
| 16 | 14 | |
| 17 | -/** | |
| 18 | - * Instructor class | |
| 19 | - * | |
| 20 | - * @since 1.0.0 | |
| 21 | - */ | |
| 15 | + | |
| 22 | 16 | class Instructor { |
| 23 | 17 | |
| 24 | - /** | |
| 25 | - * Error message | |
| 26 | - * | |
| 27 | - * @var string | |
| 28 | - */ | |
| 29 | 18 | protected $error_msgs = ''; |
| 19 | + public function __construct() { | |
| 20 | + add_action('template_redirect', array($this, 'register_instructor')); | |
| 21 | + add_action('template_redirect', array($this, 'apply_instructor')); | |
| 30 | 22 | |
| 31 | - /** | |
| 32 | - * Constructor | |
| 33 | - * | |
| 34 | - * @since 1.0.0 | |
| 35 | - * | |
| 36 | - * @param bool $register_hook register hook or not. | |
| 37 | - * | |
| 38 | - * @return void | |
| 39 | - */ | |
| 40 | - public function __construct( $register_hook = true ) { | |
| 41 | - if ( ! $register_hook ) { | |
| 42 | - return; | |
| 43 | - } | |
| 44 | - add_action( 'template_redirect', array( $this, 'register_instructor' ) ); | |
| 45 | - add_action( 'template_redirect', array( $this, 'apply_instructor' ) ); | |
| 23 | + //Add instructor from admin panel. | |
| 24 | + add_action('wp_ajax_tutor_add_instructor', array($this, 'add_new_instructor')); | |
| 46 | 25 | |
| 47 | - // Add instructor from admin panel. | |
| 48 | - add_action( 'wp_ajax_tutor_add_instructor', array( $this, 'add_new_instructor' ) ); | |
| 49 | - | |
| 50 | 26 | /** |
| 51 | 27 | * Instructor Approval |
| 52 | 28 | * Block Unblock |
| 53 | 29 | * |
| 54 | - * @since 1.5.3 | |
| 30 | + * @since v.1.5.3 | |
| 55 | 31 | */ |
| 56 | - add_action( 'wp_ajax_instructor_approval_action', array( $this, 'instructor_approval_action' ) ); | |
| 32 | + add_action('wp_ajax_instructor_approval_action', array($this, 'instructor_approval_action')); | |
| 57 | 33 | |
| 58 | - /** | |
| 59 | - * Check if instructor can publish courses | |
| 60 | - * | |
| 61 | - * @since 1.5.9 | |
| 62 | - */ | |
| 63 | - add_action( 'tutor_option_save_after', array( $this, 'can_publish_tutor_courses' ) ); | |
| 34 | + /** | |
| 35 | + * Check if instructor can publish courses | |
| 36 | + * @since v.1.5.9 | |
| 37 | + */ | |
| 38 | + add_action('tutor_option_save_after', array($this, 'can_publish_tutor_courses')); | |
| 64 | 39 | |
| 65 | 40 | /** |
| 66 | 41 | * Hide instructor rejection message |
| 67 | - * | |
| 68 | - * @since 1.9.2 | |
| 42 | + * @since v1.9.2 | |
| 69 | 43 | */ |
| 70 | - add_action( 'wp_loaded', array( $this, 'hide_instructor_notice' ) ); | |
| 71 | - } | |
| 44 | + add_action( 'wp_loaded', array($this, 'hide_instructor_notice') ); | |
| 45 | + } | |
| 72 | 46 | |
| 73 | 47 | /** |
| 74 | - * Template Redirect Callback | |
| 75 | - * For Register new user and mark him as instructor | |
| 48 | + * Register new user and mark him as instructor | |
| 76 | 49 | * |
| 77 | - * @since 1.0.0 | |
| 78 | - * @return void|null | |
| 50 | + * @since v.1.0.0 | |
| 79 | 51 | */ |
| 80 | - public function register_instructor() { | |
| 81 | - // Here tutor_action checking required before nonce checking. | |
| 82 | - if ( 'tutor_register_instructor' !== Input::post( 'tutor_action' ) || ! get_option( 'users_can_register', false ) ) { | |
| 52 | + public function register_instructor(){ | |
| 53 | + if ( ! isset($_POST['tutor_action']) || $_POST['tutor_action'] !== 'tutor_register_instructor' ){ | |
| 83 | 54 | return; |
| 84 | 55 | } |
| 85 | - | |
| 86 | - // Checking nonce. | |
| 56 | + //Checking nonce | |
| 87 | 57 | tutor_utils()->checking_nonce(); |
| 88 | 58 | |
| 89 | - $required_fields = apply_filters( | |
| 90 | - 'tutor_instructor_registration_required_fields', | |
| 91 | - array( | |
| 92 | - 'first_name' => __( 'First name field is required', 'tutor' ), | |
| 93 | - 'last_name' => __( 'Last name field is required', 'tutor' ), | |
| 94 | - 'email' => __( 'E-Mail field is required', 'tutor' ), | |
| 95 | - 'user_login' => __( 'User Name field is required', 'tutor' ), | |
| 96 | - 'password' => __( 'Password field is required', 'tutor' ), | |
| 97 | - 'password_confirmation' => __( 'Password Confirmation field is required', 'tutor' ), | |
| 59 | + $required_fields = apply_filters('tutor_instructor_registration_required_fields', array( | |
| 60 | + 'first_name' => __('First name field is required', 'tutor'), | |
| 61 | + 'last_name' => __('Last name field is required', 'tutor'), | |
| 62 | + 'email' => __('E-Mail field is required', 'tutor'), | |
| 63 | + 'user_login' => __('User Name field is required', 'tutor'), | |
| 64 | + 'password' => __('Password field is required', 'tutor'), | |
| 65 | + 'password_confirmation' => __('Password Confirmation field is required', 'tutor'), | |
| 66 | + )); | |
| 98 | 67 | |
| 99 | - ) | |
| 100 | - ); | |
| 101 | - | |
| 102 | - $terms_conditions_link = tutor_utils()->get_toc_page_link(); | |
| 103 | - if ( $terms_conditions_link ) { | |
| 104 | - $required_fields['terms_conditions'] = __( 'Please accept the Terms and Conditions to continue', 'tutor' ); | |
| 105 | - } | |
| 106 | - | |
| 107 | 68 | $validation_errors = array(); |
| 108 | 69 | |
| 109 | 70 | /* |
| 110 | - * Push into validation_errors | |
| 111 | - * Error registration_errors | |
| 71 | + *registration_errors | |
| 72 | + *push into validation_errors | |
| 112 | 73 | */ |
| 113 | - $errors = apply_filters( 'registration_errors', new \WP_Error(), '', '' ); | |
| 114 | - foreach ( $errors->errors as $key => $value ) { | |
| 115 | - $validation_errors[ $key ] = $value[0]; | |
| 74 | + $errors = apply_filters('registration_errors',new \WP_Error,'',''); | |
| 75 | + foreach ($errors->errors as $key => $value) | |
| 76 | + { | |
| 77 | + $validation_errors[$key] = $value[0]; | |
| 78 | + | |
| 116 | 79 | } |
| 117 | - | |
| 118 | - foreach ( $required_fields as $required_key => $required_value ) { | |
| 119 | - if ( empty( $_POST[ $required_key ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 120 | - $validation_errors[ $required_key ] = $required_value; | |
| 80 | + | |
| 81 | + foreach ($required_fields as $required_key => $required_value){ | |
| 82 | + if (empty($_POST[$required_key])){ | |
| 83 | + $validation_errors[$required_key] = $required_value; | |
| 121 | 84 | } |
| 122 | 85 | } |
| 123 | 86 | |
| 124 | - if ( ! filter_var( tutor_utils()->input_old( 'email' ), FILTER_VALIDATE_EMAIL ) ) { | |
| 125 | - $validation_errors['email'] = __( 'Valid E-Mail is required', 'tutor' ); | |
| 87 | + if (!filter_var(tutor_utils()->input_old('email'), FILTER_VALIDATE_EMAIL)) { | |
| 88 | + $validation_errors['email'] = __('Valid E-Mail is required', 'tutor'); | |
| 126 | 89 | } |
| 127 | - if ( tutor_utils()->input_old( 'password' ) !== tutor_utils()->input_old( 'password_confirmation' ) ) { | |
| 128 | - $validation_errors['password_confirmation'] = __( 'Your passwords should match each other. Please recheck.', 'tutor' ); | |
| 90 | + if (tutor_utils()->input_old('password') !== tutor_utils()->input_old('password_confirmation')){ | |
| 91 | + $validation_errors['password_confirmation'] = __('Confirm password does not matched with Password field', 'tutor'); | |
| 129 | 92 | } |
| 130 | 93 | |
| 131 | - if ( count( $validation_errors ) ) { | |
| 94 | + if (count($validation_errors)){ | |
| 132 | 95 | $this->error_msgs = $validation_errors; |
| 133 | - add_filter( 'tutor_instructor_register_validation_errors', array( $this, 'tutor_instructor_form_validation_errors' ) ); | |
| 96 | + add_filter('tutor_instructor_register_validation_errors', array($this, 'tutor_instructor_form_validation_errors')); | |
| 134 | 97 | return; |
| 135 | 98 | } |
| 136 | 99 | |
| 137 | - $first_name = sanitize_text_field( tutor_utils()->input_old( 'first_name' ) ); | |
| 138 | - $last_name = sanitize_text_field( tutor_utils()->input_old( 'last_name' ) ); | |
| 139 | - $email = sanitize_text_field( tutor_utils()->input_old( 'email' ) ); | |
| 140 | - $user_login = sanitize_text_field( tutor_utils()->input_old( 'user_login' ) ); | |
| 141 | - $password = sanitize_text_field( tutor_utils()->input_old( 'password' ) ); | |
| 100 | + $first_name = sanitize_text_field(tutor_utils()->input_old('first_name')); | |
| 101 | + $last_name = sanitize_text_field(tutor_utils()->input_old('last_name')); | |
| 102 | + $email = sanitize_text_field(tutor_utils()->input_old('email')); | |
| 103 | + $user_login = sanitize_text_field(tutor_utils()->input_old('user_login')); | |
| 104 | + $password = sanitize_text_field(tutor_utils()->input_old('password')); | |
| 142 | 105 | |
| 143 | 106 | $userdata = array( |
| 144 | - 'user_login' => $user_login, | |
| 145 | - 'user_email' => $email, | |
| 146 | - 'first_name' => $first_name, | |
| 147 | - 'last_name' => $last_name, | |
| 148 | - 'user_pass' => $password, | |
| 107 | + 'user_login' => $user_login, | |
| 108 | + 'user_email' => $email, | |
| 109 | + 'first_name' => $first_name, | |
| 110 | + 'last_name' => $last_name, | |
| 111 | + //'role' => tutor()->instructor_role, | |
| 112 | + 'user_pass' => $password, | |
| 149 | 113 | ); |
| 150 | 114 | |
| 151 | - global $wpdb; | |
| 152 | - $wpdb->query( 'START TRANSACTION' ); | |
| 115 | + $user_id = wp_insert_user( $userdata ) ; | |
| 116 | + if ( ! is_wp_error($user_id)){ | |
| 117 | + update_user_meta($user_id, '_is_tutor_instructor', tutor_time()); | |
| 118 | + update_user_meta($user_id, '_tutor_instructor_status', apply_filters('tutor_initial_instructor_status', 'pending')); | |
| 153 | 119 | |
| 154 | - $user_id = wp_insert_user( $userdata ); | |
| 120 | + do_action('tutor_new_instructor_after', $user_id); | |
| 155 | 121 | |
| 156 | - if ( is_wp_error( $user_id ) ) { | |
| 157 | - $this->error_msgs = $user_id->get_error_messages(); | |
| 158 | - add_filter( 'tutor_instructor_register_validation_errors', array( $this, 'tutor_instructor_form_validation_errors' ) ); | |
| 159 | - return; | |
| 160 | - } | |
| 161 | - | |
| 162 | - $is_req_email_verification = apply_filters( 'tutor_require_email_verification', false ); | |
| 163 | - | |
| 164 | - if ( $is_req_email_verification ) { | |
| 165 | - do_action( 'tutor_send_verification_mail', get_userdata( $user_id ), 'instructor-registration' ); | |
| 166 | - $reg_done = apply_filters( 'tutor_registration_done', true ); | |
| 167 | - if ( ! $reg_done ) { | |
| 168 | - $wpdb->query( 'ROLLBACK' ); | |
| 169 | - return; | |
| 170 | - } else { | |
| 171 | - $wpdb->query( 'COMMIT' ); | |
| 172 | - } | |
| 173 | - } else { | |
| 174 | - /** | |
| 175 | - * Tutor Free - regular instructor reg process. | |
| 176 | - */ | |
| 177 | - $this->update_instructor_meta( $user_id ); | |
| 178 | - $wpdb->query( 'COMMIT' ); | |
| 179 | - $user = get_user_by( 'id', $user_id ); | |
| 180 | - if ( $user ) { | |
| 122 | + $user = get_user_by( 'id', $user_id ); | |
| 123 | + if( $user ) { | |
| 181 | 124 | wp_set_current_user( $user_id, $user->user_login ); |
| 182 | 125 | wp_set_auth_cookie( $user_id ); |
| 183 | - do_action( 'tutor_after_instructor_signup', $user_id ); | |
| 184 | 126 | } |
| 127 | + }else{ | |
| 128 | + $this->error_msgs = $user_id->get_error_messages(); | |
| 129 | + add_filter('tutor_instructor_register_validation_errors', array($this, 'tutor_instructor_form_validation_errors')); | |
| 130 | + return; | |
| 185 | 131 | } |
| 186 | 132 | |
| 187 | - wp_redirect( tutor_utils()->input_old( '_wp_http_referer' ) ); | |
| 133 | + wp_redirect(tutor_utils()->input_old('_wp_http_referer')); | |
| 188 | 134 | die(); |
| 189 | 135 | } |
| 190 | 136 | |
| 191 | - /** | |
| 192 | - * Get instructor reg validation errors. | |
| 193 | - * | |
| 194 | - * @since 1.0.0 | |
| 195 | - * @return string | |
| 196 | - */ | |
| 197 | - public function tutor_instructor_form_validation_errors() { | |
| 137 | + public function tutor_instructor_form_validation_errors(){ | |
| 198 | 138 | return $this->error_msgs; |
| 199 | 139 | } |
| 200 | 140 | |
| 201 | 141 | /** |
| 202 | - * Template Redirect Callback | |
| 203 | - * for instructor applying when a user already logged in | |
| 204 | 142 | * |
| 205 | - * @since 1.0.0 | |
| 206 | - * @return void|null | |
| 143 | + * Usage for instructor applying when a user already logged in | |
| 144 | + * | |
| 145 | + * @since v.1.0.0 | |
| 207 | 146 | */ |
| 208 | - public function apply_instructor() { | |
| 209 | - // Here tutor_action checking required before nonce checking. | |
| 210 | - if ( 'tutor_apply_instructor' !== Input::post( 'tutor_action' ) ) { | |
| 147 | + public function apply_instructor(){ | |
| 148 | + if ( ! isset($_POST['tutor_action']) || $_POST['tutor_action'] !== 'tutor_apply_instructor' ){ | |
| 211 | 149 | return; |
| 212 | 150 | } |
| 213 | - | |
| 214 | - // Checking nonce. | |
| 151 | + //Checking nonce | |
| 215 | 152 | tutor_utils()->checking_nonce(); |
| 216 | 153 | |
| 217 | 154 | $user_id = get_current_user_id(); |
| 218 | - if ( $user_id ) { | |
| 219 | - if ( tutor_utils()->is_instructor() ) { | |
| 220 | - die( esc_html__( 'Already applied for instructor', 'tutor' ) ); | |
| 221 | - } else { | |
| 222 | - update_user_meta( $user_id, '_is_tutor_instructor', tutor_time() ); | |
| 223 | - update_user_meta( $user_id, '_tutor_instructor_status', apply_filters( 'tutor_initial_instructor_status', 'pending' ) ); | |
| 155 | + if ($user_id){ | |
| 156 | + if (tutor_utils()->is_instructor()){ | |
| 157 | + die(__('Already applied for instructor', 'tutor')); | |
| 158 | + }else{ | |
| 159 | + update_user_meta($user_id, '_is_tutor_instructor', tutor_time()); | |
| 160 | + update_user_meta($user_id, '_tutor_instructor_status', apply_filters('tutor_initial_instructor_status', 'pending')); | |
| 224 | 161 | |
| 225 | - do_action( 'tutor_new_instructor_after', $user_id ); | |
| 226 | - } | |
| 227 | - } else { | |
| 228 | - die( esc_html__( 'Permission denied', 'tutor' ) ); | |
| 162 | + do_action('tutor_new_instructor_after', $user_id); | |
| 163 | + } | |
| 164 | + }else{ | |
| 165 | + die(__('Permission denied', 'tutor')); | |
| 229 | 166 | } |
| 230 | 167 | |
| 231 | - wp_redirect( tutor_utils()->input_old( '_wp_http_referer' ) ); | |
| 168 | + wp_redirect(tutor_utils()->input_old('_wp_http_referer')); | |
| 232 | 169 | die(); |
| 233 | 170 | } |
| 234 | 171 | |
| 235 | 172 | |
| 236 | - /** | |
| 237 | - * Add new instructor | |
| 238 | - * | |
| 239 | - * @since 1.0.0 | |
| 240 | - * @return void | |
| 241 | - */ | |
| 242 | - public function add_new_instructor() { | |
| 243 | - tutor_utils()->checking_nonce(); | |
| 173 | + public function add_new_instructor(){ | |
| 244 | 174 | |
| 245 | - // Only admin should be able to add instructor. | |
| 246 | - if ( ! current_user_can( 'manage_options' ) || ! get_option( 'users_can_register', false ) ) { | |
| 247 | - wp_send_json_error(); | |
| 175 | + tutils()->checking_nonce(); | |
| 176 | + | |
| 177 | + // Only admin should be able to add instructor | |
| 178 | + if(!current_user_can( 'manage_options' ) || !get_option( 'users_can_register', false )) { | |
| 179 | + wp_send_json_error( ); | |
| 248 | 180 | } |
| 181 | + | |
| 249 | 182 | |
| 250 | - $required_fields = apply_filters( | |
| 251 | - 'tutor_instructor_registration_required_fields', | |
| 252 | - array( | |
| 253 | - 'first_name' => __( 'First name field is required', 'tutor' ), | |
| 254 | - 'last_name' => __( 'Last name field is required', 'tutor' ), | |
| 255 | - 'email' => __( 'E-Mail field is required', 'tutor' ), | |
| 256 | - 'user_login' => __( 'User Name field is required', 'tutor' ), | |
| 257 | - 'password' => __( 'Password field is required', 'tutor' ), | |
| 258 | - 'password_confirmation' => __( 'Your passwords should match each other. Please recheck.', 'tutor' ), | |
| 259 | - ) | |
| 260 | - ); | |
| 183 | + $required_fields = apply_filters('tutor_instructor_registration_required_fields', array( | |
| 184 | + 'first_name' => __('First name field is required', 'tutor'), | |
| 185 | + 'last_name' => __('Last name field is required', 'tutor'), | |
| 186 | + 'email' => __('E-Mail field is required', 'tutor'), | |
| 187 | + 'user_login' => __('User Name field is required', 'tutor'), | |
| 188 | + 'phone_number' => __('Phone Number field is required', 'tutor'), | |
| 189 | + 'password' => __('Password field is required', 'tutor'), | |
| 190 | + 'password_confirmation' => __('Password Confirmation field is required', 'tutor'), | |
| 191 | + )); | |
| 261 | 192 | |
| 262 | 193 | $validation_errors = array(); |
| 263 | - foreach ( $required_fields as $required_key => $required_value ) { | |
| 264 | - if ( empty( $_POST[ $required_key ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 265 | - $validation_errors[ $required_key ] = $required_value; | |
| 194 | + foreach ($required_fields as $required_key => $required_value){ | |
| 195 | + if (empty($_POST[$required_key])){ | |
| 196 | + $validation_errors[$required_key] = $required_value; | |
| 266 | 197 | } |
| 267 | 198 | } |
| 268 | 199 | |
| 269 | - if ( ! filter_var( tutor_utils()->input_old( 'email' ), FILTER_VALIDATE_EMAIL ) ) { | |
| 270 | - $validation_errors['email'] = __( 'Valid E-Mail is required', 'tutor' ); | |
| 200 | + if (!filter_var(tutor_utils()->input_old('email'), FILTER_VALIDATE_EMAIL)) { | |
| 201 | + $validation_errors['email'] = __('Valid E-Mail is required', 'tutor'); | |
| 271 | 202 | } |
| 272 | - if ( tutor_utils()->input_old( 'password' ) !== tutor_utils()->input_old( 'password_confirmation' ) ) { | |
| 273 | - $validation_errors['password_confirmation'] = __( 'Your passwords should match each other. Please recheck.', 'tutor' ); | |
| 203 | + if (tutor_utils()->input_old('password') !== tutor_utils()->input_old('password_confirmation')){ | |
| 204 | + $validation_errors['password_confirmation'] = __('Confirm password does not matched with Password field', 'tutor'); | |
| 274 | 205 | } |
| 275 | 206 | |
| 276 | - if ( count( $validation_errors ) ) { | |
| 277 | - wp_send_json_error( array( 'errors' => $validation_errors ) ); | |
| 207 | + if (count($validation_errors)){ | |
| 208 | + wp_send_json_error(array('errors' => $validation_errors)); | |
| 278 | 209 | } |
| 279 | 210 | |
| 280 | - $first_name = sanitize_text_field( tutor_utils()->input_old( 'first_name' ) ); | |
| 281 | - $last_name = sanitize_text_field( tutor_utils()->input_old( 'last_name' ) ); | |
| 282 | - $email = sanitize_text_field( tutor_utils()->input_old( 'email' ) ); | |
| 283 | - $user_login = sanitize_text_field( tutor_utils()->input_old( 'user_login' ) ); | |
| 284 | - $phone_number = sanitize_text_field( tutor_utils()->input_old( 'phone_number' ) ); | |
| 285 | - $password = sanitize_text_field( tutor_utils()->input_old( 'password' ) ); | |
| 286 | - $tutor_profile_bio = Input::post( 'tutor_profile_bio', '', Input::TYPE_KSES_POST ); | |
| 287 | - $tutor_profile_job_title = sanitize_text_field( tutor_utils()->input_old( 'tutor_profile_job_title' ) ); | |
| 211 | + $first_name = sanitize_text_field(tutor_utils()->input_old('first_name')); | |
| 212 | + $last_name = sanitize_text_field(tutor_utils()->input_old('last_name')); | |
| 213 | + $email = sanitize_text_field(tutor_utils()->input_old('email')); | |
| 214 | + $user_login = sanitize_text_field(tutor_utils()->input_old('user_login')); | |
| 215 | + $phone_number = sanitize_text_field(tutor_utils()->input_old('phone_number')); | |
| 216 | + $password = sanitize_text_field(tutor_utils()->input_old('password')); | |
| 217 | + $tutor_profile_bio = wp_kses_post(tutor_utils()->input_old('tutor_profile_bio')); | |
| 288 | 218 | |
| 289 | - $userdata = apply_filters( | |
| 290 | - 'add_new_instructor_data', | |
| 291 | - array( | |
| 292 | - 'user_login' => $user_login, | |
| 293 | - 'user_email' => $email, | |
| 294 | - 'first_name' => $first_name, | |
| 295 | - 'last_name' => $last_name, | |
| 296 | - 'role' => tutor()->instructor_role, | |
| 297 | - 'user_pass' => $password, | |
| 298 | - ) | |
| 299 | - ); | |
| 219 | + $userdata = apply_filters('add_new_instructor_data', array( | |
| 220 | + 'user_login' => $user_login, | |
| 221 | + 'user_email' => $email, | |
| 222 | + 'first_name' => $first_name, | |
| 223 | + 'last_name' => $last_name, | |
| 224 | + 'role' => tutor()->instructor_role, | |
| 225 | + 'user_pass' => $password, | |
| 226 | + )); | |
| 300 | 227 | |
| 301 | - do_action( 'tutor_add_new_instructor_before' ); | |
| 228 | + do_action('tutor_add_new_instructor_before'); | |
| 302 | 229 | |
| 303 | - $user_id = wp_insert_user( $userdata ); | |
| 304 | - if ( ! is_wp_error( $user_id ) ) { | |
| 305 | - update_user_meta( $user_id, 'phone_number', $phone_number ); | |
| 306 | - update_user_meta( $user_id, 'description', $tutor_profile_bio ); | |
| 307 | - update_user_meta( $user_id, '_tutor_profile_bio', $tutor_profile_bio ); | |
| 308 | - update_user_meta( $user_id, '_tutor_profile_job_title', $tutor_profile_job_title ); | |
| 309 | - update_user_meta( $user_id, '_is_tutor_instructor', tutor_time() ); | |
| 310 | - update_user_meta( $user_id, '_tutor_instructor_status', apply_filters( 'tutor_initial_instructor_status', 'approved' ) ); | |
| 230 | + $user_id = wp_insert_user( $userdata ) ; | |
| 231 | + if ( ! is_wp_error($user_id)) { | |
| 232 | + update_user_meta($user_id, 'phone_number', $phone_number); | |
| 233 | + update_user_meta($user_id, 'description', $tutor_profile_bio); | |
| 234 | + update_user_meta($user_id, '_tutor_profile_bio', $tutor_profile_bio); | |
| 235 | + update_user_meta($user_id, '_is_tutor_instructor', tutor_time()); | |
| 236 | + update_user_meta($user_id, '_tutor_instructor_status', apply_filters('tutor_initial_instructor_status', 'approved')); | |
| 311 | 237 | |
| 312 | - do_action( 'tutor_add_new_instructor_after', $user_id ); | |
| 238 | + do_action('tutor_add_new_instructor_after', $user_id); | |
| 313 | 239 | |
| 314 | - wp_send_json_success( array( 'msg' => __( 'Instructor has been added successfully', 'tutor' ) ) ); | |
| 240 | + wp_send_json_success(array('msg' => __('Instructor has been added successfully', 'tutor') )); | |
| 315 | 241 | } |
| 316 | 242 | |
| 317 | - wp_send_json_error( array( 'errors' => $user_id ) ); | |
| 243 | + wp_send_json_error(array('errors' => $user_id)); | |
| 318 | 244 | } |
| 319 | 245 | |
| 320 | - /** | |
| 321 | - * Handle instructor approval action | |
| 322 | - * This function not used maybe, will be removed | |
| 323 | - * | |
| 324 | - * @since 1.0.0 | |
| 325 | - * @return void | |
| 326 | - */ | |
| 327 | - public function instructor_approval_action() { | |
| 328 | - tutor_utils()->checking_nonce(); | |
| 246 | + public function instructor_approval_action(){ | |
| 247 | + tutils()->checking_nonce(); | |
| 329 | 248 | |
| 330 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 331 | - wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) ); | |
| 249 | + if(!current_user_can( 'manage_options' )) { | |
| 250 | + wp_send_json_error( array('message' =>__('Access Denied', 'tutor')) ); | |
| 332 | 251 | } |
| 333 | 252 | |
| 334 | - $instructor_id = Input::post( 'instructor_id', 0, Input::TYPE_INT ); | |
| 335 | - $action = Input::post( 'action_name' ); | |
| 253 | + $instructor_id = (int) sanitize_text_field(tutils()->array_get('instructor_id', $_POST)); | |
| 254 | + $action = sanitize_text_field(tutils()->array_get('action_name', $_POST)); | |
| 336 | 255 | |
| 337 | - if ( 'approve' === $action ) { | |
| 338 | - do_action( 'tutor_before_approved_instructor', $instructor_id ); | |
| 256 | + if( 'approve' === $action ) { | |
| 257 | + do_action('tutor_before_approved_instructor', $instructor_id); | |
| 339 | 258 | |
| 340 | - update_user_meta( $instructor_id, '_tutor_instructor_status', 'approved' ); | |
| 341 | - update_user_meta( $instructor_id, '_tutor_instructor_approved', tutor_time() ); | |
| 259 | + update_user_meta($instructor_id, '_tutor_instructor_status', 'approved'); | |
| 260 | + update_user_meta($instructor_id, '_tutor_instructor_approved', tutor_time()); | |
| 342 | 261 | |
| 343 | - $instructor = new \WP_User( $instructor_id ); | |
| 344 | - $instructor->add_role( tutor()->instructor_role ); | |
| 262 | + $instructor = new \WP_User($instructor_id); | |
| 263 | + $instructor->add_role(tutor()->instructor_role); | |
| 345 | 264 | |
| 346 | - // Send E-Mail to this user about instructor approval via hook. | |
| 347 | - do_action( 'tutor_after_approved_instructor', $instructor_id ); | |
| 265 | + // Send E-Mail to this user about instructor approval via hook | |
| 266 | + do_action('tutor_after_approved_instructor', $instructor_id); | |
| 348 | 267 | } |
| 349 | 268 | |
| 350 | - if ( 'blocked' === $action ) { | |
| 351 | - do_action( 'tutor_before_blocked_instructor', $instructor_id ); | |
| 352 | - update_user_meta( $instructor_id, '_tutor_instructor_status', 'blocked' ); | |
| 269 | + if( 'blocked' === $action ) { | |
| 270 | + do_action('tutor_before_blocked_instructor', $instructor_id); | |
| 271 | + update_user_meta($instructor_id, '_tutor_instructor_status', 'blocked'); | |
| 353 | 272 | |
| 354 | - $instructor = new \WP_User( $instructor_id ); | |
| 355 | - $instructor->remove_role( tutor()->instructor_role ); | |
| 356 | - do_action( 'tutor_after_blocked_instructor', $instructor_id ); | |
| 273 | + $instructor = new \WP_User($instructor_id); | |
| 274 | + $instructor->remove_role(tutor()->instructor_role); | |
| 275 | + do_action('tutor_after_blocked_instructor', $instructor_id); | |
| 357 | 276 | |
| 358 | - // TODO: send E-Mail to this user about instructor blocked, should via hook. | |
| 277 | + //TODO: send E-Mail to this user about instructor blocked, should via hook | |
| 359 | 278 | } |
| 360 | 279 | |
| 361 | - if ( 'remove-instructor' === $action ) { | |
| 362 | - do_action( 'tutor_before_rejected_instructor', $instructor_id ); | |
| 280 | + if( 'remove-instructor' === $action) | |
| 281 | + { | |
| 282 | + do_action('tutor_before_rejected_instructor', $instructor_id); | |
| 363 | 283 | |
| 364 | - $user = new \WP_User( $instructor_id ); | |
| 365 | - $user->remove_role( tutor()->instructor_role ); | |
| 284 | + $user = new \WP_User($instructor_id); | |
| 285 | + $user->remove_role(tutor()->instructor_role); | |
| 366 | 286 | |
| 367 | - tutor_utils()->remove_instructor_role( $instructor_id ); | |
| 368 | - update_user_meta( $instructor_id, '_is_tutor_instructor_rejected', tutor_time() ); | |
| 369 | - update_user_meta( $instructor_id, 'tutor_instructor_show_rejection_message', true ); | |
| 287 | + tutor_utils()->remove_instructor_role($instructor_id); | |
| 288 | + update_user_meta($instructor_id, '_is_tutor_instructor_rejected', tutor_time()); | |
| 289 | + update_user_meta($instructor_id, 'tutor_instructor_show_rejection_message', true); | |
| 370 | 290 | |
| 371 | - // Send E-Mail to this user about instructor rejection via hook. | |
| 372 | - do_action( 'tutor_after_rejected_instructor', $instructor_id ); | |
| 291 | + // Send E-Mail to this user about instructor rejection via hook | |
| 292 | + do_action('tutor_after_rejected_instructor', $instructor_id); | |
| 373 | 293 | } |
| 374 | 294 | |
| 375 | 295 | wp_send_json_success(); |
| 376 | 296 | } |
| 377 | 297 | |
| 378 | - /** | |
| 379 | - * Hide instructor notice | |
| 380 | - * | |
| 381 | - * @since 1.0.0 | |
| 382 | - * @return void | |
| 383 | - */ | |
| 384 | 298 | public function hide_instructor_notice() { |
| 385 | - if ( 'hide_instructor_notice' === Input::get( 'tutor_action' ) ) { | |
| 299 | + if(isset( $_GET['tutor_action'] ) && $_GET['tutor_action']=='hide_instructor_notice') { | |
| 386 | 300 | delete_user_meta( get_current_user_id(), 'tutor_instructor_show_rejection_message' ); |
| 387 | 301 | } |
| 388 | 302 | } |
| 389 | 303 | |
| 390 | - /** | |
| 391 | - * Can instructor publish courses directly | |
| 392 | - * Fixed in Gutenberg | |
| 393 | - * | |
| 394 | - * @since 1.5.9 | |
| 395 | - * @return void | |
| 396 | - */ | |
| 397 | - public function can_publish_tutor_courses() { | |
| 398 | - $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' ); | |
| 304 | + /** | |
| 305 | + * Can instructor publish courses directly | |
| 306 | + * Fixed in Gutenberg @since v.1.5.9 | |
| 307 | + */ | |
| 399 | 308 | |
| 400 | - $instructor_role = tutor()->instructor_role; | |
| 401 | - $instructor = get_role( $instructor_role ); | |
| 309 | + public function can_publish_tutor_courses(){ | |
| 310 | + $can_publish_course = (bool) tutor_utils()->get_option('instructor_can_publish_course'); | |
| 402 | 311 | |
| 403 | - if ( $can_publish_course ) { | |
| 404 | - $instructor->add_cap( 'publish_tutor_courses' ); | |
| 405 | - } else { | |
| 406 | - $instructor->remove_cap( 'publish_tutor_courses' ); | |
| 407 | - } | |
| 408 | - } | |
| 312 | + $instructor_role = tutor()->instructor_role; | |
| 313 | + $instructor = get_role( $instructor_role ); | |
| 409 | 314 | |
| 410 | - /** | |
| 411 | - * Update instructor meta just after register | |
| 412 | - * | |
| 413 | - * @since 2.1.9 | |
| 414 | - * | |
| 415 | - * @param integer $user_id user id. | |
| 416 | - * | |
| 417 | - * @return void | |
| 418 | - */ | |
| 419 | - public function update_instructor_meta( int $user_id ) { | |
| 420 | - update_user_meta( $user_id, '_is_tutor_instructor', tutor_time() ); | |
| 421 | - update_user_meta( $user_id, '_tutor_instructor_status', apply_filters( 'tutor_initial_instructor_status', 'pending' ) ); | |
| 315 | + if ($can_publish_course){ | |
| 316 | + $instructor->add_cap('publish_tutor_courses'); | |
| 317 | + }else{ | |
| 318 | + $instructor->remove_cap('publish_tutor_courses'); | |
| 319 | + } | |
| 320 | + } | |
| 422 | 321 | |
| 423 | - do_action( 'tutor_new_instructor_after', $user_id ); | |
| 424 | - } | |
| 425 | -} | |
| 322 | +} | |