瀏覽代碼

Course: Skip the learning mode style when sensei is not available (#7031)

* Skip the learning mode style when sensei is not available
Gabriel Caires 2 年之前
父節點
當前提交
e342cf066c
共有 2 個文件被更改,包括 19 次插入27 次删除
  1. 14 27
      course/functions.php
  2. 5 0
      course/learning-mode.css

+ 14 - 27
course/functions.php

@@ -20,7 +20,6 @@ if ( ! function_exists( 'course_support' ) ) :
 	 * @return void
 	 */
 	function course_support() {
-
 		add_theme_support( 'sensei-learning-mode' );
 
 		// Enqueue editor styles.
@@ -32,7 +31,7 @@ endif;
 
 add_action( 'after_setup_theme', 'course_support' );
 
-if (!function_exists( 'course_scripts' )) :
+if ( ! function_exists( 'course_scripts' ) ) :
 
 	/**
 	 * Enqueue scripts and styles.
@@ -42,33 +41,22 @@ if (!function_exists( 'course_scripts' )) :
 	 * @return void
 	 */
 	function course_scripts() {
-
-		// Register theme stylesheet.
-		wp_register_style(
-			'course-style',
-			get_stylesheet_directory_uri() . '/style.css',
-			array(),
-			wp_get_theme()->get( 'Version' )
-		);
-
-		wp_register_style(
-			'course-sensei-learning-mode',
-			get_stylesheet_directory_uri() . '/learning-mode.css',
-			array(),
-			wp_get_theme()->get(
-				'Version'
-			)
-		);
-
-		// Enqueue theme stylesheet.
+		wp_register_style( 'course-style', get_stylesheet_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
+		wp_enqueue_script( 'course-header', get_template_directory_uri() . '/assets/js/header.js', [], wp_get_theme()->get( 'Version' ), true );
 		wp_enqueue_style( 'course-style' );
 
-		// TODO: Only Load it if the the page is using learning mode
-		wp_enqueue_style( 'course-sensei-learning-mode' );
+		/**
+		 * Temporary Hook to skip the learning mode style when the Sensei LMS is able to provide it.
+		 * It is only used to continue loading the deprecated styles if a old sensei version is installed.
+		 */
+		$use_deprecated_style = apply_filters( 'course_learning_mode_load_styles', true );
+		
+		if ( class_exists( 'Sensei_Main' ) && $use_deprecated_style  ) {
+			wp_register_style( 'course-sensei-learning-mode', get_stylesheet_directory_uri() . '/learning-mode.css', array(), wp_get_theme()->get( 'Version' ) );
+			wp_enqueue_style( 'course-sensei-learning-mode' );
+		}
 
-		// Enqueque theme scripts.
-        wp_enqueue_script( 'course-header', get_template_directory_uri() . '/assets/js/header.js', [], wp_get_theme()->get( 'Version' ), true );
-    }
+	}
 
 endif;
 
@@ -99,7 +87,6 @@ function course_register_block_patterns_category() {
 }
 
 add_action( 'init', 'course_register_block_patterns_category' );
-
 /**
  * Determine the theme variation and save in option.
  *

+ 5 - 0
course/learning-mode.css

@@ -1,3 +1,8 @@
+/** 
+### DEPRECATED FILE ### 
+Please don't update it, this file will be moved to the Sensei plugin to better Maintainability. 
+
+**/
 :root, .sensei-course-theme {
 	--sensei-lm-header-height: 116px;
 }