PluginProbe
Gutenberg / 15.8.1
Gutenberg v15.8.1
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 15.8.1, at lib/block-editor-settings.php

83 lines 2.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 * 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