PluginProbe
Tutor LMS – eLearning and online course solution / 3.9.15
Tutor LMS – eLearning and online course solution v3.9.15
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
← All changes | classes/Template.php +77 -181 trunk3.9.15 View file →
@@ -9,10 +9,8 @@
9 9 */
10 10
11 11 namespace TUTOR;
12 12
13 -use Tutor\Helpers\UrlHelper;
14 -
15 13 if ( ! defined( 'ABSPATH' ) ) {
16 14 exit;
17 15 }
18 16
@@ -23,15 +21,8 @@
23 21 */
24 22 class Template extends Tutor_Base {
25 23
26 24 /**
27 - * Store Shortcode Object
28 - *
29 - * @var Shortcode
30 - */
31 - public $shortcode_obj;
32 -
33 - /**
34 25 * Register Hooks
35 26 *
36 27 * @since 1.0.0
37 28 */
@@ -50,11 +41,12 @@
50 41 }
51 42
52 43 add_filter( 'template_include', array( $this, 'load_course_archive_template' ), 99 );
53 44 add_filter( 'template_include', array( $this, 'load_single_course_template' ), 99 );
45 + add_filter( 'template_include', array( $this, 'load_single_lesson_template' ), 99 );
54 46 add_filter( 'template_include', array( $this, 'play_private_video' ), 99 );
55 - add_filter( 'tutor_single_content_template', array( $this, 'load_single_lesson_template' ), 99, 2 );
56 - add_filter( 'tutor_single_content_template', array( $this, 'load_quiz_template' ), 99, 2 );
47 + add_filter( 'template_include', array( $this, 'load_quiz_template' ), 99 );
48 + add_filter( 'template_include', array( $this, 'load_assignment_template' ), 99 );
57 49
58 50 add_filter( 'template_include', array( $this, 'student_public_profile' ), 99 );
59 51 add_filter( 'template_include', array( $this, 'tutor_dashboard' ), 99 );
60 52 add_filter( 'pre_get_document_title', array( $this, 'student_public_profile_title' ) );
@@ -60,11 +52,8 @@
60 52 add_filter( 'pre_get_document_title', array( $this, 'student_public_profile_title' ) );
61 53
62 54 add_filter( 'the_content', array( $this, 'convert_static_page_to_template' ) );
63 55 add_action( 'pre_get_posts', array( $this, 'limit_course_query_archive' ), 99 );
64 - add_filter( 'template_include', array( $this, 'load_learning_template' ) );
65 -
66 - $this->shortcode_obj = new Shortcode( false );
67 56 }
68 57
69 58 /**
70 59 * Load default template for course
@@ -172,17 +161,13 @@
172 161 * @return bool|string
173 162 */
174 163 public function load_single_course_template( $template ) {
175 164 global $wp_query;
165 +
176 166 if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === $this->course_post_type ) {
177 - // Check if the slug contains subpage of learning area.
178 - if ( Input::has( 'subpage' ) ) {
179 - $template = tutor_get_template( 'learning-area.index' );
180 - } else {
181 - do_action( 'single_course_template_before_load', get_the_ID() );
182 - wp_reset_query();
183 - $template = tutor_get_template( 'single-course' );
184 - }
167 + do_action( 'single_course_template_before_load', get_the_ID() );
168 + wp_reset_query();
169 + return tutor_get_template( 'single-course' );
185 170 }
186 171
187 172 return $template;
188 173 }
@@ -205,23 +190,20 @@
205 190 * Load lesson template
206 191 *
207 192 * @since v.1.0.0
208 193 *
209 - * @since 4.0.0 Post type argument added
210 - *
211 194 * @param string $template template name to load.
212 - * @param string $post_type Post type added.
213 195 *
214 196 * @return bool|string
215 197 */
216 - public function load_single_lesson_template( $template, $post_type ) {
217 - if ( tutor()->lesson_post_type !== $post_type ) {
218 - return $template;
219 - }
198 + public function load_single_lesson_template( $template ) {
199 + global $wp_query;
220 200
221 - $is_lesson_post_type = apply_filters( 'tutor_is_lesson_post_type', true, $post_type );
201 + $post_type = get_query_var( 'post_type' );
222 202
223 - if ( $is_lesson_post_type ) {
203 + $is_lesson_post_type = apply_filters( 'tutor_is_lesson_post_type', $wp_query->query_vars['post_type'] === $this->lesson_post_type, $post_type );
204 +
205 + if ( $wp_query->is_single && ! empty( $post_type ) && $is_lesson_post_type ) {
224 206 $page_id = get_the_ID();
225 207
226 208 do_action( 'tutor_lesson_load_before', $template );
227 209 setup_postdata( $page_id );
@@ -245,9 +227,8 @@
245 227 }
246 228
247 229 return apply_filters( 'tutor_lesson_template', $template );
248 230 }
249 -
250 231 return $template;
251 232 }
252 233
253 234 /**
@@ -289,9 +270,9 @@
289 270
290 271 /**
291 272 * Tutor Dashboard Page, Responsible to show dashboard stuffs
292 273 *
293 - * @since 1.0.0
274 + * @since v.1.0.0
294 275 *
295 276 * @param string $content page content.
296 277 *
297 278 * @return mixed
@@ -296,54 +277,42 @@
296 277 *
297 278 * @return mixed
298 279 */
299 280 public function convert_static_page_to_template( $content ) {
300 - /**
301 - * Avoid rendering dynamic templates or shortcodes during head generation.
302 - *
303 - * Some plugins (e.g., Yoast SEO) may process `the_content` while generating
304 - * frontend metadata in `wp_head`, which can cause templates or shortcodes
305 - * to be rendered multiple times within the same request.
306 - *
307 - * @since 4.0.0
308 - */
309 - if ( ! is_admin() && doing_action( 'wp_head' ) ) {
310 - return $content;
311 - }
312 -
313 - $page_id = get_the_ID();
314 -
315 281 // Dashboard Page.
316 282 $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
317 - if ( $page_id === $student_dashboard_page_id ) {
318 - return $this->shortcode_obj->tutor_dashboard();
283 + if ( get_the_ID() === $student_dashboard_page_id ) {
284 + $shortcode = new Shortcode( false );
285 + return $shortcode->tutor_dashboard();
319 286 }
320 287
321 288 // Instructor Registration Page.
322 289 $instructor_register_page_page_id = (int) tutor_utils()->get_option( 'instructor_register_page' );
323 - if ( $page_id === $instructor_register_page_page_id ) {
324 - return $this->shortcode_obj->instructor_registration_form();
290 + if ( get_the_ID() === $instructor_register_page_page_id ) {
291 + $shortcode = new Shortcode( false );
292 + return $shortcode->instructor_registration_form();
325 293 }
326 294
327 295 $student_register_page_id = (int) tutor_utils()->get_option( 'student_register_page' );
328 - if ( $page_id === $student_register_page_id ) {
329 - return $this->shortcode_obj->student_registration_form();
296 + if ( get_the_ID() === $student_register_page_id ) {
297 + $shortcode = new Shortcode( false );
298 + return $shortcode->student_registration_form();
330 299 }
331 300
332 - if ( tutor_utils()->is_monetize_by_tutor() ) {
333 - $tutor_cart_page_id = (int) tutor_utils()->get_option( 'tutor_cart_page_id' );
334 - if ( $page_id === $tutor_cart_page_id ) {
335 - return $this->shortcode_obj->tutor_cart_page();
301 + $tutor_cart_page_id = (int) tutor_utils()->get_option( 'tutor_cart_page_id' );
302 + if ( get_the_ID() === $tutor_cart_page_id ) {
303 + $shortcode = new Shortcode( false );
304 + return $shortcode->tutor_cart_page();
305 + }
306 +
307 + $tutor_checkout_page_id = (int) tutor_utils()->get_option( 'tutor_checkout_page_id' );
308 + if ( get_the_ID() === $tutor_checkout_page_id ) {
309 + if ( ! apply_filters( 'tutor_should_load_checkout_page', true ) ) {
310 + return;
336 311 }
337 312
338 - $tutor_checkout_page_id = (int) tutor_utils()->get_option( 'tutor_checkout_page_id' );
339 - if ( $page_id === $tutor_checkout_page_id ) {
340 - if ( ! apply_filters( 'tutor_should_load_checkout_page', true ) ) {
341 - return '';
342 - }
343 -
344 - return $this->shortcode_obj->tutor_checkout_page();
345 - }
313 + $shortcode = new Shortcode( false );
314 + return $shortcode->tutor_checkout_page();
346 315 }
347 316
348 317 return $content;
349 318 }
@@ -405,38 +374,11 @@
405 374 $query_var = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars );
406 375 $dashboard_pages = tutor_utils()->tutor_dashboard_pages();
407 376 $dashboard_page_item = tutor_utils()->array_get( $query_var, $dashboard_pages );
408 377 $auth_cap = tutor_utils()->array_get( 'auth_cap', $dashboard_page_item );
409 -
410 - $can_access_instructor_item = tutor()->instructor_role === $auth_cap && User::can_view_instructor_dashboard();
411 -
412 - if ( $auth_cap && ! User::is_admin() && ! current_user_can( $auth_cap ) && ! $can_access_instructor_item
413 - ) {
378 + if ( $auth_cap && ! current_user_can( $auth_cap ) ) {
414 379 $template = tutor_get_template( 'permission-denied' );
415 380 }
416 -
417 - /**
418 - * Account pages of dashboard.
419 - *
420 - * @since 4.0.0
421 - */
422 - if ( Dashboard::ACCOUNT_PAGE_SLUG === $dashboard_page ) {
423 - $subpage = tutor_utils()->array_get( 'tutor_dashboard_sub_page', $wp_query->query_vars, 'profile' );
424 - $account_pages = Dashboard::get_account_pages();
425 - $page_data = $account_pages[ $subpage ] ?? array();
426 - $page_template = $page_data['template'] ?? '';
427 -
428 - if ( file_exists( $page_template ) ) {
429 - $template = tutor_get_template( 'account' );
430 - }
431 - }
432 -
433 - $dashboard_subpage = tutor_utils()->array_get( 'tutor_dashboard_sub_page', $wp_query->query_vars );
434 - $is_isolated = Dashboard::is_isolated_page_request( $dashboard_page, $dashboard_subpage );
435 -
436 - if ( $is_isolated ) {
437 - $template = tutor_get_template( 'dashboard-isolated' );
438 - }
439 381 } else {
440 382 $template = tutor_get_template( 'login' );
441 383 }
442 384 }
@@ -452,35 +394,60 @@
452 394 *
453 395 * If course public then enrollment not required
454 396 *
455 397 * @since 2.0.2
456 - * @since 4.0.0 $post_type param added.
457 398 *
458 399 * @param string $template template to load.
459 - * @param string $post_type Post type.
460 400 *
461 401 * @return bool|string
462 402 */
463 - public function load_quiz_template( $template, $post_type ) {
464 - if ( tutor()->quiz_post_type !== $post_type ) {
403 + public function load_quiz_template( $template ) {
404 + global $wp_query, $post;
405 +
406 + if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_quiz' === $wp_query->query_vars['post_type'] ) {
407 + if ( is_user_logged_in() ) {
408 + $has_content_access = tutor_utils()->has_enrolled_content_access( 'quiz' );
409 + $course_id = tutor_utils()->get_course_id_by_content( $post );
410 + $is_public = Course_List::is_public( $course_id );
411 +
412 + // if public course don't need to be enrolled.
413 + if ( $has_content_access || $is_public ) {
414 + $template = tutor_get_template( 'single-quiz' );
415 + } else {
416 + $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
417 + }
418 + } else {
419 + $template = tutor_get_template( 'login' );
420 + }
465 421 return $template;
466 422 }
423 + return $template;
424 + }
467 425
468 - global $post;
426 + /**
427 + * Load assignment template
428 + *
429 + * @since 1.0.0
430 + *
431 + * @param string $template template file to load.
432 + *
433 + * @return string template path
434 + */
435 + public function load_assignment_template( $template ) {
436 + global $wp_query;
469 437
470 - if ( is_user_logged_in() ) {
471 - $has_content_access = tutor_utils()->has_enrolled_content_access( 'quiz' );
472 - $course_id = tutor_utils()->get_course_id_by_content( $post );
473 - $is_public = Course_List::is_public( $course_id );
474 -
475 - // if public course don't need to be enrolled.
476 - if ( $has_content_access || $is_public ) {
477 - $template = tutor_get_template( 'single-quiz' );
438 + if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_assignments' === $wp_query->query_vars['post_type'] ) {
439 + if ( is_user_logged_in() ) {
440 + $has_content_access = tutor_utils()->has_enrolled_content_access( 'assignment' );
441 + if ( $has_content_access ) {
442 + $template = tutor_get_template( 'single-assignment' );
443 + } else {
444 + $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
445 + }
478 446 } else {
479 - $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
447 + $template = tutor_get_template( 'login' );
480 448 }
481 - } else {
482 - $template = tutor_get_template( 'login' );
449 + return $template;
483 450 }
484 451
485 452 return $template;
486 453 }
@@ -524,77 +491,6 @@
524 491 return sprintf( "%s's %s", $user->display_name, __( 'Profile Page', 'tutor' ) );
525 492 }
526 493 }
527 494 return '';
528 - }
529 -
530 - /**
531 - * Load learning template
532 - *
533 - * @since 4.0.0
534 - *
535 - * @param string $template template to load.
536 - *
537 - * @return string
538 - */
539 - public function load_learning_template( string $template ): string {
540 - if ( tutor_utils()->is_learning_area() ) {
541 - $user_id = get_current_user_id();
542 - $post_type = get_post_type();
543 - $post_id = get_the_ID();
544 - $course_id = tutor()->course_post_type === $post_type ? $post_id : tutor_utils()->get_course_id_by_subcontent( $post_id );
545 - if ( ! in_array( get_post_status( $course_id ), array( 'publish', 'private' ), true ) && ! tutor_utils()->has_user_course_content_access( $user_id, $course_id ) ) {
546 - global $wp_query;
547 - $wp_query->set_404();
548 - status_header( 404 );
549 - return get_404_template();
550 - }
551 -
552 - $legacy_mode = Options_V2::LEARNING_MODE_LEGACY === tutor_utils()->get_option( 'learning_mode' );
553 -
554 - $template_path = apply_filters( 'tutor_single_content_template', $template, $post_type );
555 -
556 - $template = $legacy_mode ? $template_path : tutor_get_template( 'learning-area.index' );
557 - }
558 -
559 - return $template;
560 - }
561 -
562 - /**
563 - * Make learning area sub pages nav items
564 - *
565 - * @since 4.0.0
566 - *
567 - * @param string $base_url Nav items base url.
568 - *
569 - * @return array
570 - */
571 - public static function make_learning_area_sub_page_nav_items( $base_url = '' ): array {
572 - if ( empty( $base_url ) ) {
573 - $base_url = get_permalink();
574 - }
575 -
576 - $menu_items = apply_filters( 'tutor_learning_area_sub_page_nav_item', array(), $base_url );
577 -
578 - $menu_items['course-info'] = array(
579 - 'title' => __( 'Course Info', 'tutor' ),
580 - 'icon' => Icon::INFO_OCTAGON,
581 - 'url' => UrlHelper::add_query_params( $base_url, array( 'subpage' => 'course-info' ) ),
582 - 'template' => tutor_get_template( 'learning-area.subpages.course-info' ),
583 - );
584 -
585 - return apply_filters( 'tutor_learning_area_sub_page_menu_items', $menu_items, $base_url );
586 - }
587 -
588 - /**
589 - * Get learning area active subpage
590 - *
591 - * @since 4.0.0
592 - *
593 - * @return string
594 - */
595 - public static function learning_area_active_subpage(): string {
596 - $active_menu = Input::get( 'subpage', '' );
597 -
598 - return apply_filters( 'tutor_learning_area_active_subpage', $active_menu );
599 495 }
600 496 }