Addons.php
6 years ago
Admin.php
6 years ago
Ajax.php
6 years ago
Assets.php
6 years ago
Course.php
6 years ago
Course_Settings_Tabs.php
6 years ago
Course_Widget.php
6 years ago
Dashboard.php
6 years ago
Email.php
6 years ago
FormHandler.php
6 years ago
Gutenberg.php
6 years ago
Instructor.php
6 years ago
Instructors_List.php
6 years ago
Lesson.php
6 years ago
Options.php
6 years ago
Post_types.php
6 years ago
Q_and_A.php
6 years ago
Question_Answers_List.php
6 years ago
Quiz.php
6 years ago
Quiz_Attempts_List.php
6 years ago
Rewrite_Rules.php
6 years ago
Shortcode.php
6 years ago
Student.php
6 years ago
Students_List.php
6 years ago
Taxonomies.php
6 years ago
Template.php
6 years ago
Theme_Compatibility.php
6 years ago
Tools.php
6 years ago
Tutor.php
6 years ago
TutorEDD.php
6 years ago
Tutor_Base.php
6 years ago
Tutor_List_Table.php
6 years ago
Upgrader.php
6 years ago
User.php
6 years ago
Utils.php
6 years ago
Video_Stream.php
6 years ago
Withdraw.php
6 years ago
Withdraw_Requests_List.php
6 years ago
WooCommerce.php
6 years ago
User.php
98 lines
| 1 | <?php |
| 2 | |
| 3 | namespace TUTOR; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) |
| 6 | exit; |
| 7 | |
| 8 | |
| 9 | class User { |
| 10 | |
| 11 | public function __construct() { |
| 12 | add_action('edit_user_profile', array($this, 'edit_user_profile')); |
| 13 | add_action('show_user_profile', array($this, 'edit_user_profile'), 10, 1); |
| 14 | |
| 15 | add_action('profile_update', array($this, 'profile_update')); |
| 16 | add_action('set_user_role', array($this, 'set_user_role'), 10, 3); |
| 17 | add_action('wp_ajax_tutor_profile_photo_remove', array($this, 'tutor_profile_photo_remove')); |
| 18 | } |
| 19 | |
| 20 | public function edit_user_profile($user){ |
| 21 | include tutor()->path.'views/metabox/user-profile-fields.php'; |
| 22 | } |
| 23 | |
| 24 | public function profile_update($user_id){ |
| 25 | $_tutor_profile_job_title = sanitize_text_field(tutor_utils()->avalue_dot('_tutor_profile_job_title', $_POST)); |
| 26 | $_tutor_profile_bio = wp_kses_post(tutor_utils()->avalue_dot('_tutor_profile_bio', $_POST)); |
| 27 | |
| 28 | update_user_meta($user_id, '_tutor_profile_job_title', $_tutor_profile_job_title); |
| 29 | update_user_meta($user_id, '_tutor_profile_bio', $_tutor_profile_bio); |
| 30 | |
| 31 | /** |
| 32 | * Profile Photo Update from profile |
| 33 | * |
| 34 | */ |
| 35 | $profile_photo = tutils()->array_get('tutor_profile_photo_file', $_FILES); |
| 36 | $profile_photo_size = tutils()->array_get('size', $profile_photo); |
| 37 | $profile_photo_type = tutils()->array_get('type', $profile_photo); |
| 38 | |
| 39 | if ($profile_photo_size && strpos($profile_photo_type, 'image') !== false) { |
| 40 | if ( ! function_exists( 'wp_handle_upload' ) ) { |
| 41 | require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
| 42 | } |
| 43 | |
| 44 | $upload_overrides = array( 'test_form' => false ); |
| 45 | $movefile = wp_handle_upload( $profile_photo, $upload_overrides ); |
| 46 | |
| 47 | if ( $movefile && ! isset( $movefile['error'] ) ) { |
| 48 | $file_path = tutils()->array_get( 'file', $movefile ); |
| 49 | $file_url = tutils()->array_get( 'url', $movefile ); |
| 50 | |
| 51 | $media_id = wp_insert_attachment( array( |
| 52 | 'guid' => $file_path, |
| 53 | 'post_mime_type' => mime_content_type( $file_path ), |
| 54 | 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_url ) ), |
| 55 | 'post_content' => '', |
| 56 | 'post_status' => 'inherit' |
| 57 | ), $file_path, 0 ); |
| 58 | |
| 59 | if ($media_id) { |
| 60 | // wp_generate_attachment_metadata() won't work if you do not include this file |
| 61 | require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
| 62 | |
| 63 | // Generate and save the attachment metas into the database |
| 64 | wp_update_attachment_metadata( $media_id, wp_generate_attachment_metadata( $media_id, $file_path ) ); |
| 65 | |
| 66 | //Update it to user profile |
| 67 | update_user_meta( $user_id, '_tutor_profile_photo', $media_id ); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | } |
| 73 | |
| 74 | public function set_user_role($user_id, $role, $old_roles ){ |
| 75 | $instructor_role = tutor()->instructor_role; |
| 76 | |
| 77 | if (in_array($instructor_role, $old_roles)){ |
| 78 | tutor_utils()->remove_instructor_role($user_id); |
| 79 | } |
| 80 | |
| 81 | if ($role === $instructor_role){ |
| 82 | tutor_utils()->add_instructor_role($user_id); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |
| 88 | /** |
| 89 | * |
| 90 | * Delete profile photo |
| 91 | * @since v.1.4.5 |
| 92 | */ |
| 93 | public function tutor_profile_photo_remove(){ |
| 94 | $user_id = get_current_user_id(); |
| 95 | delete_user_meta($user_id, '_tutor_profile_photo'); |
| 96 | } |
| 97 | |
| 98 | } |