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/user/abstract-lp-user.php +122 -220 4.2.04.4.8 View file →
@@ -10,8 +10,11 @@
10 10
11 11 /**
12 12 * Prevent loading this file directly
13 13 */
14 +
15 +use LearnPress\Models\UserItems\UserCourseModel;
16 +
14 17 defined( 'ABSPATH' ) || exit();
15 18
16 19 if ( ! class_exists( 'LP_Abstract_User' ) ) {
17 20
@@ -79,9 +82,8 @@
79 82
80 83 if ( $this->get_id() > 0 ) {
81 84 $this->load();
82 85 }
83 -
84 86 }
85 87
86 88 /**
87 89 * Load user data from curd
@@ -95,10 +97,9 @@
95 97 *
96 98 * @param int $course_id .
97 99 *
98 100 * @return LP_User_Item_Course|bool
99 - * @version 3.1.3
100 - * @editor tungnx
101 + * @version 3.1.4
101 102 * @modify 4.1.3
102 103 */
103 104 public function get_course_data( int $course_id = 0 ) {
104 105 $lp_user_items_db = LP_User_Items_DB::getInstance();
@@ -108,21 +109,14 @@
108 109 if ( ! $course_id ) {
109 110 $course_id = get_the_ID();
110 111 }
111 112
112 - /*if ( $this instanceof LP_User_Guest ) {
113 - throw new Exception( 'User is Guest' );
114 - }*/
115 -
116 - $filter = new LP_User_Items_Filter();
117 - $filter->item_id = $course_id;
118 - $filter->user_id = $this->get_id();
119 - $last_user_course = $lp_user_items_db->get_last_user_course( $filter );
120 -
121 - if ( $last_user_course ) {
122 - $object_course_data = new LP_User_Item_Course( $last_user_course );
113 + $userCourseModel = UserCourseModel::find( $this->get_id(), $course_id, true );
114 + if ( $userCourseModel ) {
115 + $userCourseArr = (array) $userCourseModel;
116 + $userCourseArr['user_item_id'] = $userCourseModel->get_user_item_id();
117 + $object_course_data = new LP_User_Item_Course( $userCourseArr );
123 118 } else {
124 - $object_course_data = false;
125 119 /**
126 120 * Todo: some themes still not check false, so still use below code.\
127 121 * @editor tungnx 4.1.6.9
128 122 */
@@ -135,8 +129,28 @@
135 129 return $object_course_data;
136 130 }
137 131
138 132 /**
133 + * Get course attend of user not Guest.
134 + * Replace get_course_data method.
135 + *
136 + * @param int $course_id
137 + * @return false|UserCourseModel
138 + * @since 4.2.5
139 + * @version 1.0.1
140 + */
141 + public function get_course_attend( int $course_id = 0 ) {
142 + if ( $this instanceof LP_User_Guest ) {
143 + return false;
144 + }
145 +
146 + $filter = new LP_User_Items_Filter();
147 + $filter->item_id = $course_id;
148 + $filter->user_id = $this->get_id();
149 + return UserCourseModel::get_user_item_model_from_db( $filter );
150 + }
151 +
152 + /**
139 153 * Get user course item.
140 154 *
141 155 * @param int $item_id
142 156 * @param int $course_id
@@ -524,58 +538,8 @@
524 538 return $result;
525 539 }
526 540
527 541 /**
528 - * Mark question that user has checked.
529 - *
530 - * @param int $question_id
531 - * @param int $quiz_id
532 - * @param int $course_id
533 - *
534 - * @return WP_Error|mixed
535 - * @since 3.0.0
536 - */
537 - public function hint( $question_id, $quiz_id, $course_id ) {
538 - $course = learn_press_get_course( $course_id );
539 - if ( ! $course ) {
540 - return false;
541 - }
542 -
543 - if ( ! $course->has_item( $quiz_id ) ) {
544 - return false;
545 - }
546 -
547 - /**
548 - * @var $quiz LP_Quiz
549 - */
550 - $quiz = $course->get_item( $quiz_id );
551 - if ( ! $quiz instanceof LP_Course_Item_Quiz ) {
552 - return false;
553 - }
554 -
555 - if ( ! $quiz->has_question( $question_id ) ) {
556 - return false;
557 - }
558 -
559 - $quiz_data = $this->get_item_data( $quiz_id, $course_id );
560 - $remain = $quiz_data->hint( $question_id );
561 - if ( false === $remain ) {
562 - return new WP_Error( 1001, __( 'You can not hint at the question.', 'learnpress' ) );
563 - }
564 -
565 - return $remain;
566 - }
567 -
568 - public function get_quiz_last_results( $quiz_id ) {
569 - $results = $this->get_course_info( $quiz_id );
570 - if ( $results ) {
571 - $results = reset( $results );
572 - }
573 -
574 - return apply_filters( 'learn_press_user_quiz_last_results', $results, $quiz_id, $this );
575 - }
576 -
577 - /**
578 542 * Check if user has at least one role.
579 543 *
580 544 * @param array|string $roles
581 545 *
@@ -607,30 +571,8 @@
607 571
608 572 return $is;
609 573 }
610 574
611 - /**
612 - *
613 - * Check what the user can do
614 - *
615 - * @param $role
616 - *
617 - * @return mixed
618 - * @throws Exception
619 - */
620 - public function can( $role ) {
621 - _deprecated_function( __FUNCTION__, '3.0.8' );
622 - $args = func_get_args();
623 - unset( $args[0] );
624 - $method = 'can_' . preg_replace( '!-!', '_', $role );
625 - $callback = array( $this, $method );
626 - if ( is_callable( $callback ) ) {
627 - return call_user_func_array( $callback, $args );
628 - } else {
629 - throw new Exception( sprintf( __( 'The role %s for the user doesn\'t exist', 'learnpress' ), $role ) );
630 - }
631 - }
632 -
633 575 public function can_edit_item( $item_id, $course_id = 0 ) {
634 576 $return = $this->is_admin();
635 577
636 578 if ( ! $return ) {
@@ -645,24 +587,8 @@
645 587 return apply_filters( 'learn_press_user_can_edit_item', $return, $item_id, $course_id, $this->get_id() );
646 588 }
647 589
648 590 /**
649 - * Check if user can finish course by getting current progress
650 - * and compares with course passing condition.
651 - *
652 - * @param int $course_id
653 - *
654 - * @return bool
655 - * @editor tungnx
656 - * @modify 4.1.3
657 - */
658 - public function can_finish_course( int $course_id ) {
659 - _deprecated_function( __FUNCTION__, '4.1.3', 'is_course_finished' );
660 -
661 - return true;
662 - }
663 -
664 - /**
665 591 * Check if course has any passed status for an user.
666 592 * Statuses: depending on value of column `status` in user_items.
667 593 * - purchased: bought and order is completed, `start_date` and `end_date` is null
668 594 * - enrolled: value of column `status` in user_items is enrolled
@@ -766,22 +692,8 @@
766 692 public function is_author_of( $post_id ) {
767 693 return absint( get_post_field( 'post_author', $post_id ) ) === $this->get_id();
768 694 }
769 695
770 - public function has( $role ) {
771 - _deprecated_function( __FUNCTION__, '3.0.8' );
772 -
773 - $args = func_get_args();
774 - unset( $args[0] );
775 - $method = 'has_' . preg_replace( '!-!', '_', $role );
776 - $callback = array( $this, $method );
777 - if ( is_callable( $callback ) ) {
778 - return call_user_func_array( $callback, $args );
779 - } else {
780 - throw new Exception( sprintf( __( 'The role %s for the user doesn\'t exist', 'learnpress' ), $role ) );
781 - }
782 - }
783 -
784 696 public function get( $role ) {
785 697 $args = func_get_args();
786 698 unset( $args[0] );
787 699 $method = 'get_' . preg_replace( '!-!', '_', $role );
@@ -1013,31 +925,8 @@
1013 925 return apply_filters( 'learn_press_user_has_completed_item', $return, $item );
1014 926 }
1015 927
1016 928 /**
1017 - * Get the remaining time of a course for the user.
1018 - *
1019 - * @param int $course_id
1020 - *
1021 - * @return bool|int|string
1022 - * @deprecated 4.1.7.3
1023 - */
1024 - public function get_course_remaining_time( $course_id ) {
1025 - _deprecated_function( __FUNCTION__, '4.1.7.3' );
1026 - /*$course = learn_press_get_course( $course_id );
1027 - $remain = false;
1028 -
1029 - if ( $course && $course->get_id() ) {
1030 - $course_data = $this->get_course_data( $course_id, true );
1031 - if ( $course_data ) {
1032 - $remain = $course_data->is_exceeded();
1033 - }
1034 - }
1035 -
1036 - return $remain > 0 ? learn_press_seconds_to_weeks( $remain ) : false;*/
1037 - }
1038 -
1039 - /**
1040 929 * Get the order that contains the course.
1041 930 *
1042 931 * @param int $course_id
1043 932 *
@@ -1079,60 +968,8 @@
1079 968 return $wpdb->get_var( $query );
1080 969 }
1081 970
1082 971 /**
1083 - * @param $question_id
1084 - * @param null $quiz_id
1085 - *
1086 - * @return bool
1087 - */
1088 - public function get_answer_results( $question_id, $quiz_id = null ) {
1089 -
1090 - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, '3.0.0' );
1091 -
1092 - $data = false;
1093 - if ( ! $quiz_id ) {
1094 - $quiz_id = $this->get_quiz_by_question( $question_id );
1095 - }
1096 - if ( $quiz_id ) {
1097 - $question = LP_Question::get_question( $question_id );
1098 -
1099 - if ( $question ) {
1100 - $quiz_results = $this->get_quiz_results( $quiz_id );
1101 - if ( ! empty( $quiz_results->question_answers ) ) {
1102 - $question_answer = array_key_exists(
1103 - $question_id,
1104 - $quiz_results->question_answers
1105 - ) ? $quiz_results->question_answers[ $question_id ] : null;
1106 - $data = $question->check( $question_answer );
1107 - }
1108 - }
1109 - }
1110 -
1111 - return $data;
1112 - }
1113 -
1114 - /**
1115 - * @param $question_id
1116 - * @param null $quiz_id
1117 - *
1118 - * @return bool
1119 - */
1120 - public function is_answered_question( $question_id, $quiz_id = null ) {
1121 - if ( empty( $this->answered_questions ) ) {
1122 - $this->answered_questions = array();
1123 - }
1124 - if ( ! $quiz_id ) {
1125 - $quiz_id = $this->get_quiz_by_question( $question_id );
1126 - }
1127 -
1128 - $results = $this->get_quiz_results( $quiz_id );
1129 - $answered = ! empty( $results->question_answers ) ? $results->question_answers : array();
1130 -
1131 - return $answered ? array_key_exists( $question_id, $answered ) : false;
1132 - }
1133 -
1134 - /**
1135 972 * @return array
1136 973 */
1137 974 public function get_roles() {
1138 975 return (array) $this->get_data( 'roles' );
@@ -1155,25 +992,8 @@
1155 992 return $quiz_data ? $quiz_data->has_checked_question( $question_id ) : false;
1156 993 }
1157 994
1158 995 /**
1159 - * @param $question_id
1160 - * @param $quiz_id
1161 - * @param int $course_id
1162 - *
1163 - * @return bool
1164 - */
1165 - public function has_hinted_answer( $question_id, $quiz_id, $course_id = 0 ) {
1166 - if ( ! $course_id ) {
1167 - $course_id = get_the_ID();
1168 - }
1169 -
1170 - $quiz_data = $this->get_item_data( $quiz_id, $course_id );
1171 -
1172 - return $quiz_data ? $quiz_data->has_hinted_question( $question_id ) : false;
1173 - }
1174 -
1175 - /**
1176 996 * Return TRUE if user is already exists.
1177 997 *
1178 998 * @return bool
1179 999 */
@@ -1197,13 +1017,33 @@
1197 1017 * @param mixed $size
1198 1018 *
1199 1019 * @return string
1200 1020 */
1201 - public function get_upload_profile_src( $size = '' ) {
1202 - return LP_Profile::instance( $this->get_id() )->get_upload_profile_src( $size );
1021 + public function get_upload_profile_src() {
1022 + return LP_Profile::instance( $this->get_id() )->get_upload_profile_src();
1203 1023 }
1204 1024
1205 1025 /**
1026 + * Get profile avatar url
1027 + *
1028 + * @return string
1029 + * @since 4.2.7.2
1030 + * @version 1.0.0
1031 + */
1032 + public function get_profile_avatar_url(): string {
1033 + $avatar_url = $this->get_upload_profile_src();
1034 + if ( empty( $avatar_url ) ) {
1035 + $args = learn_press_get_avatar_thumb_size();
1036 + $avatar_url = get_avatar_url( $this->get_id(), $args );
1037 + if ( empty( $avatar_url ) ) {
1038 + $avatar_url = LP_PLUGIN_URL . 'assets/images/avatar-default.png';
1039 + }
1040 + }
1041 +
1042 + return $avatar_url;
1043 + }
1044 +
1045 + /**
1206 1046 * @param string $type
1207 1047 * @param int $size
1208 1048 * @param bool $src_only
1209 1049 *
@@ -1214,11 +1054,13 @@
1214 1054 }
1215 1055
1216 1056 /**
1217 1057 * Get links socials of use on Profile page
1058 + * Icon is font awesome
1218 1059 *
1219 1060 * @param int $user_id
1220 1061 * @return array
1062 + * @deprecated 4.2.3
1221 1063 */
1222 1064 public function get_profile_socials( int $user_id = 0 ): array {
1223 1065 $socials = array();
1224 1066 $extra_info = learn_press_get_user_extra_profile_info( $user_id );
@@ -1230,21 +1072,24 @@
1230 1072 }
1231 1073
1232 1074 switch ( $k ) {
1233 1075 case 'facebook':
1234 - $i = '<i class="fab fa-facebook-f"></i>';
1076 + $i = '<i class="lp-icon-facebook-f"></i>';
1235 1077 break;
1236 1078 case 'twitter':
1237 - $i = '<i class="fab fa-twitter"></i>';
1079 + $i = '<i class="lp-icon-twitter"></i>';
1238 1080 break;
1239 1081 case 'googleplus':
1240 - $i = '<i class="fab fa-google-plus-g"></i>';
1082 + $i = '<i class="lp-icon-google-plus"></i>';
1241 1083 break;
1242 1084 case 'youtube':
1243 - $i = '<i class="fab fa-youtube"></i>';
1085 + $i = '<i class="lp-icon-youtube-play"></i>';
1244 1086 break;
1087 + case 'linkedin':
1088 + $i = '<i class="lp-icon-linkedin"></i>';
1089 + break;
1245 1090 default:
1246 - $i = sprintf( '<i class="fab fa-%s"></i>', $k );
1091 + $i = sprintf( '<i class="lp-icon-%s"></i>', $k );
1247 1092 }
1248 1093
1249 1094 $icon = apply_filters(
1250 1095 'learn-press/user-profile-social-icon',
@@ -1260,8 +1105,58 @@
1260 1105 return apply_filters( 'learn-press/user-profile-socials', $socials, $this->get_id(), $this );
1261 1106 }
1262 1107
1263 1108 /**
1109 + * Get links socials of use on Profile page
1110 + * Icon is svg
1111 + *
1112 + * @param int $user_id
1113 + * @return array
1114 + * @since 4.2.3
1115 + * @version 1.0.0
1116 + */
1117 + public function get_profile_social( int $user_id = 0 ): array {
1118 + $socials = array();
1119 + $extra_info = learn_press_get_user_extra_profile_info( $user_id );
1120 +
1121 + if ( $extra_info ) {
1122 + foreach ( $extra_info as $k => $v ) {
1123 + if ( empty( $v ) ) {
1124 + continue;
1125 + }
1126 +
1127 + switch ( $k ) {
1128 + case 'facebook':
1129 + $i = '<i class="lp-user-ico lp-icon-facebook"></i>';
1130 + break;
1131 + case 'twitter':
1132 + $i = '<i class="lp-user-ico lp-icon-twitter"></i>';
1133 + break;
1134 + case 'linkedin':
1135 + $i = '<i class="lp-user-ico lp-icon-linkedin"></i>';
1136 + break;
1137 + case 'youtube':
1138 + $i = '<i class="lp-user-ico lp-icon-youtube-play"></i>';
1139 + break;
1140 + default:
1141 + $i = sprintf( '<i class="lp-user-ico lp-icon-%s"></i>', esc_attr( $k ) );
1142 + }
1143 +
1144 + $icon = apply_filters(
1145 + 'learn-press/user-profile-social-icon',
1146 + $i,
1147 + $k,
1148 + $this->get_id(),
1149 + $this
1150 + );
1151 + $socials[ $k ] = sprintf( '<a href="%s">%s</a>', esc_url_raw( $v ), $icon );
1152 + }
1153 + }
1154 +
1155 + return apply_filters( 'learn-press/user-profile-socials', $socials, $this->get_id(), $this );
1156 + }
1157 +
1158 + /**
1264 1159 * Check course of user has graduation is in-progress
1265 1160 *
1266 1161 * @param $course_id
1267 1162 * @return bool
@@ -1270,9 +1165,9 @@
1270 1165 public function is_course_in_progress( $course_id ): bool {
1271 1166 $user = learn_press_get_user( $this->get_id() );
1272 1167 $user_course = $user->get_course_data( $course_id );
1273 1168
1274 - return $user_course && LP_COURSE_GRADUATION_IN_PROGRESS === $user_course->get_graduation();
1169 + return $user_course && LP_COURSE_GRADUATION_IN_PROGRESS === $user_course->get_graduation();
1275 1170 }
1276 1171
1277 1172 /**
1278 1173 * Return TRUE if user can do a quiz
@@ -1314,10 +1209,17 @@
1314 1209
1315 1210 return $course_results['completed_items'] >= $course->count_items();
1316 1211 }
1317 1212
1213 + /**
1214 + * Get role of user.
1215 + *
1216 + * @return string
1217 + * @since 3.0.0
1218 + * @version 1.0.1
1219 + */
1318 1220 public function get_role() {
1319 - return $this->is_admin() ? 'admin' : ( $this->is_instructor() ? 'instructor' : 'user' );
1221 + return $this->get_data( 'role' );
1320 1222 }
1321 1223
1322 1224 /**
1323 1225 * Get user course's grade.
@@ -1346,9 +1248,9 @@
1346 1248 *
1347 1249 * @return bool
1348 1250 */
1349 1251 public function is_guest(): bool {
1350 - return ! $this->get_id() || ! get_user_by( 'id', $this->get_id() );
1252 + return $this instanceof LP_User_Guest;
1351 1253 }
1352 1254
1353 1255 /**
1354 1256 * Check if user can edit a post.
@@ -1388,9 +1290,9 @@
1388 1290 *
1389 1291 * @return string
1390 1292 */
1391 1293 public function get_description(): string {
1392 - return $this->get_data( 'description', '' );
1294 + return get_the_author_meta( 'description', $this->get_id() );
1393 1295 }
1394 1296
1395 1297 /**
1396 1298 * Return user first name.