PluginProbe
Gutenberg / 23.5.2
Gutenberg v23.5.2
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 23.5.2, at lib/block-editor-settings.php

127 lines 5.4 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 $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