Skip to content

Commit

Permalink
Buttons: Add specificity for the editor (#44731)
Browse files Browse the repository at this point in the history
* Button elements: Add specificity for the editor

* only output on classic themes

* lint fixes

* add docblock

* return the editor settings on a block theme
  • Loading branch information
scruffian authored and ockham committed Oct 10, 2022
1 parent 9d79474 commit e2f4b7e
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lib/compat/wordpress-6.1/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function gutenberg_enqueue_global_styles() {
add_action( 'wp_footer', 'gutenberg_enqueue_stored_styles', 1 );

/**
* Loads classic theme styles on classic themes.
* Loads classic theme styles on classic themes in the frontend.
*
* This is needed for backwards compatibility for button blocks specifically.
*/
Expand All @@ -192,7 +192,35 @@ function gutenberg_enqueue_classic_theme_styles() {
wp_enqueue_style( 'classic-theme-styles' );
}
}
// To load classic theme styles on the frontend.
add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_classic_theme_styles' );
// To load classic theme styles in the the editor.
add_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_classic_theme_styles' );

/**
* Loads classic theme styles on classic themes in the editor.
*
* This is needed for backwards compatibility for button blocks specifically.
*
* @since 6.1
*
* @param array $editor_settings The array of editor settings.
* @return array A filtered array of editor settings.
*/
function gutenberg_add_editor_classic_theme_styles( $editor_settings ) {
if ( wp_is_block_theme() ) {
return $editor_settings;
}

$classic_theme_styles = gutenberg_dir_path() . '/build/block-library/classic.css';

// This follows the pattern of get_block_editor_theme_styles,
// but we can't use get_block_editor_theme_styles directly as it
// only handles external files or theme files.
$editor_settings['styles'][] = array(
'css' => file_get_contents( $classic_theme_styles ),
'baseURL' => get_theme_file_uri( $classic_theme_styles ),
'__unstableType' => 'theme',
'isGlobalStyles' => false,
);

return $editor_settings;
}
add_filter( 'block_editor_settings_all', 'gutenberg_add_editor_classic_theme_styles' );

0 comments on commit e2f4b7e

Please sign in to comment.