PluginProbe
Gutenberg / 17.6.0
Gutenberg v17.6.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / block-editor-settings.php

block-editor-settings.php in Gutenberg 17.6.0, at lib/block-editor-settings.php

152 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 if ( wp_theme_has_theme_json() ) {
45 $block_classes = array(
46 'css' => 'styles',
47 '__unstableType' => 'theme',
48 'isGlobalStyles' => true,
49 );
50 $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) );
51 if ( '' !== $actual_css ) {
52 $block_classes['css'] = $actual_css;
53 $global_styles[] = $block_classes;
54 }
55
56 /*
57 * Add the custom CSS as a separate stylesheet so any invalid CSS
58 * entered by users does not break other global styles.
59 */
60 $global_styles[] = array(
61 'css' => gutenberg_get_global_styles_custom_css(),
62 '__unstableType' => 'user',
63 'isGlobalStyles' => true,
64 );
65 } else {
66 // If there is no `theme.json` file, ensure base layout styles are still available.
67 $block_classes = array(
68 'css' => 'base-layout-styles',
69 '__unstableType' => 'base-layout',
70 'isGlobalStyles' => true,
71 );
72 $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) );
73 if ( '' !== $actual_css ) {
74 $block_classes['css'] = $actual_css;
75 $global_styles[] = $block_classes;
76 }
77 }
78
79 $settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() );
80
81 $settings['__experimentalFeatures'] = gutenberg_get_global_settings();
82 // These settings may need to be updated based on data coming from theme.json sources.
83 if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) {
84 $colors_by_origin = $settings['__experimentalFeatures']['color']['palette'];
85 $settings['colors'] = isset( $colors_by_origin['custom'] ) ?
86 $colors_by_origin['custom'] : (
87 isset( $colors_by_origin['theme'] ) ?
88 $colors_by_origin['theme'] :
89 $colors_by_origin['default']
90 );
91 }
92 if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) {
93 $gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients'];
94 $settings['gradients'] = isset( $gradients_by_origin['custom'] ) ?
95 $gradients_by_origin['custom'] : (
96 isset( $gradients_by_origin['theme'] ) ?
97 $gradients_by_origin['theme'] :
98 $gradients_by_origin['default']
99 );
100 }
101 if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
102 $font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes'];
103 $settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ?
104 $font_sizes_by_origin['custom'] : (
105 isset( $font_sizes_by_origin['theme'] ) ?
106 $font_sizes_by_origin['theme'] :
107 $font_sizes_by_origin['default']
108 );
109 }
110 if ( isset( $settings['__experimentalFeatures']['color']['custom'] ) ) {
111 $settings['disableCustomColors'] = ! $settings['__experimentalFeatures']['color']['custom'];
112 unset( $settings['__experimentalFeatures']['color']['custom'] );
113 }
114 if ( isset( $settings['__experimentalFeatures']['color']['customGradient'] ) ) {
115 $settings['disableCustomGradients'] = ! $settings['__experimentalFeatures']['color']['customGradient'];
116 unset( $settings['__experimentalFeatures']['color']['customGradient'] );
117 }
118 if ( isset( $settings['__experimentalFeatures']['typography']['customFontSize'] ) ) {
119 $settings['disableCustomFontSizes'] = ! $settings['__experimentalFeatures']['typography']['customFontSize'];
120 unset( $settings['__experimentalFeatures']['typography']['customFontSize'] );
121 }
122 if ( isset( $settings['__experimentalFeatures']['typography']['lineHeight'] ) ) {
123 $settings['enableCustomLineHeight'] = $settings['__experimentalFeatures']['typography']['lineHeight'];
124 unset( $settings['__experimentalFeatures']['typography']['lineHeight'] );
125 }
126 if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) {
127 $settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units'];
128 unset( $settings['__experimentalFeatures']['spacing']['units'] );
129 }
130 if ( isset( $settings['__experimentalFeatures']['spacing']['padding'] ) ) {
131 $settings['enableCustomSpacing'] = $settings['__experimentalFeatures']['spacing']['padding'];
132 unset( $settings['__experimentalFeatures']['spacing']['padding'] );
133 }
134 if ( isset( $settings['__experimentalFeatures']['spacing']['customSpacingSize'] ) ) {
135 $settings['disableCustomSpacingSizes'] = ! $settings['__experimentalFeatures']['spacing']['customSpacingSize'];
136 unset( $settings['__experimentalFeatures']['spacing']['customSpacingSize'] );
137 }
138
139 if ( isset( $settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) {
140 $spacing_sizes_by_origin = $settings['__experimentalFeatures']['spacing']['spacingSizes'];
141 $settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ?
142 $spacing_sizes_by_origin['custom'] : (
143 isset( $spacing_sizes_by_origin['theme'] ) ?
144 $spacing_sizes_by_origin['theme'] :
145 $spacing_sizes_by_origin['default']
146 );
147 }
148
149 return $settings;
150 }
151 add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', 0 );
152