PluginProbe
Gutenberg / 9.8.0
Gutenberg v9.8.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
← All changes | lib/editor-settings.php +60 -75 12.6.09.8.0 View file →
@@ -5,93 +5,78 @@
5 5 * @package gutenberg
6 6 */
7 7
8 8 /**
9 - * Extends the block editor with settings that are only in the plugin.
9 + * Returns editor settings that are common to all editors:
10 + * post, site, widgets, and navigation.
10 11 *
11 - * This is a temporary solution until the Gutenberg plugin sets
12 - * the required WordPress version to 5.9.
12 + * All these settings are already part of core,
13 + * see edit-form-blocks.php
13 14 *
14 - * @see https://core.trac.wordpress.org/ticket/52920
15 - *
16 - * @param array $settings Existing editor settings.
17 - *
18 - * @return array Filtered settings.
15 + * @return array Common editor settings.
19 16 */
20 -function gutenberg_extend_post_editor_settings( $settings ) {
21 - $settings['__unstableEnableFullSiteEditingBlocks'] = current_theme_supports( 'block-templates' );
17 +function gutenberg_get_common_block_editor_settings() {
18 + $max_upload_size = wp_max_upload_size();
19 + if ( ! $max_upload_size ) {
20 + $max_upload_size = 0;
21 + }
22 22
23 - if ( wp_is_block_theme() ) {
24 - $settings['defaultTemplatePartAreas'] = get_allowed_block_template_part_areas();
23 + $available_image_sizes = array();
24 + // This filter is documented in wp-admin/includes/media.php.
25 + $image_size_names = apply_filters(
26 + 'image_size_names_choose',
27 + array(
28 + 'thumbnail' => __( 'Thumbnail', 'gutenberg' ),
29 + 'medium' => __( 'Medium', 'gutenberg' ),
30 + 'large' => __( 'Large', 'gutenberg' ),
31 + 'full' => __( 'Full Size', 'gutenberg' ),
32 + )
33 + );
34 + foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
35 + $available_image_sizes[] = array(
36 + 'slug' => $image_size_slug,
37 + 'name' => $image_size_name,
38 + );
39 + };
40 +
41 + $settings = array(
42 + '__unstableEnableFullSiteEditingBlocks' => gutenberg_is_fse_theme(),
43 + 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
44 + 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
45 + 'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
46 + 'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
47 + 'enableCustomUnits' => get_theme_support( 'custom-units' ),
48 + 'imageSizes' => $available_image_sizes,
49 + 'isRTL' => is_rtl(),
50 + 'maxUploadFileSize' => $max_upload_size,
51 + );
52 +
53 + $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
54 + if ( false !== $color_palette ) {
55 + $settings['colors'] = $color_palette;
25 56 }
26 57
58 + $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
59 + if ( false !== $font_sizes ) {
60 + $settings['fontSizes'] = $font_sizes;
61 + }
62 +
63 + $gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
64 + if ( false !== $gradient_presets ) {
65 + $settings['gradients'] = $gradient_presets;
66 + }
67 +
27 68 return $settings;
28 69 }
29 -add_filter( 'block_editor_settings_all', 'gutenberg_extend_post_editor_settings' );
30 70
31 71 /**
32 - * Initialize a block-based editor.
72 + * Extends the block editor with settings that are only in the plugin.
33 73 *
34 - * @param string $editor_name Editor name.
35 - * @param string $editor_script_handle Editor script handle.
36 - * @param array $settings {
37 - * Elements to initialize a block-based editor.
74 + * @param array $settings Existing editor settings.
38 75 *
39 - * @type array $preload_paths Array of paths to preload.
40 - * @type string $initializer_name Editor initialization function name.
41 - * @type array $editor_settings Editor settings.
42 - * }
43 - * @return void
76 + * @return array Filtered settings.
44 77 */
45 -function gutenberg_initialize_editor( $editor_name, $editor_script_handle, $settings ) {
46 -
47 - $defaults = array(
48 - 'preload_paths' => array(),
49 - 'initializer_name' => 'initialize',
50 - 'editor_settings' => array(),
51 - );
52 -
53 - $settings = wp_parse_args( $settings, $defaults );
54 -
55 - /**
56 - * Preload common data by specifying an array of REST API paths that will be preloaded.
57 - *
58 - * Filters the array of paths that will be preloaded.
59 - *
60 - * @param string[] $preload_paths Array of paths to preload.
61 - */
62 - $preload_paths = apply_filters( "{$editor_name}_preload_paths", $settings['preload_paths'] );
63 -
64 - $preload_data = array_reduce(
65 - $preload_paths,
66 - 'rest_preload_api_request',
67 - array()
68 - );
69 -
70 - wp_add_inline_script(
71 - 'wp-api-fetch',
72 - sprintf(
73 - 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
74 - wp_json_encode( $preload_data )
75 - ),
76 - 'after'
77 - );
78 - wp_add_inline_script(
79 - "wp-{$editor_script_handle}",
80 - sprintf(
81 - 'wp.domReady( function() {
82 - wp.%s.%s( "%s", %s );
83 - } );',
84 - lcfirst( str_replace( '-', '', ucwords( $editor_script_handle, '-' ) ) ),
85 - $settings['initializer_name'],
86 - str_replace( '_', '-', $editor_name ),
87 - wp_json_encode( $settings['editor_settings'] )
88 - )
89 - );
90 -
91 - // Preload server-registered block schemas.
92 - wp_add_inline_script(
93 - 'wp-blocks',
94 - 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
95 - );
96 -
78 +function gutenberg_extend_post_editor_settings( $settings ) {
79 + $settings['__unstableEnableFullSiteEditingBlocks'] = gutenberg_is_fse_theme();
80 + return $settings;
97 81 }
82 +add_filter( 'block_editor_settings', 'gutenberg_extend_post_editor_settings' );