Browse Source

Add course theme single lesson template (#7265)

* Add single lesson template

* Add single lesson template in theme.json

* Change template name from Single Lesson to Lesson

* Remove single-lesson template from lesson dropdown

* Move template removing hook to separate function

* Add doc block on filter function
Imran Hossain 1 year ago
parent
commit
fb4fabd270
3 changed files with 68 additions and 2 deletions
  1. 36 2
      course/functions.php
  2. 25 0
      course/templates/single-lesson.html
  3. 7 0
      course/theme.json

+ 36 - 2
course/functions.php

@@ -49,8 +49,8 @@ if ( ! function_exists( 'course_scripts' ) ) :
 		 * 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  ) {
+
+		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' );
 		}
@@ -85,3 +85,37 @@ function course_register_block_patterns_category() {
 
 add_action( 'init', 'course_register_block_patterns_category' );
 
+add_filter(
+	'theme_lesson_templates',
+	'course_theme_filter_single_lesson_template_for_sensei_learning_mode',
+	11,
+	3
+);
+
+/**
+ * Filter the list of templates for the single lesson page.
+ *
+ * @param array   $page_templates Array of page templates.
+ * @param string  $theme          The current theme.
+ * @param WP_Post $post           The post being edited, provided for context, or null.
+ *
+ * @since Course 1.3.1
+ *
+ * @return array Array of page templates.
+ */
+function course_theme_filter_single_lesson_template_for_sensei_learning_mode( $page_templates, $theme, $post ) {
+	// In case some other plugin has a post type called lesson.
+	if ( ! $post || ! class_exists( 'Sensei_Main' ) ) {
+		return $page_templates;
+	}
+
+	$course_id                = Sensei()->lesson->get_course_id( $post->ID );
+	$is_learning_mode_enabled = Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id );
+
+	if ( $is_learning_mode_enabled ) {
+		unset( $page_templates['single-lesson'] );
+	}
+
+	return $page_templates;
+}
+

+ 25 - 0
course/templates/single-lesson.html

@@ -0,0 +1,25 @@
+<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
+
+<!-- wp:group {"tagName":"main","style":{"spacing":{"margin":{"bottom":"80px"}}},"layout":{"type":"constrained","contentSize":"1000px"}} -->
+<main class="wp-block-group" style="margin-bottom:80px">
+    <!-- wp:group {"layout":{"inherit":true,"type":"constrained","contentSize":"1000px"}} -->
+    <div class="wp-block-group">
+        <!-- wp:post-title {"level":1,"align":"wide","style":{"spacing":{"margin":{"bottom":"2.5rem"}}}} /-->
+    </div>
+    <!-- /wp:group -->
+
+    <!-- wp:post-content {"layout":{"inherit":true,"contentSize":"1000px"}} /-->
+
+    <!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
+    <div class="wp-block-group">
+        <!-- wp:group {"layout":{"type":"constrained"}} -->
+        <div class="wp-block-group">
+            <!-- wp:pattern {"slug":"course/comments"} /-->
+        </div>
+        <!-- /wp:group -->
+    </div>
+    <!-- /wp:group -->
+</main>
+<!-- /wp:group -->
+
+<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->

+ 7 - 0
course/theme.json

@@ -82,6 +82,13 @@
 				"post",
 				"course"
 			]
+		},
+		{
+			"name": "single-lesson",
+			"title": "Lesson",
+			"postTypes": [
+				"lesson"
+			]
 		}
 	],
 	"settings": {