lib
block-supports
4 months ago
compat
3 months ago
experimental
3 months ago
media
3 months ago
README.md
10.0 KB
7 months ago
block-editor-settings.php
5.4 KB
7 months ago
block-template-utils.php
3.5 KB
1 year ago
blocks.php
11.8 KB
7 months ago
class-wp-duotone-gutenberg.php
37.6 KB
5 months ago
class-wp-icons-registry-gutenberg.php
7.1 KB
4 months ago
class-wp-rest-edit-site-export-controller-gutenberg.php
1.2 KB
2 years ago
class-wp-rest-global-styles-controller-gutenberg.php
24.5 KB
7 months ago
class-wp-rest-icons-controller-gutenberg.php
481 B
4 months ago
class-wp-theme-json-data-gutenberg.php
1.7 KB
2 years ago
class-wp-theme-json-gutenberg.php
196.1 KB
3 months ago
class-wp-theme-json-resolver-gutenberg.php
34.7 KB
6 months ago
class-wp-theme-json-schema-gutenberg.php
7.4 KB
7 months ago
client-assets.php
16.4 KB
4 months ago
demo.php
1.6 KB
1 year ago
global-styles-and-settings.php
14.2 KB
7 months ago
init.php
945 B
4 months ago
interactivity-api.php
1.2 KB
7 months ago
load.php
10.9 KB
3 months ago
mathml-kses.php
6.3 KB
10 months ago
overlay-patterns.php
12.2 KB
6 months ago
remove-core-enqueue-scripts.php
779 B
5 months ago
rest-api.php
1.6 KB
4 months ago
script-loader.php
5.9 KB
5 months ago
theme-i18n.json
1.8 KB
7 months ago
theme.json
9.2 KB
5 months ago
upgrade.php
2.6 KB
5 months ago
block-editor-settings.php in Gutenberg 23.2.0, at lib/block-editor-settings.php
| 1 | <?php |
| 2 | /** |
| 3 | * Adds settings to the block editor. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Replaces core 'styles' and '__experimentalFeatures' block editor settings from |
| 10 | * wordpress-develop/block-editor.php with the Gutenberg versions. Much of the |
| 11 | * code is copied from get_block_editor_settings() in that file. |
| 12 | * |
| 13 | * This hook should run first as it completely replaces the core settings that |
| 14 | * other hooks may need to update. |
| 15 | * |
| 16 | * Note: The settings that are WP version specific should be handled inside the `compat` directory. |
| 17 | * |
| 18 | * @param array $settings Existing block editor settings. |
| 19 | * |
| 20 | * @return array New block editor settings. |
| 21 | */ |
| 22 | function gutenberg_get_block_editor_settings( $settings ) { |
| 23 | $global_styles = array(); |
| 24 | $presets = array( |
| 25 | array( |
| 26 | 'css' => 'variables', |
| 27 | '__unstableType' => 'presets', |
| 28 | 'isGlobalStyles' => true, |
| 29 | ), |
| 30 | array( |
| 31 | 'css' => 'presets', |
| 32 | '__unstableType' => 'presets', |
| 33 | 'isGlobalStyles' => true, |
| 34 | ), |
| 35 | ); |
| 36 | foreach ( $presets as $preset_style ) { |
| 37 | $actual_css = gutenberg_get_global_stylesheet( array( $preset_style['css'] ) ); |
| 38 | if ( '' !== $actual_css ) { |
| 39 | $preset_style['css'] = $actual_css; |
| 40 | $global_styles[] = $preset_style; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | $block_classes = array( |
| 45 | 'css' => 'styles', |
| 46 | '__unstableType' => 'theme', |
| 47 | 'isGlobalStyles' => true, |
| 48 | ); |
| 49 | $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) ); |
| 50 | if ( '' !== $actual_css ) { |
| 51 | $block_classes['css'] = $actual_css; |
| 52 | $global_styles[] = $block_classes; |
| 53 | } |
| 54 | |
| 55 | // Get any additional css from the customizer and add it before global styles custom CSS. |
| 56 | $global_styles[] = array( |
| 57 | 'css' => wp_get_custom_css(), |
| 58 | '__unstableType' => 'user', |
| 59 | 'isGlobalStyles' => false, |
| 60 | ); |
| 61 | |
| 62 | /* |
| 63 | * Add the custom CSS as a separate stylesheet so any invalid CSS |
| 64 | * entered by users does not break other global styles. |
| 65 | */ |
| 66 | $global_styles[] = array( |
| 67 | 'css' => gutenberg_get_global_stylesheet( array( 'custom-css' ) ), |
| 68 | '__unstableType' => 'user', |
| 69 | 'isGlobalStyles' => true, |
| 70 | ); |
| 71 | |
| 72 | $settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() ); |
| 73 | |
| 74 | $settings['__experimentalFeatures'] = gutenberg_get_global_settings(); |
| 75 | // These settings may need to be updated based on data coming from theme.json sources. |
| 76 | if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) { |
| 77 | $colors_by_origin = $settings['__experimentalFeatures']['color']['palette']; |
| 78 | $settings['colors'] = $colors_by_origin['custom'] ?? $colors_by_origin['theme'] ?? $colors_by_origin['default']; |
| 79 | } |
| 80 | if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) { |
| 81 | $gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients']; |
| 82 | $settings['gradients'] = $gradients_by_origin['custom'] ?? $gradients_by_origin['theme'] ?? $gradients_by_origin['default']; |
| 83 | } |
| 84 | if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) { |
| 85 | $font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes']; |
| 86 | $settings['fontSizes'] = $font_sizes_by_origin['custom'] ?? $font_sizes_by_origin['theme'] ?? $font_sizes_by_origin['default']; |
| 87 | } |
| 88 | if ( isset( $settings['__experimentalFeatures']['color']['custom'] ) ) { |
| 89 | $settings['disableCustomColors'] = ! $settings['__experimentalFeatures']['color']['custom']; |
| 90 | unset( $settings['__experimentalFeatures']['color']['custom'] ); |
| 91 | } |
| 92 | if ( isset( $settings['__experimentalFeatures']['color']['customGradient'] ) ) { |
| 93 | $settings['disableCustomGradients'] = ! $settings['__experimentalFeatures']['color']['customGradient']; |
| 94 | unset( $settings['__experimentalFeatures']['color']['customGradient'] ); |
| 95 | } |
| 96 | if ( isset( $settings['__experimentalFeatures']['typography']['customFontSize'] ) ) { |
| 97 | $settings['disableCustomFontSizes'] = ! $settings['__experimentalFeatures']['typography']['customFontSize']; |
| 98 | unset( $settings['__experimentalFeatures']['typography']['customFontSize'] ); |
| 99 | } |
| 100 | if ( isset( $settings['__experimentalFeatures']['typography']['lineHeight'] ) ) { |
| 101 | $settings['enableCustomLineHeight'] = $settings['__experimentalFeatures']['typography']['lineHeight']; |
| 102 | unset( $settings['__experimentalFeatures']['typography']['lineHeight'] ); |
| 103 | } |
| 104 | if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) { |
| 105 | $settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units']; |
| 106 | unset( $settings['__experimentalFeatures']['spacing']['units'] ); |
| 107 | } |
| 108 | if ( isset( $settings['__experimentalFeatures']['spacing']['padding'] ) ) { |
| 109 | $settings['enableCustomSpacing'] = $settings['__experimentalFeatures']['spacing']['padding']; |
| 110 | unset( $settings['__experimentalFeatures']['spacing']['padding'] ); |
| 111 | } |
| 112 | if ( isset( $settings['__experimentalFeatures']['spacing']['customSpacingSize'] ) ) { |
| 113 | $settings['disableCustomSpacingSizes'] = ! $settings['__experimentalFeatures']['spacing']['customSpacingSize']; |
| 114 | unset( $settings['__experimentalFeatures']['spacing']['customSpacingSize'] ); |
| 115 | } |
| 116 | |
| 117 | if ( isset( $settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) { |
| 118 | $spacing_sizes_by_origin = $settings['__experimentalFeatures']['spacing']['spacingSizes']; |
| 119 | $settings['spacingSizes'] = $spacing_sizes_by_origin['custom'] ?? $spacing_sizes_by_origin['theme'] ?? $spacing_sizes_by_origin['default']; |
| 120 | } |
| 121 | |
| 122 | $settings['canEditCSS'] = current_user_can( 'edit_css' ); |
| 123 | |
| 124 | return $settings; |
| 125 | } |
| 126 | add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', 0 ); |
| 127 |