Skip to content

Commit

Permalink
Header: Enqueue wp4.css if the current theme does not provide theme…
Browse files Browse the repository at this point in the history
…-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.
  • Loading branch information
ryelle committed Jan 7, 2022
1 parent 5f408e4 commit 5cde8ec
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mu-plugins/blocks/global-header-footer/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 5cde8ec

Please sign in to comment.