stylesheet handles to layer, and * whether to add the neutral button layer. */ const THEMES = [ 'hello-elementor' => [ 'handles' => [ 'hello-elementor', 'hello-elementor-theme-style' ], 'neutral' => true, ], 'blocksy' => [ // Only the base bundle; the dynamic colour variables and header/ // page-title CSS are separate handles and stay as they are. 'handles' => [ 'ct-main-styles' ], 'neutral' => false, ], ]; /** * Academy frontend stylesheets; one of them being enqueued marks an * Academy page (course/archive, learn page, dashboard, registration, * shortcode/block pages). */ const ACADEMY_HANDLES = [ 'academy-common-styles', 'academy-course-lessons-styles', 'academy-course-php-render-lessons-styles', 'academy-frontend-dashboard-styles', 'academy-dashboard-style', 'academy-learn-page-style', ]; public static function init() { if ( ! isset( self::THEMES[ get_template() ] ) ) { return; } // After the theme (10) and Academy (10, or ACADEMY_FRONTEND_SCRIPTS_PRIORITY; // the learn page adjusts theme assets at 100) have enqueued. add_action( 'wp_enqueue_scripts', [ __CLASS__, 'layer_theme_css' ], 110 ); } /** * Swap the theme's stylesheets for an inline `@import … layer()` on the * first handle; the rest become inline-only (empty) handles. * * @return void */ public static function layer_theme_css() { $template = get_template(); if ( ! apply_filters( 'academy/integration/theme_compat/layer_theme_css', self::is_academy_page(), $template ) ) { return; } $config = self::THEMES[ $template ]; $styles = wp_styles(); $imports = []; $host = ''; foreach ( $config['handles'] as $handle ) { if ( ! wp_style_is( $handle, 'enqueued' ) || empty( $styles->registered[ $handle ]->src ) ) { continue; } $style = $styles->registered[ $handle ]; $url = $style->src; // Mirror WP's `rtl => 'replace'` handling for the theme's RTL files. if ( is_rtl() && ! empty( $style->extra['rtl'] ) ) { $url = 'replace' === $style->extra['rtl'] ? str_replace( '.css', '-rtl.css', $url ) : $style->extra['rtl']; } if ( $style->ver ) { $url = add_query_arg( 'ver', $style->ver, $url ); } $imports[] = sprintf( '@import url("%s") layer(%s);', esc_url( $url ), self::LAYER_THEME ); // Inline-only handle: WP prints just the inline