PluginProbe
Gutenberg / 9.7.2
Gutenberg v9.7.2
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/widgets-page.php +67 -56 7.4.09.7.2 View file →
@@ -8,22 +8,14 @@
8 8 /**
9 9 * The main entry point for the Gutenberg widgets page.
10 10 *
11 11 * @since 5.2.0
12 - *
13 - * @param string $page The page name the function is being called for, `'gutenberg_customizer'` for the Customizer.
14 12 */
15 -function the_gutenberg_widgets( $page = 'gutenberg_page_gutenberg-widgets' ) {
13 +function the_gutenberg_widgets() {
16 14 ?>
17 15 <div
18 16 id="widgets-editor"
19 - class="blocks-widgets-container
20 - <?php
21 - echo 'gutenberg_customizer' === $page
22 - ? ' is-in-customizer'
23 - : '';
24 - ?>
25 - "
17 + class="blocks-widgets-container"
26 18 >
27 19 </div>
28 20 <?php
29 21 }
@@ -35,63 +27,53 @@
35 27 *
36 28 * @param string $hook Page.
37 29 */
38 30 function gutenberg_widgets_init( $hook ) {
39 - if ( 'gutenberg_page_gutenberg-widgets' !== $hook && 'gutenberg_customizer' !== $hook ) {
40 - return;
31 + if ( 'widgets.php' === $hook ) {
32 + wp_enqueue_style( 'wp-block-library' );
33 + wp_enqueue_style( 'wp-block-library-theme' );
34 + wp_add_inline_style(
35 + 'wp-block-library-theme',
36 + '.block-widget-form .widget-control-save { display: none; }'
37 + );
38 + return;
41 39 }
42 -
43 - $initializer_name = 'gutenberg_page_gutenberg-widgets' === $hook
44 - ? 'initialize'
45 - : 'customizerInitialize';
46 -
47 - // Media settings.
48 - $max_upload_size = wp_max_upload_size();
49 - if ( ! $max_upload_size ) {
50 - $max_upload_size = 0;
40 + if ( ! in_array( $hook, array( 'appearance_page_gutenberg-widgets' ), true ) ) {
41 + return;
51 42 }
52 43
53 - /** This filter is documented in wp-admin/includes/media.php */
54 - $image_size_names = apply_filters(
55 - 'image_size_names_choose',
56 - array(
57 - 'thumbnail' => __( 'Thumbnail', 'gutenberg' ),
58 - 'medium' => __( 'Medium', 'gutenberg' ),
59 - 'large' => __( 'Large', 'gutenberg' ),
60 - 'full' => __( 'Full Size', 'gutenberg' ),
61 - )
62 - );
44 + $initializer_name = 'initialize';
63 45
64 - $available_image_sizes = array();
65 - foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
66 - $available_image_sizes[] = array(
67 - 'slug' => $image_size_slug,
68 - 'name' => $image_size_name,
69 - );
70 - }
71 -
72 46 $settings = array_merge(
73 - array(
74 - 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
75 - 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
76 - 'imageSizes' => $available_image_sizes,
77 - 'isRTL' => is_rtl(),
78 - 'maxUploadFileSize' => $max_upload_size,
79 - ),
47 + gutenberg_get_common_block_editor_settings(),
80 48 gutenberg_get_legacy_widget_settings()
81 49 );
82 50
83 - list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' );
84 - list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' );
51 + // This purposefully does not rely on apply_filters( 'block_editor_settings', $settings, null );
52 + // Applying that filter would bring over multitude of features from the post editor, some of which
53 + // may be undesirable. Instead of using that filter, we simply pick just the settings that are needed.
54 + $settings = gutenberg_experimental_global_styles_settings( $settings );
55 + $settings = gutenberg_extend_block_editor_styles( $settings );
85 56
86 - if ( false !== $color_palette ) {
87 - $settings['colors'] = $color_palette;
88 - }
57 + $preload_paths = array(
58 + array( '/wp/v2/media', 'OPTIONS' ),
59 + '/wp/v2/sidebars?context=edit&per_page=-1',
60 + '/wp/v2/widgets?context=edit&per_page=-1',
61 + );
62 + $preload_data = array_reduce(
63 + $preload_paths,
64 + 'rest_preload_api_request',
65 + array()
66 + );
67 + wp_add_inline_script(
68 + 'wp-api-fetch',
69 + sprintf(
70 + 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
71 + wp_json_encode( $preload_data )
72 + ),
73 + 'after'
74 + );
89 75
90 - if ( false !== $font_sizes ) {
91 - $settings['fontSizes'] = $font_sizes;
92 - }
93 -
94 76 wp_add_inline_script(
95 77 'wp-edit-widgets',
96 78 sprintf(
97 79 'wp.domReady( function() {
@@ -97,9 +79,9 @@
97 79 'wp.domReady( function() {
98 80 wp.editWidgets.%s( "widgets-editor", %s );
99 81 } );',
100 82 $initializer_name,
101 - wp_json_encode( gutenberg_experiments_editor_settings( $settings ) )
83 + wp_json_encode( $settings )
102 84 )
103 85 );
104 86
105 87 // Preload server-registered block schemas.
@@ -114,4 +96,33 @@
114 96 wp_enqueue_style( 'wp-edit-widgets' );
115 97 wp_enqueue_style( 'wp-format-library' );
116 98 }
117 99 add_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' );
100 +
101 +/**
102 + * Tells the script loader to load the scripts and styles of custom block on widgets editor screen.
103 + *
104 + * @param bool $is_block_editor_screen Current decision about loading block assets.
105 + * @return bool Filtered decision about loading block assets.
106 + */
107 +function gutenberg_widgets_editor_load_block_editor_scripts_and_styles( $is_block_editor_screen ) {
108 + if ( is_callable( 'get_current_screen' ) && 'appearance_page_gutenberg-widgets' === get_current_screen()->base ) {
109 + return true;
110 + }
111 +
112 + return $is_block_editor_screen;
113 +}
114 +
115 +add_filter( 'should_load_block_editor_scripts_and_styles', 'gutenberg_widgets_editor_load_block_editor_scripts_and_styles' );
116 +
117 +/**
118 + * Show responsive embeds correctly on the widgets screen by adding the wp-embed-responsive class.
119 + *
120 + * @param string $classes existing admin body classes.
121 + *
122 + * @return string admin body classes including the wp-embed-responsive class.
123 + */
124 +function gutenberg_widgets_editor_add_responsive_embed_body_class( $classes ) {
125 + return "$classes wp-embed-responsive";
126 +}
127 +
128 +add_filter( 'admin_body_class', 'gutenberg_widgets_editor_add_responsive_embed_body_class' );