Skip to content

Commit

Permalink
Tweaks to accommodate latest changes in core (#31702)
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath authored May 11, 2021
1 parent cb9fd48 commit caa1787
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function gutenberg_register_core_block_styles( $block_name ) {
$editor_style_path = "build/block-library/blocks/$block_name/style-editor.css";

if ( file_exists( gutenberg_dir_path() . $style_path ) ) {
wp_deregister_style( "wp-block-{$block_name}" );
wp_register_style(
"wp-block-{$block_name}",
gutenberg_url( $style_path ),
Expand All @@ -183,6 +184,7 @@ function gutenberg_register_core_block_styles( $block_name ) {
}

if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) {
wp_deregister_style( "wp-block-{$block_name}-editor" );
wp_register_style(
"wp-block-{$block_name}-editor",
gutenberg_url( $editor_style_path ),
Expand All @@ -198,10 +200,17 @@ function gutenberg_register_core_block_styles( $block_name ) {
*
* Optimizes performance and sustainability of styles by inlining smaller stylesheets.
*
* @todo Remove this function when the minimum supported version is WordPress 5.8.
*
* @return void
*/
function gutenberg_maybe_inline_styles() {

// Early exit if the "wp_maybe_inline_styles" function exists.
if ( function_exists( 'wp_maybe_inline_styles' ) ) {
return;
}

$total_inline_limit = 20000;
/**
* The maximum size of inlined styles in bytes.
Expand Down
29 changes: 28 additions & 1 deletion lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@
/**
* Determine if the current theme needs to load separate block styles or not.
*
* @todo Remove this function when the minimum supported version is WordPress 5.8.
*
* @return bool
*/
function gutenberg_should_load_separate_block_assets() {
$load_separate_styles = gutenberg_is_fse_theme();
if ( function_exists( 'should_load_separate_core_block_assets' ) ) {
return should_load_separate_core_block_assets();
}

if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
return false;
}

// The `separate_core_block_assets` filter was added in WP 5.8.
$load_separate_styles = apply_filters( 'separate_core_block_assets', gutenberg_is_fse_theme() );

/**
* Determine if separate styles will be loaded for blocks on-render or not.
*
Expand All @@ -25,6 +37,21 @@ function gutenberg_should_load_separate_block_assets() {
return apply_filters( 'load_separate_block_assets', $load_separate_styles );
}

/**
* Opt-in to separate styles loading for block themes in WordPress 5.8.
*
* @todo Remove this function when the minimum supported version is WordPress 5.8.
*/
add_filter(
'separate_core_block_assets',
function( $load_separate_styles ) {
if ( function_exists( 'gutenberg_is_fse_theme' ) && gutenberg_is_fse_theme() ) {
return true;
}
return $load_separate_styles;
}
);

/**
* Remove the `wp_enqueue_registered_block_scripts_and_styles` hook if needed.
*
Expand Down

0 comments on commit caa1787

Please sign in to comment.