PluginProbe
Gutenberg / 14.7.0
Gutenberg v14.7.0
24.0.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 All 403 releases
gutenberg / lib / compat / wordpress-6.1 / block-editor-settings.php

block-editor-settings.php in Gutenberg 14.7.0, at lib/compat/wordpress-6.1/block-editor-settings.php

178 lines 6.6 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 * Adds styles and __experimentalFeatures to the block editor settings.
10 *
11 * @param array $settings Existing block editor settings.
12 *
13 * @return array New block editor settings.
14 */
15 function gutenberg_get_block_editor_settings( $settings ) {
16 // Set what is the context for this data request.
17 $context = 'other';
18 if (
19 defined( 'REST_REQUEST' ) &&
20 REST_REQUEST &&
21 isset( $_GET['context'] ) &&
22 'mobile' === $_GET['context']
23 ) {
24 $context = 'mobile';
25 }
26
27 if ( 'other' === $context ) {
28 global $wp_version;
29 $is_wp_5_9 = version_compare( $wp_version, '5.9', '>=' ) && version_compare( $wp_version, '6.0-beta1', '<' );
30 $is_wp_6_0 = version_compare( $wp_version, '6.0-beta1', '>=' );
31
32 // Make sure the styles array exists.
33 // In some contexts, like the navigation editor, it doesn't.
34 if ( ! isset( $settings['styles'] ) ) {
35 $settings['styles'] = array();
36 }
37
38 // Remove existing global styles provided by core.
39 $styles_without_existing_global_styles = array();
40 foreach ( $settings['styles'] as $style ) {
41 if (
42 ( $is_wp_5_9 && ! gutenberg_is_global_styles_in_5_9( $style ) ) || // Can be removed when plugin minimum version is 6.0.
43 ( $is_wp_6_0 && ( ! isset( $style['isGlobalStyles'] ) || ! $style['isGlobalStyles'] ) )
44 ) {
45 $styles_without_existing_global_styles[] = $style;
46 }
47 }
48
49 // Recreate global styles.
50 $new_global_styles = array();
51 $presets = array(
52 array(
53 'css' => 'variables',
54 '__unstableType' => 'presets',
55 'isGlobalStyles' => true,
56 ),
57 array(
58 'css' => 'presets',
59 '__unstableType' => 'presets',
60 'isGlobalStyles' => true,
61 ),
62 );
63 foreach ( $presets as $preset_style ) {
64 $actual_css = gutenberg_get_global_stylesheet( array( $preset_style['css'] ) );
65 if ( '' !== $actual_css ) {
66 $preset_style['css'] = $actual_css;
67 $new_global_styles[] = $preset_style;
68 }
69 }
70
71 if ( wp_theme_has_theme_json() ) {
72 $block_classes = array(
73 'css' => 'styles',
74 '__unstableType' => 'theme',
75 'isGlobalStyles' => true,
76 );
77 $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) );
78 if ( '' !== $actual_css ) {
79 $block_classes['css'] = $actual_css;
80 $new_global_styles[] = $block_classes;
81 }
82 } else {
83 // If there is no `theme.json` file, ensure base layout styles are still available.
84 $block_classes = array(
85 'css' => 'base-layout-styles',
86 '__unstableType' => 'base-layout',
87 'isGlobalStyles' => true,
88 );
89 $actual_css = gutenberg_get_global_stylesheet( array( $block_classes['css'] ) );
90 if ( '' !== $actual_css ) {
91 $block_classes['css'] = $actual_css;
92 $new_global_styles[] = $block_classes;
93 }
94 }
95
96 $settings['styles'] = array_merge( $new_global_styles, $styles_without_existing_global_styles );
97 }
98
99 // Copied from get_block_editor_settings() at wordpress-develop/block-editor.php.
100 $settings['__experimentalFeatures'] = gutenberg_get_global_settings();
101
102 if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) {
103 $colors_by_origin = $settings['__experimentalFeatures']['color']['palette'];
104 $settings['colors'] = isset( $colors_by_origin['custom'] ) ?
105 $colors_by_origin['custom'] : (
106 isset( $colors_by_origin['theme'] ) ?
107 $colors_by_origin['theme'] :
108 $colors_by_origin['default']
109 );
110 }
111
112 if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) {
113 $gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients'];
114 $settings['gradients'] = isset( $gradients_by_origin['custom'] ) ?
115 $gradients_by_origin['custom'] : (
116 isset( $gradients_by_origin['theme'] ) ?
117 $gradients_by_origin['theme'] :
118 $gradients_by_origin['default']
119 );
120 }
121
122 if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
123 $font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes'];
124 $settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ?
125 $font_sizes_by_origin['custom'] : (
126 isset( $font_sizes_by_origin['theme'] ) ?
127 $font_sizes_by_origin['theme'] :
128 $font_sizes_by_origin['default']
129 );
130 }
131
132 if ( isset( $settings['__experimentalFeatures']['color']['custom'] ) ) {
133 $settings['disableCustomColors'] = ! $settings['__experimentalFeatures']['color']['custom'];
134 unset( $settings['__experimentalFeatures']['color']['custom'] );
135 }
136 if ( isset( $settings['__experimentalFeatures']['color']['customGradient'] ) ) {
137 $settings['disableCustomGradients'] = ! $settings['__experimentalFeatures']['color']['customGradient'];
138 unset( $settings['__experimentalFeatures']['color']['customGradient'] );
139 }
140 if ( isset( $settings['__experimentalFeatures']['typography']['customFontSize'] ) ) {
141 $settings['disableCustomFontSizes'] = ! $settings['__experimentalFeatures']['typography']['customFontSize'];
142 unset( $settings['__experimentalFeatures']['typography']['customFontSize'] );
143 }
144 if ( isset( $settings['__experimentalFeatures']['typography']['lineHeight'] ) ) {
145 $settings['enableCustomLineHeight'] = $settings['__experimentalFeatures']['typography']['lineHeight'];
146 unset( $settings['__experimentalFeatures']['typography']['lineHeight'] );
147 }
148 if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) {
149 $settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units'];
150 unset( $settings['__experimentalFeatures']['spacing']['units'] );
151 }
152 if ( isset( $settings['__experimentalFeatures']['spacing']['padding'] ) ) {
153 $settings['enableCustomSpacing'] = $settings['__experimentalFeatures']['spacing']['padding'];
154 unset( $settings['__experimentalFeatures']['spacing']['padding'] );
155 }
156 if ( isset( $settings['__experimentalFeatures']['spacing']['customSpacingSize'] ) ) {
157 $settings['disableCustomSpacingSizes'] = ! $settings['__experimentalFeatures']['spacing']['customSpacingSize'];
158 unset( $settings['__experimentalFeatures']['spacing']['customSpacingSize'] );
159 }
160
161 if ( isset( $settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) {
162 $spacing_sizes_by_origin = $settings['__experimentalFeatures']['spacing']['spacingSizes'];
163 $settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ?
164 $spacing_sizes_by_origin['custom'] : (
165 isset( $spacing_sizes_by_origin['theme'] ) ?
166 $spacing_sizes_by_origin['theme'] :
167 $spacing_sizes_by_origin['default']
168 );
169 }
170
171 $settings['localAutosaveInterval'] = 15;
172 $settings['disableLayoutStyles'] = current_theme_supports( 'disable-layout-styles' );
173
174 return $settings;
175 }
176
177 add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings', PHP_INT_MAX );
178