-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin: Use bundled files for enqueuing global styles (#50310)
* Plugin: Use bundled files for enqueuing global styles * Override the '__experimentalFeatures' * Recreate global styles for block editors * Move global styles custom CSS handlers * Move _gutenberg_clean_theme_json_caches * Override global styles custom CSS properties
- Loading branch information
Showing
8 changed files
with
412 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* Adds settings to the block editor. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Adds styles and __experimentalFeatures to the block editor settings. | ||
* | ||
* Note: The settings that are WP version specific should be handled inside the `compat` directory. | ||
* | ||
* @param array $settings Existing block editor settings. | ||
* | ||
* @return array New block editor settings. | ||
*/ | ||
function gutenberg_get_block_editor_settings( $settings ) { | ||
// Recreate global styles. | ||
$global_styles = array(); | ||
$presets = array( | ||
array( | ||
'css' => 'variables', | ||
'__unstableType' => 'presets', | ||
'isGlobalStyles' => true, | ||
), | ||
array( | ||
'css' => 'presets', | ||
'__unstableType' => 'presets', | ||
'isGlobalStyles' => true, | ||
), | ||
); | ||
foreach ( $presets as $preset_style ) { | ||
$actual_css = gutenberg_get_global_stylesheet( array( $preset_style['css'] ) ); | ||
if ( '' !== $actual_css ) { | ||
$preset_style['css'] = $actual_css; | ||
$global_styles[] = $preset_style; | ||
} | ||
} | ||
|
||
if ( wp_theme_has_theme_json() ) { | ||
$block_classes = array( | ||
'css' => 'styles', | ||
'__unstableType' => 'theme', | ||
'isGlobalStyles' => true, | ||
); | ||
$actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); | ||
if ( '' !== $actual_css ) { | ||
$block_classes['css'] = $actual_css; | ||
$global_styles[] = $block_classes; | ||
} | ||
|
||
/* | ||
* Add the custom CSS as a separate stylesheet so any invalid CSS | ||
* entered by users does not break other global styles. | ||
*/ | ||
$global_styles[] = array( | ||
'css' => gutenberg_get_global_styles_custom_css(), | ||
'__unstableType' => 'user', | ||
'isGlobalStyles' => true, | ||
); | ||
} else { | ||
// If there is no `theme.json` file, ensure base layout styles are still available. | ||
$block_classes = array( | ||
'css' => 'base-layout-styles', | ||
'__unstableType' => 'base-layout', | ||
'isGlobalStyles' => true, | ||
); | ||
$actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); | ||
if ( '' !== $actual_css ) { | ||
$block_classes['css'] = $actual_css; | ||
$global_styles[] = $block_classes; | ||
} | ||
} | ||
|
||
$settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() ); | ||
|
||
// Copied from get_block_editor_settings() at wordpress-develop/block-editor.php. | ||
$settings['__experimentalFeatures'] = gutenberg_get_global_settings(); | ||
|
||
return $settings; | ||
} | ||
add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', PHP_INT_MAX ); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.