block-supports
2 years ago
compat
2 years ago
experimental
2 years ago
README.md
2 years ago
block-editor-settings.php
2 years ago
blocks.php
2 years ago
class-wp-duotone-gutenberg.php
2 years ago
class-wp-theme-json-data-gutenberg.php
2 years ago
class-wp-theme-json-gutenberg.php
2 years ago
class-wp-theme-json-resolver-gutenberg.php
2 years ago
client-assets.php
2 years ago
demo.php
2 years ago
experiments-page.php
2 years ago
global-styles-and-settings.php
2 years ago
init.php
2 years ago
load.php
2 years ago
script-loader.php
2 years ago
theme-i18n.json
2 years ago
theme.json
2 years ago
upgrade.php
2 years ago
block-editor-settings.php
83 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Adds settings to the block editor. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Adds styles and __experimentalFeatures to the block editor settings. |
| 10 | * |
| 11 | * Note: The settings that are WP version specific should be handled inside the `compat` directory. |
| 12 | * |
| 13 | * @param array $settings Existing block editor settings. |
| 14 | * |
| 15 | * @return array New block editor settings. |
| 16 | */ |
| 17 | function gutenberg_get_block_editor_settings( $settings ) { |
| 18 | // Recreate global styles. |
| 19 | $global_styles = array(); |
| 20 | $presets = array( |
| 21 | array( |
| 22 | 'css' => 'variables', |
| 23 | '__unstableType' => 'presets', |
| 24 | 'isGlobalStyles' => true, |
| 25 | ), |
| 26 | array( |
| 27 | 'css' => 'presets', |
| 28 | '__unstableType' => 'presets', |
| 29 | 'isGlobalStyles' => true, |
| 30 | ), |
| 31 | ); |
| 32 | foreach ( $presets as $preset_style ) { |
| 33 | $actual_css = gutenberg_get_global_stylesheet( array( $preset_style['css'] ) ); |
| 34 | if ( '' !== $actual_css ) { |
| 35 | $preset_style['css'] = $actual_css; |
| 36 | $global_styles[] = $preset_style; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if ( wp_theme_has_theme_json() ) { |
| 41 | $block_classes = array( |
| 42 | 'css' => 'styles', |
| 43 | '__unstableType' => 'theme', |
| 44 | 'isGlobalStyles' => true, |
| 45 | ); |
| 46 | $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); |
| 47 | if ( '' !== $actual_css ) { |
| 48 | $block_classes['css'] = $actual_css; |
| 49 | $global_styles[] = $block_classes; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Add the custom CSS as a separate stylesheet so any invalid CSS |
| 54 | * entered by users does not break other global styles. |
| 55 | */ |
| 56 | $global_styles[] = array( |
| 57 | 'css' => gutenberg_get_global_styles_custom_css(), |
| 58 | '__unstableType' => 'user', |
| 59 | 'isGlobalStyles' => true, |
| 60 | ); |
| 61 | } else { |
| 62 | // If there is no `theme.json` file, ensure base layout styles are still available. |
| 63 | $block_classes = array( |
| 64 | 'css' => 'base-layout-styles', |
| 65 | '__unstableType' => 'base-layout', |
| 66 | 'isGlobalStyles' => true, |
| 67 | ); |
| 68 | $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); |
| 69 | if ( '' !== $actual_css ) { |
| 70 | $block_classes['css'] = $actual_css; |
| 71 | $global_styles[] = $block_classes; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | $settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() ); |
| 76 | |
| 77 | // Copied from get_block_editor_settings() at wordpress-develop/block-editor.php. |
| 78 | $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); |
| 79 | |
| 80 | return $settings; |
| 81 | } |
| 82 | add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', PHP_INT_MAX ); |
| 83 |