Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Custom Colors: Fix block editor CSS not applying in Gutenberg 22.6.0+ iframe context.
28 changes: 27 additions & 1 deletion projects/plugins/wpcomsh/custom-colors/colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static function init() {
// If colors are set, print them in the Block Editor as well.
if ( self::theme_has_set_colors() ) {
self::override_themecolors();
add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'print_theme_css' ), 20 );
add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'print_block_editor_css' ), 20 );
}
}
}
Expand Down Expand Up @@ -1461,6 +1461,32 @@ public static function print_theme_css() {
);
}

/**
* Enqueue theme CSS for the block editor.
*
* @since $$next-version$$
*/
public static function print_block_editor_css() {
if ( ! self::should_enable_colors() ) {
return;
}
$css = self::get_theme_css();

// Gutenberg 22.6.0+ renders the editor in an iframe for all themes.
// #editor no longer exists inside the iframe, so extend any
// "#editor .editor-styles-wrapper" selector to also match the
// iframe context while keeping the original for older versions.
$css = str_replace(
'#editor .editor-styles-wrapper',
'#editor .editor-styles-wrapper, :root :where(.editor-styles-wrapper)',
$css
);

wp_register_style( 'custom-colors-editor-css', false, array(), '20210311' ); // Register an empty stylesheet to append custom CSS to.
wp_enqueue_style( 'custom-colors-editor-css' );
wp_add_inline_style( 'custom-colors-editor-css', $css ); // Append inline style to our new stylesheet
}

/**
* Return theme CSS.
*/
Expand Down
Loading