@@ -255,90 +255,92 @@ function llms_get_template_override_directories() {
255255}
256256
257257/**
258- * Determine if Focus Mode is enabled for a specific lesson.
258+ * Determine if Focus Mode is enabled for a specific post (lesson, quiz, or other post types via filter).
259+ *
260+ * For lessons and quizzes, uses the parent course focus mode setting (or global setting).
261+ * Add-ons (e.g. LifterLMS Assignments) can use the filter to enable focus mode for their post types.
259262 *
260263 * @since [version]
261264 *
262- * @param int $lesson_id The ID of the lesson.
265+ * @param int $post_id The ID of the post ( lesson, quiz, etc.) .
263266 * @return bool
264267 */
265- function llms_is_focus_mode_enabled ( $ lesson_id ) {
266- $ lesson = llms_get_post ( $ lesson_id );
267- if ( ! $ lesson || ' lesson ' !== $ lesson -> get ( ' type ' ) ) {
268+ function llms_is_focus_mode_enabled ( $ post_id ) {
269+ $ post = llms_get_post ( $ post_id );
270+ if ( ! $ post ) {
268271 return false ;
269272 }
270273
271- $ course_id = $ lesson ->get ( 'parent_course ' );
272- if ( ! $ course_id ) {
273- return false ;
274- }
274+ $ result = false ;
275+ $ type = $ post ->get ( 'type ' );
275276
276- $ course = llms_get_post ( $ course_id );
277- if ( ! $ course ) {
278- return false ;
279- }
277+ if ( 'lesson ' === $ type || 'llms_quiz ' === $ type ) {
278+ $ course = llms_get_post_parent_course ( $ post_id );
279+ if ( ! $ course ) {
280+ return apply_filters ( 'llms_is_focus_mode_enabled ' , false , $ post_id );
281+ }
280282
281- $ course_focus_mode = $ course ->get ( 'focus_mode ' );
282-
283- if ( 'enable ' === $ course_focus_mode ) {
284- return true ;
285- } elseif ( 'disable ' === $ course_focus_mode ) {
286- return false ;
283+ $ course_focus_mode = $ course ->get ( 'focus_mode ' );
284+ if ( 'enable ' === $ course_focus_mode ) {
285+ $ result = true ;
286+ } elseif ( 'disable ' === $ course_focus_mode ) {
287+ $ result = false ;
288+ } else {
289+ $ result = 'yes ' === get_option ( 'lifterlms_enable_focus_mode ' , 'no ' );
290+ }
287291 }
288292
289- // Fallback to global setting.
290- return 'yes ' === get_option ( 'lifterlms_enable_focus_mode ' , 'no ' );
293+ /**
294+ * Filters whether focus mode is enabled for a given post.
295+ *
296+ * Used by add-ons (e.g. LifterLMS Assignments) to enable focus mode for their post types
297+ * when focus mode is enabled globally and/or for the course.
298+ *
299+ * @since [version]
300+ *
301+ * @param bool $result Whether focus mode is enabled.
302+ * @param int $post_id The post ID.
303+ */
304+ return apply_filters ( 'llms_is_focus_mode_enabled ' , $ result , $ post_id );
291305}
292306
293307/**
294- * Retrieve the effective focus mode content width for a lesson .
308+ * Retrieve the effective focus mode content width for a post .
295309 *
296- * Checks the course-level setting first, then falls back to global.
310+ * Checks the parent course setting first (for lesson/quiz) , then falls back to global.
297311 *
298312 * @since [version]
299313 *
300- * @param int $lesson_id The ID of the lesson.
314+ * @param int $post_id The ID of the post ( lesson, quiz, or other focus-mode post type) .
301315 * @return string Width value: 'full', '1600', '1180', '960', or '768'.
302316 */
303- function llms_get_focus_mode_content_width ( $ lesson_id ) {
304- $ lesson = llms_get_post ( $ lesson_id );
305- if ( $ lesson && 'lesson ' === $ lesson ->get ( 'type ' ) ) {
306- $ course_id = $ lesson ->get ( 'parent_course ' );
307- if ( $ course_id ) {
308- $ course = llms_get_post ( $ course_id );
309- if ( $ course ) {
310- $ value = $ course ->get ( 'focus_mode_content_width ' );
311- if ( $ value && 'inherit ' !== $ value ) {
312- return $ value ;
313- }
314- }
317+ function llms_get_focus_mode_content_width ( $ post_id ) {
318+ $ course = llms_get_post_parent_course ( $ post_id );
319+ if ( $ course ) {
320+ $ value = $ course ->get ( 'focus_mode_content_width ' );
321+ if ( $ value && 'inherit ' !== $ value ) {
322+ return $ value ;
315323 }
316324 }
317325 return get_option ( 'lifterlms_focus_mode_content_width ' , '960 ' );
318326}
319327
320328/**
321- * Retrieve the effective focus mode sidebar position for a lesson .
329+ * Retrieve the effective focus mode sidebar position for a post .
322330 *
323- * Checks the course-level setting first, then falls back to global.
331+ * Checks the parent course setting first (for lesson/quiz) , then falls back to global.
324332 *
325333 * @since [version]
326334 *
327- * @param int $lesson_id The ID of the lesson.
335+ * @param int $post_id The ID of the post ( lesson, quiz, or other focus-mode post type) .
328336 * @return string 'left' or 'right'.
329337 */
330- function llms_get_focus_mode_sidebar_position ( $ lesson_id ) {
331- $ lesson = llms_get_post ( $ lesson_id );
332- if ( $ lesson && 'lesson ' === $ lesson ->get ( 'type ' ) ) {
333- $ course_id = $ lesson ->get ( 'parent_course ' );
334- if ( $ course_id ) {
335- $ course = llms_get_post ( $ course_id );
336- if ( $ course ) {
337- $ value = $ course ->get ( 'focus_mode_sidebar_position ' );
338- if ( $ value && 'inherit ' !== $ value ) {
339- return $ value ;
340- }
341- }
338+ function llms_get_focus_mode_sidebar_position ( $ post_id ) {
339+ $ course = llms_get_post_parent_course ( $ post_id );
340+ if ( $ course ) {
341+ $ value = $ course ->get ( 'focus_mode_sidebar_position ' );
342+ if ( $ value && 'inherit ' !== $ value ) {
343+ return $ value ;
342344 }
343345 }
344346 return get_option ( 'lifterlms_focus_mode_sidebar_position ' , 'left ' );
@@ -389,7 +391,18 @@ function llms_lesson_uses_page_builder( $lesson_id ) {
389391 * @return array
390392 */
391393function llms_focus_mode_body_class ( $ classes ) {
392- if ( is_lesson () && llms_is_focus_mode_enabled ( get_the_ID () ) ) {
394+ /**
395+ * Post types that can use the focus mode template when focus mode is enabled.
396+ *
397+ * Add-ons (e.g. LifterLMS Assignments) can add their post types here and use
398+ * the `llms_is_focus_mode_enabled` filter to return true when appropriate.
399+ *
400+ * @since [version]
401+ *
402+ * @param string[] $post_types Post type names. Default: [ 'lesson', 'llms_quiz' ].
403+ */
404+ $ focus_mode_post_types = apply_filters ( 'llms_focus_mode_post_types ' , array ( 'lesson ' , 'llms_quiz ' ) );
405+ if ( is_singular ( $ focus_mode_post_types ) && llms_is_focus_mode_enabled ( get_the_ID () ) ) {
393406 $ classes [] = 'llms-focus-mode ' ;
394407
395408 $ width = llms_get_focus_mode_content_width ( get_the_ID () );
@@ -412,7 +425,8 @@ function llms_focus_mode_body_class( $classes ) {
412425 * @return void
413426 */
414427function llms_focus_mode_enqueue_scripts () {
415- if ( is_lesson () && llms_is_focus_mode_enabled ( get_the_ID () ) ) {
428+ $ focus_mode_post_types = apply_filters ( 'llms_focus_mode_post_types ' , array ( 'lesson ' , 'llms_quiz ' ) );
429+ if ( is_singular ( $ focus_mode_post_types ) && llms_is_focus_mode_enabled ( get_the_ID () ) ) {
416430 $ suffix = defined ( 'SCRIPT_DEBUG ' ) && SCRIPT_DEBUG ? '' : '.min ' ;
417431
418432 wp_enqueue_style (
0 commit comments