PluginProbe
Tutor LMS – eLearning and online course solution / 3.7.2
Tutor LMS – eLearning and online course solution v3.7.2
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/Assets.php +63 -339 trunk3.7.2 View file →
@@ -9,16 +9,13 @@
9 9 */
10 10
11 11 namespace TUTOR;
12 12
13 -use Tutor\Ecommerce\CartController;
14 -use Tutor\Ecommerce\CheckoutController;
15 13 use Tutor\Ecommerce\CouponController;
16 14 use Tutor\Ecommerce\OptionKeys;
17 15 use Tutor\Ecommerce\OrderController;
18 16 use Tutor\Ecommerce\Settings;
19 17 use Tutor\Models\CourseModel;
20 -use Tutor\Options_V2;
21 18
22 19 if ( ! defined( 'ABSPATH' ) ) {
23 20 exit;
24 21 }
@@ -98,25 +95,8 @@
98 95 *
99 96 * @since v2.0.5
100 97 */
101 98 add_action( 'enqueue_block_editor_assets', __CLASS__ . '::add_frontend_editor_button' );
102 -
103 - /**
104 - * Enqueue styles & scripts
105 - *
106 - * @since 4.0.0
107 - */
108 - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
109 -
110 - // Add custom meta.
111 - add_action( 'wp_head', array( $this, 'add_custom_data' ) );
112 -
113 - /**
114 - * Add preload to CSS
115 - *
116 - * @since 4.0.0
117 - */
118 - add_filter( 'style_loader_tag', array( $this, 'add_preload_to_css' ), 10, 2 );
119 99 }
120 100
121 101 /**
122 102 * Load default localized data
@@ -173,19 +153,8 @@
173 153 );
174 154
175 155 $tutor_settings = Options_V2::get_only( $required_options );
176 156
177 - // Load available kids mode icons to avoid frontend 404s if kids mode is active.
178 - $kids_icons = array();
179 - if ( tutor_utils()->is_kids_mode() ) {
180 - $kids_icons = array_map(
181 - function ( $file ) {
182 - return basename( $file, '.svg' );
183 - },
184 - glob( tutor()->path . 'assets/icons/kids/*.svg' ) ?: array()
185 - );
186 - }
187 -
188 157 return array(
189 158 'ajaxurl' => admin_url( 'admin-ajax.php' ),
190 159 'home_url' => rtrim( get_home_url(), '/' ),
191 160 'site_url' => rtrim( get_site_url(), '/' ),
@@ -198,9 +167,8 @@
198 167 'loading_icon_url' => get_admin_url() . 'images/wpspin_light.gif',
199 168 'placeholder_img_src' => tutor_placeholder_img_src(),
200 169 'enable_lesson_classic_editor' => get_tutor_option( 'enable_lesson_classic_editor' ),
201 170 'tutor_frontend_dashboard_url' => tutor_utils()->get_tutor_dashboard_page_permalink(),
202 - 'is_dashboard_page' => tutor_utils()->is_dashboard_page(),
203 171 'wp_date_format' => tutor_js_date_format_against_wp(),
204 172 'start_of_week' => get_option( 'start_of_week', 1 ),
205 173 'is_admin' => is_admin(),
206 174 'is_admin_bar_showing' => is_admin_bar_showing(),
@@ -207,8 +175,9 @@
207 175 'addons_data' => tutor_utils()->prepare_free_addons_data(),
208 176 'current_user' => $current_user,
209 177 'content_change_event' => 'tutor_content_changed_event',
210 178 'is_tutor_course_edit' => isset( $_GET['action'] ) && 'edit' === $_GET['action'] && tutor()->course_post_type === get_post_type( get_the_ID() ) ? true : false,
179 + 'assignment_max_file_allowed' => 'tutor_assignments' === $post_type ? (int) tutor_utils()->get_assignment_option( $post_id, 'upload_files_limit' ) : 0,
211 180 'current_page' => $current_page,
212 181 'quiz_answer_display_time' => 1000 * (int) tutor_utils()->get_option( 'quiz_answer_display_time' ),
213 182 'is_ssl' => is_ssl(),
214 183 'course_list_page_url' => admin_url( 'admin.php?page=tutor' ),
@@ -215,18 +184,9 @@
215 184 'course_post_type' => tutor()->course_post_type,
216 185 'tutor_currency' => $tutor_currency,
217 186 'local' => get_locale(),
218 187 'settings' => $tutor_settings,
219 - 'max_upload_size' => wp_max_upload_size(),
220 - 'monetize_by' => tutor_utils()->get_option( 'monetize_by' ),
221 - 'kids_icons_registry' => $kids_icons,
222 - 'is_kids_mode' => tutor_utils()->is_kids_mode(),
223 - 'user_preferences' => UserPreference::get_preferences( get_current_user_id() ),
224 - 'is_legacy_learning_mode' => tutor_utils()->is_legacy_learning_mode(),
225 - 'course_slug' => tutor_utils()->get_option( 'course_permalink_base', 'courses' ),
226 - 'lesson_slug' => tutor_utils()->get_option( 'lesson_permalink_base', 'lessons' ),
227 - 'quiz_slug' => tutor_utils()->get_option( 'quiz_permalink_base', 'quizzes' ),
228 - 'is_tour_completed' => (bool) get_user_meta( get_current_user_id(), User::TOUR_COMPLETED_META, true ),
188 + 'max_upload_size' => size_format( wp_max_upload_size() ),
229 189 );
230 190 }
231 191
232 192 /**
@@ -234,16 +194,13 @@
234 194 *
235 195 * @since 1.0.0
236 196 * @since 3.0.0 Order details & coupon scripts added.
237 197 *
238 - * @param string $slug The page slug.
239 - *
240 198 * @return void
241 199 */
242 - public function admin_scripts( $slug ) {
200 + public function admin_scripts() {
243 201 wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.min.css', array(), TUTOR_VERSION );
244 202 wp_enqueue_style( 'tutor-admin', tutor()->url . 'assets/css/tutor-admin.min.css', array(), TUTOR_VERSION );
245 -
246 203 /**
247 204 * Scripts
248 205 */
249 206 wp_enqueue_media();
@@ -287,8 +244,13 @@
287 244
288 245 if ( 'tutor-addons' === $page ) {
289 246 wp_enqueue_script( 'tutor-coupon', tutor()->url . 'assets/js/tutor-addon-list.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
290 247 }
248 +
249 + if ( 'tutor-themes' === $page ) {
250 + wp_enqueue_style( 'tutor-template-import', tutor()->url . 'assets/css/tutor-template-import.min.css', array(), TUTOR_VERSION, 'all' );
251 + wp_enqueue_script( 'tutor-template-import-js', tutor()->url . 'assets/js/tutor-template-import-script.js', array( 'wp-i18n' ), TUTOR_VERSION, true );
252 + }
291 253 }
292 254
293 255 /**
294 256 * Load frontend scripts
@@ -293,18 +255,12 @@
293 255 /**
294 256 * Load frontend scripts
295 257 *
296 258 * @since 1.0.0
297 - *
298 - * @since 4.0.0 Legacy scripts loading check added.
299 - *
300 259 * @return void
301 260 */
302 261 public function frontend_scripts() {
303 - $load_legacy_scripts = self::should_load_legacy_scripts();
304 - if ( ! $load_legacy_scripts ) {
305 - return;
306 - }
262 + global $post, $wp_query;
307 263
308 264 /**
309 265 * We checked wp_enqueue_editor() in condition because it conflicting with Divi Builder
310 266 * condition updated @since v.1.7.4
@@ -315,17 +271,25 @@
315 271 if ( function_exists( 'et_pb_is_pagebuilder_used' ) ) {
316 272 $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
317 273 if ( ! $is_page_builder_used ) {
318 274 wp_enqueue_editor();
319 - wp_enqueue_script( 'quicktags' );
320 275 }
321 276 } else {
322 277 wp_enqueue_editor();
323 - wp_enqueue_script( 'quicktags' );
324 278 }
325 279 }
326 280
327 281 /**
282 + * Initializing quicktags script to use in wp_editor();
283 + */
284 + wp_enqueue_script( 'quicktags' );
285 +
286 + $tutor_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
287 + if ( get_the_ID() === $tutor_dashboard_page_id ) {
288 + wp_enqueue_media();
289 + }
290 +
291 + /**
328 292 * Enabling Sorting, draggable, droppable...
329 293 */
330 294 wp_enqueue_script( 'jquery-ui-sortable' );
331 295 wp_enqueue_script('jquery-touch-punch', ['jquery-ui-sortable']); //phpcs:ignore
@@ -339,8 +303,22 @@
339 303 // Social Share.
340 304 wp_enqueue_script( 'tutor-social-share', tutor()->url . 'assets/lib/SocialShare/SocialShare.min.js', array( 'jquery' ), TUTOR_VERSION, true );
341 305
342 306 /**
307 + * Chart Data
308 + */
309 + if ( ! empty( $wp_query->query_vars['tutor_dashboard_page'] ) ) {
310 + wp_enqueue_script( 'jquery-ui-slider' );
311 +
312 + wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.min.css', array(), TUTOR_VERSION );
313 + wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true );
314 +
315 + if ( 'earning' === $wp_query->query_vars['tutor_dashboard_page'] ) {
316 + wp_enqueue_script( 'tutor-front-chart-js', tutor()->url . 'assets/lib/Chart.bundle.min.js', array(), TUTOR_VERSION );
317 + wp_enqueue_script( 'jquery-ui-datepicker' );
318 + }
319 + }
320 + /**
343 321 * Dependency wp-i18n added for translate js file
344 322 *
345 323 * @since 1.9.0
346 324 */
@@ -345,8 +323,23 @@
345 323 * @since 1.9.0
346 324 */
347 325 wp_enqueue_style( 'tutor-frontend', tutor()->url . 'assets/css/tutor-front.min.css', array(), TUTOR_VERSION );
348 326 wp_enqueue_script( 'tutor-frontend', tutor()->url . 'assets/js/tutor-front.js', array( 'jquery', 'wp-i18n', 'wp-date' ), TUTOR_VERSION, true );
327 +
328 + /**
329 + * Load frontend dashboard style
330 + *
331 + * @since v1.9.8
332 + */
333 + $should_load_dashboard_styles = apply_filters( 'tutor_should_load_dashboard_styles', tutor_utils()->is_tutor_frontend_dashboard() );
334 + if ( $should_load_dashboard_styles ) {
335 + wp_enqueue_style( 'tutor-frontend-dashboard-css', tutor()->url . 'assets/css/tutor-frontend-dashboard.min.css', array(), TUTOR_VERSION );
336 + }
337 +
338 + // Load date picker for announcement at frontend.
339 + wp_enqueue_script( 'jquery-ui-datepicker' );
340 + $css = '.mce-notification.mce-notification-error{display: none !important;}';
341 + wp_add_inline_style( 'tutor-frontend', $css );
349 342 }
350 343
351 344 /**
352 345 * Modify localize data
@@ -373,11 +366,8 @@
373 366 $localize_data['coupon_main_content_locales'] = tutils()->get_script_locale_data( 'tutor-coupon-main-content', $localize_data['local'] );
374 367 }
375 368 }
376 369 } else {
377 - if ( 'en_US' !== $localize_data['local'] ) {
378 - $localize_data['calendar_locales'] = tutils()->get_script_locale_data( 'tutor-calendar', $localize_data['local'] );
379 - }
380 370
381 371 // Assign quiz option.
382 372 if ( ! empty( $post->post_type ) && 'tutor_quiz' === $post->post_type ) {
383 373 $single_quiz_options = (array) tutor_utils()->get_quiz_option( $post->ID );
@@ -414,19 +404,11 @@
414 404 /**
415 405 * Load common scripts for frontend and backend
416 406 *
417 407 * @since 1.0.0
418 - *
419 - * @since 4.0.0 Legacy scripts loading check added.
420 - *
421 - * @param string $slug The page slug.
422 - *
423 408 * @return void
424 409 */
425 - public function common_scripts( $slug ) {
426 - if ( ! self::should_load_legacy_scripts() ) {
427 - return;
428 - }
410 + public function common_scripts() {
429 411
430 412 /**
431 413 * Load TinyMCE for tutor settings page if tutor pro is not available.
432 414 *
@@ -442,9 +424,9 @@
442 424 wp_enqueue_style( 'tutor-icon', tutor()->url . 'assets/css/tutor-icon.min.css', array(), TUTOR_VERSION );
443 425
444 426 // Common css library.
445 427 if ( is_rtl() ) {
446 - wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor-rtl.min.css', array(), TUTOR_VERSION );
428 + wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.rtl.min.css', array(), TUTOR_VERSION );
447 429 } else {
448 430 wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.min.css', array(), TUTOR_VERSION );
449 431 }
450 432
@@ -534,28 +516,14 @@
534 516 'tutor_border_color' => '#E3E5EB',
535 517 'tutor_gray_color' => '#CDCFD5',
536 518 );
537 519
538 - $brand_color = tutor_utils()->get_brand_color();
539 -
540 520 $color_string = '';
541 521 foreach ( $colors as $key => $property ) {
542 522 $fallback_color = isset( $fallback_colors[ $key ] ) ? $fallback_colors[ $key ] : '#212327';
543 - $color = $fallback_color;
523 + $color = tutor_utils()->get_option( $key, $fallback_color );
524 + $color_rgb = tutor_utils()->hex2rgb( $color );
544 525
545 - if ( Options_V2::DEFAULT_BRAND_COLOR !== $brand_color ) {
546 - if ( 'tutor_primary_color' === $key ) {
547 - $color = $brand_color;
548 - }
549 -
550 - if ( 'tutor_primary_hover_color' === $key ) {
551 - $palette = $this->generate_color_palette( $brand_color );
552 - $color = $palette[700];
553 - }
554 - }
555 -
556 - $color_rgb = tutor_utils()->hex2rgb( $color );
557 -
558 526 if ( is_admin() && isset( $admin_colors[ $property ] ) ) {
559 527 $color = $admin_colors[ $property ];
560 528 $color_rgb = tutor_utils()->hex2rgb( $admin_colors[ $property ] );
561 529 }
@@ -572,85 +540,8 @@
572 540 return ':root{' . $color_string . '}';
573 541 }
574 542
575 543 /**
576 - * Generate color palette
577 - *
578 - * @since 4.0.0
579 - *
580 - * @param string $base_hex HEX color code.
581 - *
582 - * @return array
583 - */
584 - private function generate_color_palette( $base_hex ) {
585 - $base = tutor_utils()->hex_to_hsl( $base_hex );
586 -
587 - // Mapping of [Hue-Shift, Saturation-Shift, Target-Lightness].
588 - $rules = array(
589 - 100 => array( -1, 3, 97.5 ),
590 - 200 => array( -3, 1, 94.1 ),
591 - 300 => array( -3, -2, 92.2 ),
592 - 400 => array( -4, 0, 79.6 ),
593 - 450 => array( -2, -3, 76.7 ),
594 - 500 => array( -4, 5, 59.8 ),
595 - 600 => array( 0, 0, $base['l'] ),
596 - 700 => array( 3, -7, 48.0 ),
597 - 800 => array( 4, -12, 40.2 ),
598 - 900 => array( 5, -17, 33.1 ),
599 - 950 => array( 6, -24, 20.8 ),
600 - );
601 -
602 - $palette = array();
603 - foreach ( $rules as $weight => $modifier ) {
604 - if ( 600 === $weight ) {
605 - $palette[ $weight ] = strtolower( $base_hex );
606 - continue;
607 - }
608 -
609 - $new_h = fmod( ( $base['h'] + $modifier[0] + 360 ), 360 );
610 - $new_s = max( 0, min( 100, $base['s'] + $modifier[1] ) );
611 - $new_l = max( 0, min( 100, $modifier[2] ) );
612 -
613 - $palette[ $weight ] = tutor_utils()->hsl_to_hex( $new_h, $new_s, $new_l );
614 - }
615 -
616 - return $palette;
617 - }
618 -
619 - /**
620 - * Load core color palette
621 - *
622 - * @since 4.0.0
623 - *
624 - * @param string $brand_color Base color code.
625 - *
626 - * @return string
627 - */
628 - private function load_core_color_palette( $brand_color ) {
629 - if ( empty( $brand_color ) ) {
630 - return '';
631 - }
632 -
633 - $palette = $this->generate_color_palette( $brand_color );
634 -
635 - return "
636 - :root {
637 - --tutor-brand-100: {$palette[100]};
638 - --tutor-brand-200: {$palette[200]};
639 - --tutor-brand-300: {$palette[300]};
640 - --tutor-brand-400: {$palette[400]};
641 - --tutor-brand-450: {$palette[450]};
642 - --tutor-brand-500: {$palette[500]};
643 - --tutor-brand-600: {$palette[600]};
644 - --tutor-brand-700: {$palette[700]};
645 - --tutor-brand-800: {$palette[800]};
646 - --tutor-brand-900: {$palette[900]};
647 - --tutor-brand-950: {$palette[950]};
648 - }
649 - ";
650 - }
651 -
652 - /**
653 544 * Add Tinymce button for placing shortcode
654 545 *
655 546 * @since 1.0.0
656 547 * @return void|null
@@ -719,29 +610,22 @@
719 610 * Load text domain handled script after all enqueue_scripts
720 611 * registered functions
721 612 *
722 613 * @since 1.9.0
723 - * @since 3.9.2 Refactored to dynamically detect scripts instead of hardcoded list.
724 - *
725 614 * @return void
726 615 */
727 616 public function tutor_script_text_domain() {
728 - global $wp_scripts;
729 -
730 - if ( empty( $wp_scripts->registered ) ) {
731 - return;
732 - }
733 -
734 - foreach ( $wp_scripts->registered as $handle => $data ) {
735 - $src = $data->src ?? '';
736 - $is_from_tutor = str_contains( $src, 'tutor/assets/js' );
737 -
738 - if ( ! $is_from_tutor ) {
739 - continue;
740 - }
741 -
742 - wp_set_script_translations( $handle, 'tutor', tutor()->path . 'languages/' );
743 - }
617 + wp_set_script_translations( 'tutor-script', 'tutor', tutor()->path . 'languages/' );
618 + wp_set_script_translations( 'tutor-frontend', 'tutor', tutor()->path . 'languages/' );
619 + wp_set_script_translations( 'tutor-admin', 'tutor', tutor()->path . 'languages/' );
620 + wp_set_script_translations( 'tutor-gutenberg', 'tutor', tutor()->path . 'languages/' );
621 + wp_set_script_translations( 'tutor-order-details', 'tutor', tutor()->path . 'languages/' );
622 + wp_set_script_translations( 'tutor-coupon', 'tutor', tutor()->path . 'languages/' );
623 + wp_set_script_translations( 'tutor-tax-settings', 'tutor', tutor()->path . 'languages/' );
624 + wp_set_script_translations( 'tutor-payment-settings', 'tutor', tutor()->path . 'languages/' );
625 + wp_set_script_translations( 'tutor-addon-list', 'tutor', tutor()->path . 'languages/' );
626 + wp_set_script_translations( 'tutor-import-export', 'tutor', tutor()->path . 'languages/' );
627 + wp_set_script_translations( 'tutor-template-import-js', 'tutor', tutor()->path . 'languages/' );
744 628 }
745 629
746 630 /**
747 631 * Add translation support for external tinyMCE button
@@ -853,166 +737,6 @@
853 737 'const tutorInlineData =' . json_encode( $data ),
854 738 'before'
855 739 );
856 740 }
857 - }
858 -
859 - /**
860 - * Enqueue styles & scripts for latest design system
861 - *
862 - * @since 4.0.0
863 - *
864 - * @return void
865 - */
866 - public function enqueue_scripts() {
867 - if ( self::should_load_legacy_scripts() ) {
868 - return;
869 - }
870 -
871 - $is_dashboard = tutor_utils()->is_dashboard_page();
872 - $is_learning_area = tutor_utils()->is_learning_area();
873 - $is_kids_mode = tutor_utils()->is_kids_mode();
874 - $is_legacy_learning = Options_V2::LEARNING_MODE_LEGACY === tutor_utils()->get_option( 'learning_mode' );
875 -
876 - $core_css_url = tutor()->assets_url . 'css/tutor-core.min.css';
877 - $kids_css_url = tutor()->assets_url . 'css/tutor-kids.min.css';
878 - $dashboard_css_url = tutor()->assets_url . 'css/tutor-dashboard.min.css';
879 - $learning_area_css_url = tutor()->assets_url . 'css/tutor-learning-area.min.css';
880 - $google_font_url = 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap';
881 -
882 - $core_js_url = tutor()->assets_url . 'js/tutor-core.js';
883 - $dashboard_js_url = tutor()->assets_url . 'js/tutor-dashboard.js';
884 - $learning_area_js_url = tutor()->assets_url . 'js/tutor-learning-area.js';
885 -
886 - $version = TUTOR_ENV === 'DEV' ? time() : TUTOR_VERSION;
887 -
888 - $is_course_list_page = tutor_utils()->is_course_list_page();
889 - $is_course_details_page = tutor_utils()->is_course_details_page();
890 -
891 - $localize_data = apply_filters( 'tutor_localize_data', $this->get_default_localized_data() );
892 - if ( $is_kids_mode ) {
893 - $google_font_url = 'https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;500;600;700&display=swap';
894 - wp_enqueue_style( 'tutor-kids', $kids_css_url, array( 'tutor-core' ), $version );
895 - }
896 -
897 - // Core.
898 - wp_enqueue_style( 'tutor-google-fonts', $google_font_url, array(), $version );
899 -
900 - wp_enqueue_style( 'tutor-core', $core_css_url, array( 'tutor-google-fonts' ), $version );
901 - wp_enqueue_script( 'tutor-core', $core_js_url, array( 'wp-i18n' ), $version, true );
902 -
903 - wp_localize_script( 'tutor-core', '_tutorobject', $localize_data );
904 -
905 - // Generate color palette from user selected brand color and add to the root.
906 - $brand_color = tutor_utils()->get_brand_color();
907 - if ( Options_V2::DEFAULT_BRAND_COLOR !== $brand_color ) {
908 - wp_add_inline_style( 'tutor-core', $this->load_core_color_palette( $brand_color ) );
909 - }
910 -
911 - if ( $is_dashboard ) {
912 - wp_enqueue_style( 'tutor-dashboard', $dashboard_css_url, array(), $version );
913 - wp_enqueue_script( 'tutor-dashboard', $dashboard_js_url, array( 'tutor-core', 'wp-i18n' ), $version, true );
914 - }
915 -
916 - if ( $is_learning_area ) {
917 - wp_enqueue_style( 'tutor-learning', $learning_area_css_url, array(), $version );
918 - wp_enqueue_script( 'tutor-learning', $learning_area_js_url, array( 'tutor-core', 'wp-i18n' ), $version, true );
919 -
920 - if ( is_single_course( true ) ) {
921 - wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.css', array(), $version );
922 - wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.polyfilled.min.js', array( 'jquery' ), $version, true );
923 - }
924 - }
925 - }
926 -
927 - /**
928 - * Check if need to load legacy scripts
929 - *
930 - * If the current screen is dashboard or new learning area
931 - * then this method will return false to avoid loading legacy css & js files
932 - *
933 - * @since 4.0.0
934 - *
935 - * @return boolean
936 - */
937 - public static function should_load_legacy_scripts(): bool {
938 - $load = true;
939 -
940 - $post_id = get_the_ID();
941 -
942 - $is_learning_area = tutor_utils()->is_learning_area();
943 - $is_legacy_learning = tutor_utils()->is_legacy_learning_mode();
944 - $is_dashboard = tutor_utils()->is_dashboard_page();
945 -
946 - $page_ids = array(
947 - (int) tutor_utils()->get_option( 'student_register_page' ),
948 - (int) tutor_utils()->get_option( 'instructor_register_page' ),
949 - );
950 -
951 - // Ignore loading legacy scripts on specific case.
952 - if ( $is_learning_area && ! $is_legacy_learning ) {
953 - $load = false;
954 - } elseif ( $is_dashboard ) {
955 - $load = false;
956 - } elseif ( in_array( $post_id, $page_ids, true ) ) {
957 - $load = false;
958 - } else {
959 - // Ignore loading legacy scripts for these shortcodes.
960 - $has_shortcode = false;
961 -
962 - $shortcdes = array(
963 - 'tutor_student_registration_form',
964 - 'tutor_instructor_registration_form',
965 - 'tutor_dashboard',
966 - 'tutor_login',
967 - );
968 -
969 - $post_content = get_the_content();
970 -
971 - foreach ( $shortcdes as $shortcde ) {
972 - $has_shortcode = has_shortcode( $post_content, $shortcde );
973 - if ( $has_shortcode ) {
974 - $load = false;
975 - break;
976 - }
977 - }
978 - }
979 -
980 - return apply_filters( 'tutor_should_load_legacy_scripts', $load );
981 - }
982 -
983 - /**
984 - * Add custom meta data to the head section.
985 - *
986 - * Outputs a viewport meta tag to improve mobile responsiveness.
987 - *
988 - * @since 4.0.0
989 - *
990 - * @return void
991 - */
992 - public function add_custom_data() {
993 - if ( tutor_utils()->is_dashboard_page() || tutor_utils()->is_learning_area() ) {
994 - echo '<meta name="viewport" content="width=device-width, initial-scale=1" />' . "\n";
995 - }
996 - }
997 -
998 - /**
999 - * Add preload to CSS
1000 - *
1001 - * @param string $html HTML.
1002 - * @param string $handle Handle.
1003 - *
1004 - * @since 4.0.0
1005 - *
1006 - * @return string
1007 - */
1008 - public function add_preload_to_css( $html, $handle ) {
1009 - if ( 'tutor-google-fonts' === $handle ) {
1010 - $html = str_replace(
1011 - "rel='stylesheet'",
1012 - "rel='preload' as='style' onload=\"this.onload=null;this.rel='stylesheet'\"",
1013 - $html
1014 - );
1015 - }
1016 - return $html;
1017 741 }
1018 742 }