Skip to content

Enhancement: Block themes inherit their own Learning Mode styles - #8083

Open
faisalahammad wants to merge 3 commits into
Automattic:trunkfrom
faisalahammad:enhancement/7449-block-theme-lm-styles
Open

Enhancement: Block themes inherit their own Learning Mode styles#8083
faisalahammad wants to merge 3 commits into
Automattic:trunkfrom
faisalahammad:enhancement/7449-block-theme-lm-styles

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Learning Mode loads learning-mode-compat.css to force its own fonts, type scale, and colors so it looks consistent across all themes. On block themes that overrides the active theme's theme.json, which is not what we want. This skips that stylesheet on block themes (and on themes that already declare sensei-learning-mode support) so they inherit their own styles. Classic themes (Divi, Astra, and others) keep the compatibility styles as before.

Closes #7449

Changes

Learning Mode style loading

Before:

// includes/course-theme/class-sensei-course-theme.php
if ( ! current_theme_supports( 'sensei-learning-mode' ) ) {
    Sensei()->assets->enqueue( self::THEME_NAME . 'compatibility-style', $compat_css_file );
}

// includes/blocks/class-sensei-blocks.php
if ( ! current_theme_supports( 'sensei-learning-mode' ) ) {
    Sensei()->assets->register( 'sensei-learning-mode', 'css/learning-mode.css', [ 'sensei-theme-blocks', 'sensei-learning-mode-compat' ] );
} else {
    Sensei()->assets->register( 'sensei-learning-mode', 'css/learning-mode.css', [ 'sensei-theme-blocks' ] );
}

After:

// includes/course-theme/class-sensei-course-theme.php
if ( Sensei_Course_Theme_Option::should_load_learning_mode_compat() ) {
    Sensei()->assets->enqueue( self::THEME_NAME . 'compatibility-style', $compat_css_file );
}

// includes/blocks/class-sensei-blocks.php
if ( Sensei_Course_Theme_Option::should_load_learning_mode_compat() ) {
    Sensei()->assets->register( 'sensei-learning-mode', 'css/learning-mode.css', [ 'sensei-theme-blocks', 'sensei-learning-mode-compat' ] );
} else {
    Sensei()->assets->register( 'sensei-learning-mode', 'css/learning-mode.css', [ 'sensei-theme-blocks' ] );
}

New helper in includes/course-theme/class-sensei-course-theme-option.php:

public static function should_load_learning_mode_compat() {
    if ( current_theme_supports( 'sensei-learning-mode' ) ) {
        return false;
    }

    if ( Sensei_Utils::is_fse_theme() ) {
        return false;
    }

    return true;
}

Why: Sensei_Utils::is_fse_theme() wraps wp_is_block_theme(). Block themes already ship their own theme.json styles, so the compatibility overrides are only needed for classic themes.

Testing

Test 1: block theme inherits its own styles

  1. Activate a block theme (e.g. Twenty Twenty-Four).
  2. Open a lesson in Learning Mode on the frontend.
  3. Check the page source / DevTools Network tab.
    Result: learning-mode-compat.css is not loaded. Typography and colors follow the active theme.

Test 2: classic theme still gets compatibility styles

  1. Activate a classic theme (e.g. Astra).
  2. Open the same Learning Mode lesson.
    Result: learning-mode-compat.css is loaded and Learning Mode looks the same as before.

Test 3: automated

  1. Run make test-php-filter FILTER="Sensei_Course_Theme_Option_Test".
    Result: all tests pass, including the three new tests covering the helper (classic + no support loads, support declared skips, block theme skips).

Notes

This is a visual change for existing block-theme sites: Learning Mode will start matching the theme's design instead of Sensei's default. That is the behavior requested in the issue.

Per the issue's own consideration, this applies to all installs. If a site needs the old behavior, its theme can avoid the change by staying a classic theme.

Block themes were forced to load learning-mode-compat.css, which overrides
their fonts, type scale, and colors so Learning Mode looks the same
everywhere. Skip that stylesheet for block themes so they inherit their own
styles from theme.json. Classic themes (Divi, Astra, and others) keep the
compatibility styles. Themes declaring sensei-learning-mode support are still
skipped as before.

Fixes Automattic#7449
Use Sensei_File_System_Helper trait methods instead of mkdir, unlink and
rmdir to satisfy the WordPress filesystem alternatives PHPCS rules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block themes should inherit their own styles in Learning Mode

1 participant