PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 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 All 140 releases
← All changes | inc/templates/class-lp-template-profile.php +143 -133 4.1.7.3.2 → 4.4.9 View file →
@@ -1,5 +1,12 @@
1 1 <?php
2 +
3 +use LearnPress\Helpers\Template;
4 +use LearnPress\Models\UserModel;
5 +use LearnPress\TemplateHooks\Instructor\SingleInstructorTemplate;
6 +use LearnPress\TemplateHooks\Profile\ProfileTemplate;
7 +use LearnPress\TemplateHooks\UserTemplate;
8 +
2 9 /**
3 10 * Class LP_Profile_Template
4 11 *
5 12 * Group templates related user profile.
@@ -7,54 +14,48 @@
7 14 * @since 4.0.0
8 15 */
9 16 class LP_Template_Profile extends LP_Abstract_Template {
10 17 public function header( $user ) {
11 - $profile = LP_Global::profile();
18 + learn_press_get_template( 'profile/header.php', array( 'user' => $user ) );
19 + }
12 20
21 + public function sidebar() {
22 + $profile = LP_Profile::instance();
13 23 if ( $profile->get_user()->is_guest() ) {
14 24 return;
15 25 }
16 26
17 - learn_press_get_template( 'profile/header.php', array( 'user' => $user ) );
18 - }
19 -
20 - public function sidebar() {
21 - $profile = LP_Global::profile();
22 -
23 - if ( $profile->get_user()->is_guest() ) {
27 + if ( $profile->get_user_current()->is_guest()
28 + && 'yes' !== LP_Profile::get_option_publish_profile() ) {
24 29 return;
25 30 }
26 31
32 + $user = $profile->get_user();
33 + $userModel = UserModel::find( $user->get_id(), true );
34 + // Display cover image
35 + echo ProfileTemplate::instance()->html_cover_image( $userModel );
36 + // Display Sidebar
27 37 learn_press_get_template( 'profile/sidebar.php' );
28 38 }
29 39
30 40 /**
31 - * @param LP_Profile $user
41 + * @param LP_Profile $profile
42 + *
43 + * @since 3.0.0
44 + * @version 1.0.1
32 45 */
33 - public function content( LP_Profile $user ) {
34 - $profile = LP_Global::profile();
35 - $user_id = get_current_user_id();
36 -
37 - if ( $profile->get_user()->is_guest() ) {
46 + public function content( LP_Profile $profile ) {
47 + $user = $profile->get_user();
48 + $current_tab = $profile->get_current_tab();
49 + $user_can_view = $profile->current_user_can( 'view-tab-' . $current_tab );
50 + if ( ! $user_can_view ) {
38 51 return;
39 52 }
40 53
41 - $current_tab = $profile->get_current_tab();
42 -
43 - if ( 'settings' === $current_tab && ( ! $user_id || $user_id != $profile->get_user()->get_id() ) ) {
54 + if ( $profile->get_user_current()->is_guest() ) {
44 55 return;
45 56 }
46 57
47 - $privacy = get_user_meta( $user->get_user()->get_id(), '_lp_profile_privacy', true );
48 -
49 - if ( ! current_user_can( ADMIN_ROLE ) && ( $user->get_user()->get_id() != $user_id && empty( $privacy ) ) ) {
50 - return;
51 - }
52 -
53 - $profile = learn_press_get_profile();
54 - /**
55 - * LP_Profile_Tabs
56 - */
57 58 $tabs = $profile->get_tabs();
58 59 $tab_key = $profile->get_current_tab();
59 60 $profile_tab = $tabs->get( $tab_key );
60 61
@@ -60,10 +61,26 @@
60 61
61 62 learn_press_get_template( 'profile/content.php', compact( 'user', 'profile_tab', 'tab_key', 'profile' ) );
62 63 }
63 64
65 + /**
66 + * Display avatar
67 + *
68 + * @return void
69 + * @version 1.0.1
70 + * @since 3.x.x
71 + */
64 72 public function avatar() {
65 - learn_press_get_template( 'profile/avatar.php' );
73 + $lp_profile = LP_Profile::instance();
74 + $user = $lp_profile->get_user();
75 + $userModel = UserModel::find( $user->get_id(), true );
76 + if ( ! $userModel instanceof UserModel ) {
77 + return;
78 + }
79 +
80 + $userTemplate = new UserTemplate();
81 + echo $userTemplate->html_avatar_edit( $userModel );
82 + //learn_press_get_template( 'profile/avatar.php' );
66 83 }
67 84
68 85 public function socials() {
69 86 learn_press_get_template( 'profile/socials.php' );
@@ -69,11 +86,10 @@
69 86 learn_press_get_template( 'profile/socials.php' );
70 87 }
71 88
72 89 public function tabs( $user = null ) {
73 - $profile = LP_Global::profile();
74 -
75 - if ( $profile->get_user()->is_guest() ) {
90 + $profile = LP_Profile::instance();
91 + if ( $profile->get_user_current()->is_guest() ) {
76 92 return;
77 93 }
78 94
79 95 learn_press_get_template( 'profile/tabs.php', compact( 'user', 'profile' ) );
@@ -81,12 +97,12 @@
81 97
82 98 /**
83 99 * Get template tab course
84 100 *
85 - * @author tungnx
101 + * @return void
86 102 * @since 4.1.5
87 103 * @version 1.0.0
88 - * @return void
104 + * @author tungnx
89 105 */
90 106 public static function tab_courses() {
91 107 if ( ! LP_Profile::instance()->current_user_can( 'view-tab-courses' ) ) {
92 108 return;
@@ -93,19 +109,8 @@
93 109 }
94 110
95 111 $user = LP_Profile::instance()->get_user();
96 112
97 - $courses_enrolled_tab = apply_filters(
98 - 'lp/profile/user_courses_attend/subtask',
99 - array(
100 - '' => esc_html__( 'All', 'learnpress' ),
101 - 'in-progress' => esc_html__( 'In Progress', 'learnpress' ),
102 - 'finished' => esc_html__( 'Finished', 'learnpress' ),
103 - 'passed' => esc_html__( 'Passed', 'learnpress' ),
104 - 'failed' => esc_html__( 'Failed', 'learnpress' ),
105 - )
106 - );
107 -
108 113 $courses_created_tab = apply_filters(
109 114 'lp/profile/user_courses_created/subtask',
110 115 array(
111 116 '' => esc_html__( 'All', 'learnpress' ),
@@ -113,16 +118,9 @@
113 118 'pending' => esc_html__( 'Pending', 'learnpress' ),
114 119 )
115 120 );
116 121
117 - $courses_enrolled_tab_active = apply_filters( 'learnpress/profile/tab/enrolled/subtab-active', ! learn_press_user_maybe_is_a_teacher() ? 'in-progress' : '' );
118 - $tab_active = LP_Helper::sanitize_params_submitted( $_GET['tab'] ?? '' );
119 - if ( ! $tab_active ) {
120 - $tab_active = ! learn_press_user_maybe_is_a_teacher() ? 'enrolled' : 'created';
121 - }
122 - $tab_active = apply_filters( 'learnpress/profile/tab-active', $tab_active );
123 -
124 - $args_query_user_courses_created = apply_filters(
122 + $args_query_user_courses_created = apply_filters(
125 123 'lp/profile/args/user_courses_created',
126 124 array(
127 125 'userID' => $user->get_id(),
128 126 'query' => 'own',
@@ -127,8 +125,47 @@
127 125 'userID' => $user->get_id(),
128 126 'query' => 'own',
129 127 )
130 128 );
129 +
130 + $args_query_user_courses_statistic = apply_filters(
131 + 'lp/profile/args/user_courses_statistic',
132 + array(
133 + 'userID' => $user->get_id(),
134 + )
135 + );
136 +
137 + do_action(
138 + 'learn-press/profile/layout/courses',
139 + compact(
140 + 'user',
141 + 'courses_created_tab',
142 + 'args_query_user_courses_created',
143 + 'args_query_user_courses_statistic'
144 + )
145 + );
146 + }
147 +
148 + public static function tab_my_courses() {
149 + if ( ! LP_Profile::instance()->current_user_can( 'view-tab-my-courses' ) ) {
150 + return;
151 + }
152 +
153 + $user = LP_Profile::instance()->get_user();
154 +
155 + $courses_enrolled_tab = apply_filters(
156 + 'lp/profile/user_courses_attend/subtask',
157 + array(
158 + '' => esc_html__( 'All', 'learnpress' ),
159 + 'in-progress' => esc_html__( 'In Progress', 'learnpress' ),
160 + 'finished' => esc_html__( 'Finished', 'learnpress' ),
161 + 'passed' => esc_html__( 'Passed', 'learnpress' ),
162 + 'failed' => esc_html__( 'Failed', 'learnpress' ),
163 + )
164 + );
165 +
166 + $courses_enrolled_tab_active = apply_filters( 'learnpress/profile/tab/enrolled/subtab-active', ! learn_press_user_maybe_is_a_teacher() ? 'in-progress' : '' );
167 +
131 168 $args_query_user_courses_attend = apply_filters(
132 169 'lp/profile/args/user_courses_attend',
133 170 array(
134 171 'userID' => $user->get_id(),
@@ -143,17 +180,14 @@
143 180 )
144 181 );
145 182
146 183 learn_press_get_template(
147 - 'profile/tabs/courses',
184 + 'profile/tabs/my_courses',
148 185 compact(
149 186 'user',
150 - 'courses_created_tab',
151 187 'courses_enrolled_tab',
152 - 'tab_active',
153 188 'courses_enrolled_tab_active',
154 189 'args_query_user_courses_attend',
155 - 'args_query_user_courses_created',
156 190 'args_query_user_courses_statistic'
157 191 )
158 192 );
159 193 }
@@ -158,84 +192,58 @@
158 192 );
159 193 }
160 194
161 195 /**
162 - * @author tungnx
163 - * @deprecated 4.1.6
196 + * Display tab avatar image
197 + *
198 + * @return void
199 + * @since 4.2.8.2
200 + * @version 1.0.0
164 201 */
165 - /*public function dashboard_statistic() {
166 - $user = $this->get_user();
167 - $query = LP_Profile::instance()->query_courses( 'purchased' );
168 - $counts = $query['counts'];
169 - $statistic = array(
170 - 'enrolled_courses' => isset( $counts['all'] ) ? $counts['all'] : 0,
171 - 'active_courses' => isset( $counts['in-progress'] ) ? $counts['in-progress'] : 0,
172 - 'completed_courses' => isset( $counts['finished'] ) ? $counts['finished'] : 0,
173 - 'total_courses' => count_user_posts( $user->get_id(), LP_COURSE_CPT ),
174 - 'total_users' => learn_press_count_instructor_users( $user->get_id() ),
175 - );
202 + public static function tab_avatar() {
203 + if ( ! LP_Profile::instance()->current_user_can( 'view-tab-avatar' ) ) {
204 + return;
205 + }
176 206
177 - learn_press_get_template( 'profile/tabs/courses/general-statistic', compact( 'statistic' ) );
178 - }*/
179 -
180 - public function dashboard_featured_courses() {
181 - $profile_privacy = $this->get_user()->get_extra_data(
182 - 'profile_privacy',
183 - array(
184 - 'courses' => 'no',
185 - 'quizzes' => 'no',
186 - )
187 - );
188 -
189 - if ( $this->get_user()->get_id() !== get_current_user_id() && 'yes' !== $profile_privacy['courses'] ) {
207 + $user = LP_Profile::instance()->get_user();
208 + $userModel = UserModel::find( $user->get_id(), true );
209 + if ( ! $userModel ) {
190 210 return;
191 211 }
192 212
193 - $user = $this->get_user();
194 - $query = new LP_Course_Query(
195 - array(
196 - 'paginate' => true,
197 - 'featured' => 'yes',
198 - 'return' => 'ids',
199 - 'author' => $user->get_id(),
200 - )
201 - );
202 -
203 - $data = $query->get_courses();
204 -
205 - learn_press_get_template( 'profile/dashboard/featured-courses', (array) $data );
213 + echo ProfileTemplate::instance()->html_upload_avatar( $userModel );
206 214 }
207 215
208 - public function dashboard_latest_courses() {
209 - $profile_privacy = $this->get_user()->get_extra_data(
210 - 'profile_privacy',
211 - array(
212 - 'courses' => 'no',
213 - 'quizzes' => 'no',
214 - )
215 - );
216 + /**
217 + * Display tab cover image
218 + *
219 + * @return void
220 + * @since 4.2.7.2
221 + * @version 1.0.0
222 + */
223 + public static function tab_cover_image() {
224 + if ( ! LP_Profile::instance()->current_user_can( 'view-tab-cover-image' ) ) {
225 + return;
226 + }
216 227
217 - if ( $this->get_user()->get_id() !== get_current_user_id() && 'yes' !== $profile_privacy['courses'] ) {
228 + $user = LP_Profile::instance()->get_user();
229 + $userModel = UserModel::find( $user->get_id(), true );
230 + if ( ! $userModel ) {
218 231 return;
219 232 }
220 233
221 - $user = $this->get_user();
222 - $query = new LP_Course_Query(
223 - array(
224 - 'paginate' => true,
225 - 'return' => 'ids',
226 - 'author' => $user->get_id(),
227 - )
228 - );
229 -
230 - learn_press_get_template( 'profile/dashboard/latest-courses', (array) $query->get_courses() );
234 + echo ProfileTemplate::instance()->html_upload_cover_image( $userModel );
231 235 }
232 236
237 + /**
238 + * @deprecated v4.3.2.6
239 + */
233 240 public function order_details() {
241 + _deprecated_function( __METHOD__, '4.3.2.6' );
242 + return;
243 +
234 244 $profile = LP_Profile::instance();
235 -
236 - $order = $profile->get_view_order();
237 -
245 + $order = $profile->get_view_order();
238 246 if ( false === $order ) {
239 247 return;
240 248 }
241 249
@@ -264,15 +272,17 @@
264 272 learn_press_get_template( 'profile/tabs/orders/order-message.php', array( 'order' => $order ) );
265 273 }
266 274
267 275 public function dashboard_not_logged_in() {
268 - $profile = LP_Global::profile();
276 + if ( is_user_logged_in() ) {
277 + return;
278 + }
269 279
270 - if ( ! $profile->get_user()->is_guest() ) {
280 + if ( ! LP_Profile::instance()->get_user()->is_guest() ) {
271 281 return;
272 282 }
273 283
274 - if ( 'yes' === LP_Settings::instance()->get( 'enable_login_profile' ) || 'yes' === LP_Settings::instance()->get( 'enable_register_profile' ) ) {
284 + if ( 'yes' === LP_Settings::get_option( 'enable_login_profile' ) ) {
275 285 return;
276 286 }
277 287
278 288 learn_press_get_template( 'profile/not-logged-in.php' );
@@ -278,15 +288,20 @@
278 288 learn_press_get_template( 'profile/not-logged-in.php' );
279 289 }
280 290
281 291 public function login_form() {
282 - $profile = LP_Global::profile();
292 + if ( is_user_logged_in() && ! LP_Page_Controller::is_page_profile() ) {
293 + Template::print_message(
294 + esc_html__( 'You are already logged in.', 'learnpress' )
295 + );
296 + return;
297 + }
283 298
284 - if ( ! $profile->get_user()->is_guest() ) {
299 + if ( ! LP_Profile::instance()->get_user()->is_guest() ) {
285 300 return;
286 301 }
287 302
288 - if ( 'yes' !== LP_Settings::instance()->get( 'enable_login_profile' ) ) {
303 + if ( 'yes' !== LP_Settings::get_option( 'enable_login_profile', 'no' ) ) {
289 304 return;
290 305 }
291 306
292 307 learn_press_get_template( 'global/form-login.php' );
@@ -292,26 +307,21 @@
292 307 learn_press_get_template( 'global/form-login.php' );
293 308 }
294 309
295 310 public function register_form() {
296 - $profile = LP_Global::profile();
311 + if ( is_user_logged_in() ) {
312 + return;
313 + }
297 314
298 - if ( ! $profile->get_user()->is_guest() ) {
315 + if ( ! LP_Profile::instance()->get_user()->is_guest() ) {
299 316 return;
300 317 }
301 318
302 - if ( 'yes' !== LP_Settings::instance()->get( 'enable_register_profile' ) || ! get_option( 'users_can_register' ) ) {
319 + if ( 'yes' !== LP_Settings::get_option( 'enable_register_profile' ) || ! get_option( 'users_can_register' ) ) {
303 320 return;
304 321 }
305 322
306 323 learn_press_get_template( 'global/form-register.php' );
307 - }
308 -
309 - /**
310 - * @return bool|LP_User|mixed
311 - */
312 - protected function get_user() {
313 - return LP_Profile::instance()->get_user();
314 324 }
315 325 }
316 326
317 327 return new LP_Template_Profile();