From 5cde8ecadd5bfb9a53b1c3cc5e2b7ef6f5c52132 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Fri, 7 Jan 2022 14:22:39 -0500 Subject: [PATCH] Header: Enqueue `wp4.css` if the current theme does not provide theme-support. This mirrors the behavior of the classic header.php, which loads Open Sans and wp4.css if the current site/theme does not provide those styles itself. Fixes #60. --- .../blocks/global-header-footer/blocks.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mu-plugins/blocks/global-header-footer/blocks.php b/mu-plugins/blocks/global-header-footer/blocks.php index 0fc84a9ab..e1e4a5149 100644 --- a/mu-plugins/blocks/global-header-footer/blocks.php +++ b/mu-plugins/blocks/global-header-footer/blocks.php @@ -9,6 +9,7 @@ add_action( 'enqueue_block_assets', __NAMESPACE__ . '\register_block_types_js' ); add_filter( 'pre_set_transient_global_styles_wporg-news-2021', __NAMESPACE__ . '\save_dependent_global_styles' ); add_action( 'rest_api_init', __NAMESPACE__ . '\register_routes' ); +add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_compat_wp4_styles' ); /** * Register block types @@ -127,6 +128,24 @@ function ( $block ) { wp_add_inline_script( 'wp-editor', ob_get_clean(), 'after' ); } +/** + * Output styles for themes that don't use `wp4-styles`. This provides compat with the classic header.php. + */ +function enqueue_compat_wp4_styles() { + if ( ! current_theme_supports( 'wp4-styles' ) ) { + $cdn_domain = defined( 'WPORG_SANDBOXED' ) && WPORG_SANDBOXED ? 'wordpress.org' : 's.w.org'; + $suffix = 'rtl' === $text_direction ? '-rtl' : ''; + wp_register_style( + 'wp4-styles', + 'https://' . $cdn_domain . '/style/wp4' . $suffix . '.css', + array( 'open-sans' ), + '95' + ); + + wp_enqueue_style( 'wp4-styles' ); + } +} + /** * Remove the wrapping element to preserve markup. *