PluginProbe
Gutenberg / 14.5.2
Gutenberg v14.5.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/client-assets.php +273 -222 24.0.014.5.2 View file →
@@ -12,11 +12,11 @@
12 12
13 13 /**
14 14 * Retrieves the root plugin path.
15 15 *
16 + * @return string Root path to the gutenberg plugin.
17 + *
16 18 * @since 0.1.0
17 - *
18 - * @return string Root path to the gutenberg plugin.
19 19 */
20 20 function gutenberg_dir_path() {
21 21 return plugin_dir_path( __DIR__ );
22 22 }
@@ -23,13 +23,13 @@
23 23
24 24 /**
25 25 * Retrieves a URL to a file in the gutenberg plugin.
26 26 *
27 - * @since 0.1.0
27 + * @param string $path Relative path of the desired file.
28 28 *
29 - * @param string $path Relative path of the desired file.
29 + * @return string Fully qualified URL pointing to the desired file.
30 30 *
31 - * @return string Fully qualified URL pointing to the desired file.
31 + * @since 0.1.0
32 32 */
33 33 function gutenberg_url( $path ) {
34 34 return plugins_url( $path, __DIR__ );
35 35 }
@@ -34,8 +34,78 @@
34 34 return plugins_url( $path, __DIR__ );
35 35 }
36 36
37 37 /**
38 + * Registers a script according to `wp_register_script`. Honors this request by
39 + * reassigning internal dependency properties of any script handle already
40 + * registered by that name. It does not deregister the original script, to
41 + * avoid losing inline scripts which may have been attached.
42 + *
43 + * @since 4.1.0
44 + *
45 + * @param WP_Scripts $scripts WP_Scripts instance.
46 + * @param string $handle Name of the script. Should be unique.
47 + * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
48 + * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
49 + * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
50 + * as a query string for cache busting purposes. If version is set to false, a version
51 + * number is automatically added equal to current installed WordPress version.
52 + * If set to null, no version is added.
53 + * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
54 + * Default 'false'.
55 + */
56 +function gutenberg_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
57 + /*
58 + * Force `wp-i18n` script to be registered in the <head> as a
59 + * temporary workaround for https://meta.trac.wordpress.org/ticket/6195.
60 + */
61 + $in_footer = 'wp-i18n' === $handle ? false : $in_footer;
62 +
63 + $script = $scripts->query( $handle, 'registered' );
64 + if ( $script ) {
65 + /*
66 + * In many ways, this is a reimplementation of `wp_register_script` but
67 + * bypassing consideration of whether a script by the given handle had
68 + * already been registered.
69 + */
70 +
71 + // See: `_WP_Dependency::__construct` .
72 + $script->src = $src;
73 + $script->deps = $deps;
74 + $script->ver = $ver;
75 + $script->args = $in_footer ? 1 : null;
76 + } else {
77 + $scripts->add( $handle, $src, $deps, $ver, ( $in_footer ? 1 : null ) );
78 + }
79 +
80 + /*
81 + * `WP_Dependencies::set_translations` will fall over on itself if setting
82 + * translations on the `wp-i18n` handle, since it internally adds `wp-i18n`
83 + * as a dependency of itself, exhausting memory. The same applies for the
84 + * polyfill and hooks scripts, which are dependencies _of_ `wp-i18n`.
85 + *
86 + * See: https://core.trac.wordpress.org/ticket/46089
87 + */
88 + if ( ! in_array( $handle, array( 'wp-i18n', 'wp-polyfill', 'wp-hooks' ), true ) ) {
89 + $scripts->set_translations( $handle, 'default' );
90 + }
91 +
92 + /*
93 + * Wp-editor module is exposed as window.wp.editor.
94 + * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
95 + * Solution: fuse the two objects together to maintain backward compatibility.
96 + * For more context, see https://github.com/WordPress/gutenberg/issues/33203
97 + */
98 + if ( 'wp-editor' === $handle ) {
99 + $scripts->add_inline_script(
100 + 'wp-editor',
101 + 'Object.assign( window.wp.editor, window.wp.oldEditor );',
102 + 'after'
103 + );
104 + }
105 +}
106 +
107 +/**
38 108 * Filters the default translation file load behavior to load the Gutenberg
39 109 * plugin translation file, if available.
40 110 *
41 111 * @param string|false $file Path to the translation file to load. False if
@@ -55,10 +125,10 @@
55 125 if ( ! str_starts_with( $handle, 'wp-' ) ) {
56 126 return $file;
57 127 }
58 128
59 - // Ignore scripts that are not found in the expected `build/scripts/` location.
60 - $script_path = gutenberg_dir_path() . 'build/scripts/' . substr( $handle, 3 ) . '/index.min.js';
129 + // Ignore scripts that are not found in the expected `build/` location.
130 + $script_path = gutenberg_dir_path() . 'build/' . substr( $handle, 3 ) . '/index.min.js';
61 131 if ( ! file_exists( $script_path ) ) {
62 132 return $file;
63 133 }
64 134
@@ -86,127 +156,166 @@
86 156 }
87 157 add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 );
88 158
89 159 /**
90 - * Adds the 'editor' dependency to wp-block-library, required by the Classic block.
160 + * Registers a style according to `wp_register_style`. Honors this request by
161 + * deregistering any style by the same handler before registration.
91 162 *
92 - * @param WP_Scripts $scripts WP_Scripts instance.
163 + * @since 4.1.0
164 + *
165 + * @param WP_Styles $styles WP_Styles instance.
166 + * @param string $handle Name of the stylesheet. Should be unique.
167 + * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
168 + * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
169 + * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
170 + * as a query string for cache busting purposes. If version is set to false, a version
171 + * number is automatically added equal to current installed WordPress version.
172 + * If set to null, no version is added.
173 + * @param string $media Optional. The media for which this stylesheet has been defined.
174 + * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
175 + * '(orientation: portrait)' and '(max-width: 640px)'.
93 176 */
94 -function gutenberg_register_block_library_script_special_case( $scripts ) {
95 - $handle = 'wp-block-library';
96 - $script = $scripts->query( $handle, 'registered' );
97 - if ( ! in_array( 'editor', $script->deps, true ) ) {
98 - $script->deps[] = 'editor';
177 +function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
178 + $style = $styles->query( $handle, 'registered' );
179 + if ( $style ) {
180 + $styles->remove( $handle );
99 181 }
182 + $styles->add( $handle, $src, $deps, $ver, $media );
100 183 }
101 -add_action( 'wp_default_scripts', 'gutenberg_register_block_library_script_special_case', 11 );
102 184
103 185 /**
104 - * Registers WordPress package styles with complex requirements.
186 + * Registers all the WordPress packages scripts that are in the standardized
187 + * `build/` location.
105 188 *
106 - * Simple styles (main style.css with inferred dependencies) are auto-registered
107 - * via build/styles.php at default priority (10). This function runs at priority 15 to handle:
108 - * - Multiple style files per package (content.css, classic.css, etc.)
109 - * - Non-WordPress dependencies (dashicons, common, forms)
110 - * - Custom handles that don't match wp-{package} pattern
111 - * - Conditional dependencies based on theme/settings
112 - * - Dynamic filename logic
189 + * @since 4.5.0
113 190 *
114 - * These override calls will replace the auto-registered versions as needed.
191 + * @param WP_Scripts $scripts WP_Scripts instance.
192 + */
193 +function gutenberg_register_packages_scripts( $scripts ) {
194 + // When in production, use the plugin's version as the default asset version;
195 + // else (for development or test) default to use the current time.
196 + $default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time();
197 +
198 + foreach ( glob( gutenberg_dir_path() . 'build/*/index.min.js' ) as $path ) {
199 + // Prefix `wp-` to package directory to get script handle.
200 + // For example, `…/build/a11y/index.min.js` becomes `wp-a11y`.
201 + $handle = 'wp-' . basename( dirname( $path ) );
202 +
203 + // Replace extension with `.asset.php` to find the generated dependencies file.
204 + $asset_file = substr( $path, 0, -( strlen( '.js' ) ) ) . '.asset.php';
205 + $asset = file_exists( $asset_file )
206 + ? require $asset_file
207 + : null;
208 + $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
209 + $version = isset( $asset['version'] ) ? $asset['version'] : $default_version;
210 +
211 + // Add dependencies that cannot be detected and generated by build tools.
212 + switch ( $handle ) {
213 + case 'wp-block-library':
214 + array_push( $dependencies, 'editor' );
215 + break;
216 +
217 + case 'wp-edit-post':
218 + array_push( $dependencies, 'media-models', 'media-views', 'postbox' );
219 + break;
220 +
221 + case 'wp-edit-site':
222 + array_push( $dependencies, 'wp-dom-ready' );
223 + break;
224 + }
225 +
226 + // Get the path from Gutenberg directory as expected by `gutenberg_url`.
227 + $gutenberg_path = substr( $path, strlen( gutenberg_dir_path() ) );
228 +
229 + gutenberg_override_script(
230 + $scripts,
231 + $handle,
232 + gutenberg_url( $gutenberg_path ),
233 + $dependencies,
234 + $version,
235 + true
236 + );
237 + }
238 +}
239 +add_action( 'wp_default_scripts', 'gutenberg_register_packages_scripts' );
240 +
241 +/**
242 + * Registers all the WordPress packages styles that are in the standardized
243 + * `build/` location.
115 244 *
116 245 * @since 6.7.0
117 - *
118 - * @global array $editor_styles
119 - *
246 +
120 247 * @param WP_Styles $styles WP_Styles instance.
121 248 */
122 249 function gutenberg_register_packages_styles( $styles ) {
123 250 // When in production, use the plugin's version as the asset version;
124 251 // else (for development or test) default to use the current time.
125 - $version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time();
126 - $suffix = SCRIPT_DEBUG ? '' : '.min';
252 + $version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time();
127 253
128 - // wp-components: add dashicons (icon font dependency) and design tokens.
129 - $components_style = $styles->query( 'wp-components', 'registered' );
130 - $components_style->deps[] = 'dashicons';
131 - $components_style->deps[] = 'wp-theme';
254 + // Editor Styles.
255 + gutenberg_override_style(
256 + $styles,
257 + 'wp-block-editor',
258 + gutenberg_url( 'build/block-editor/style.css' ),
259 + array( 'wp-components' ),
260 + $version
261 + );
262 + $styles->add_data( 'wp-block-editor', 'rtl', 'replace' );
132 263
133 - // wp-edit-post: add wp-edit-blocks (custom handle not auto-inferred)
134 - $styles->query( 'wp-edit-post', 'registered' )->deps[] = 'wp-edit-blocks';
135 -
136 - // wp-edit-site: add core WP styles and custom handles
137 - $edit_site_style = $styles->query( 'wp-edit-site', 'registered' );
138 - $edit_site_style->deps[] = 'common';
139 - $edit_site_style->deps[] = 'forms';
140 - $edit_site_style->deps[] = 'wp-block-library-editor';
141 -
142 - // wp-edit-widgets: add wp-edit-blocks (custom handle not auto-inferred)
143 - $styles->query( 'wp-edit-widgets', 'registered' )->deps[] = 'wp-edit-blocks';
144 -
145 - // wp-customize-widgets: add wp-edit-blocks (custom handle not auto-inferred)
146 - $styles->query( 'wp-customize-widgets', 'registered' )->deps[] = 'wp-edit-blocks';
147 -
148 264 gutenberg_override_style(
149 265 $styles,
150 - 'wp-theme',
151 - gutenberg_url( 'build/styles/theme/design-tokens' . $suffix . '.css' ),
152 - array(),
266 + 'wp-editor',
267 + gutenberg_url( 'build/editor/style.css' ),
268 + array( 'wp-components', 'wp-block-editor', 'wp-nux', 'wp-reusable-blocks' ),
153 269 $version
154 270 );
155 - $styles->add_data( 'wp-theme', 'rtl', 'replace' );
156 - $styles->add_data( 'wp-theme', 'suffix', $suffix );
157 - $styles->add_data( 'wp-theme', 'path', gutenberg_dir_path() . 'build/styles/theme/design-tokens' . $suffix . '.css' );
271 + $styles->add_data( 'wp-editor', 'rtl', 'replace' );
158 272
159 - // Register wp-base-styles and add it to the already registered wp-admin stylesheet
160 273 gutenberg_override_style(
161 274 $styles,
162 - 'wp-base-styles',
163 - gutenberg_url( 'build/styles/base-styles/admin-schemes' . $suffix . '.css' ),
164 - array(),
275 + 'wp-edit-post',
276 + gutenberg_url( 'build/edit-post/style.css' ),
277 + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-block-library', 'wp-nux' ),
165 278 $version
166 279 );
167 - $styles->add_data( 'wp-base-styles', 'rtl', 'replace' );
168 - $styles->add_data( 'wp-base-styles', 'suffix', $suffix );
169 - $styles->add_data( 'wp-base-styles', 'path', gutenberg_dir_path() . 'build/styles/base-styles/admin-schemes' . $suffix . '.css' );
170 - $styles->query( 'wp-admin', 'registered' )->deps[] = 'wp-base-styles';
280 + $styles->add_data( 'wp-edit-post', 'rtl', 'replace' );
171 281
172 282 gutenberg_override_style(
173 283 $styles,
174 - 'wp-block-editor-content',
175 - gutenberg_url( 'build/styles/block-editor/content' . $suffix . '.css' ),
176 - array( 'wp-components' ),
284 + 'wp-components',
285 + gutenberg_url( 'build/components/style.css' ),
286 + array( 'dashicons' ),
177 287 $version
178 288 );
179 - $styles->add_data( 'wp-block-editor-content', 'rtl', 'replace' );
180 - $styles->add_data( 'wp-block-editor-content', 'suffix', $suffix );
289 + $styles->add_data( 'wp-components', 'rtl', 'replace' );
181 290
182 291 $block_library_filename = wp_should_load_separate_core_block_assets() ? 'common' : 'style';
183 292 gutenberg_override_style(
184 293 $styles,
185 294 'wp-block-library',
186 - gutenberg_url( 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' ),
295 + gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ),
187 296 array(),
188 297 $version
189 298 );
190 299 $styles->add_data( 'wp-block-library', 'rtl', 'replace' );
191 - $styles->add_data( 'wp-block-library', 'suffix', $suffix );
192 - $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' );
300 + $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/block-library/' . $block_library_filename . '.css' );
193 301
194 - // Only add CONTENT styles here that should be enqueued in the iframe!
302 + gutenberg_override_style(
303 + $styles,
304 + 'wp-format-library',
305 + gutenberg_url( 'build/format-library/style.css' ),
306 + array( 'wp-block-editor', 'wp-components' ),
307 + $version
308 + );
309 + $styles->add_data( 'wp-format-library', 'rtl', 'replace' );
310 +
195 311 $wp_edit_blocks_dependencies = array(
196 - // Design System tokens load first so the `:root` CSS custom
197 - // properties are defined before any consuming stylesheet reads
198 - // them inside the editor iframe.
199 - 'wp-theme',
200 312 'wp-components',
201 313 // This need to be added before the block library styles,
202 314 // The block library styles override the "reset" styles.
203 315 'wp-reset-editor-styles',
204 316 'wp-block-library',
205 - // Until #37466, we can't specifically add them as editor styles yet,
206 - // so we must hard-code it here as a dependency.
207 - 'wp-block-editor-content',
208 - 'wp-base-styles',
317 + 'wp-reusable-blocks',
209 318 );
210 319
211 320 // Only load the default layout and margin styles for themes without theme.json file.
212 321 if ( ! wp_theme_has_theme_json() ) {
@@ -221,67 +330,122 @@
221 330
222 331 gutenberg_override_style(
223 332 $styles,
224 333 'wp-reset-editor-styles',
225 - gutenberg_url( 'build/styles/block-library/reset' . $suffix . '.css' ),
334 + gutenberg_url( 'build/block-library/reset.css' ),
226 335 array( 'common', 'forms' ), // Make sure the reset is loaded after the default WP Admin styles.
227 336 $version
228 337 );
229 338 $styles->add_data( 'wp-reset-editor-styles', 'rtl', 'replace' );
230 - $styles->add_data( 'wp-reset-editor-styles', 'suffix', $suffix );
231 339
232 340 gutenberg_override_style(
233 341 $styles,
234 342 'wp-editor-classic-layout-styles',
235 - gutenberg_url( 'build/styles/edit-post/classic' . $suffix . '.css' ),
343 + gutenberg_url( 'build/edit-post/classic.css' ),
236 344 array(),
237 345 $version
238 346 );
239 347 $styles->add_data( 'wp-editor-classic-layout-styles', 'rtl', 'replace' );
240 - $styles->add_data( 'wp-editor-classic-layout-styles', 'suffix', $suffix );
241 348
242 349 gutenberg_override_style(
243 350 $styles,
244 - 'wp-block-library-editor',
245 - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ),
246 - array(),
351 + 'wp-edit-blocks',
352 + gutenberg_url( 'build/block-library/editor.css' ),
353 + $wp_edit_blocks_dependencies,
247 354 $version
248 355 );
249 - $styles->add_data( 'wp-block-library-editor', 'rtl', 'replace' );
250 - $styles->add_data( 'wp-block-library-editor', 'suffix', $suffix );
356 + $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' );
251 357
252 358 gutenberg_override_style(
253 359 $styles,
254 - 'wp-edit-blocks',
255 - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ),
256 - $wp_edit_blocks_dependencies,
360 + 'wp-nux',
361 + gutenberg_url( 'build/nux/style.css' ),
362 + array( 'wp-components' ),
257 363 $version
258 364 );
259 - $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' );
260 - $styles->add_data( 'wp-edit-blocks', 'suffix', $suffix );
365 + $styles->add_data( 'wp-nux', 'rtl', 'replace' );
261 366
262 367 gutenberg_override_style(
263 368 $styles,
264 369 'wp-block-library-theme',
265 - gutenberg_url( 'build/styles/block-library/theme' . $suffix . '.css' ),
370 + gutenberg_url( 'build/block-library/theme.css' ),
266 371 array(),
267 372 $version
268 373 );
269 374 $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' );
270 - $styles->add_data( 'wp-block-library-theme', 'suffix', $suffix );
271 375
272 376 gutenberg_override_style(
273 377 $styles,
274 - 'classic-theme-styles',
275 - gutenberg_url( 'build/styles/block-library/classic' . $suffix . '.css' ),
276 - array(),
378 + 'wp-list-reusable-blocks',
379 + gutenberg_url( 'build/list-reusable-blocks/style.css' ),
380 + array( 'wp-components' ),
277 381 $version
278 382 );
279 - $styles->add_data( 'classic-theme-styles', 'rtl', 'replace' );
280 - $styles->add_data( 'classic-theme-styles', 'suffix', $suffix );
281 - $styles->add_data( 'classic-theme-styles', 'path', gutenberg_dir_path() . 'build/styles/block-library/classic' . $suffix . '.css' );
383 + $styles->add_data( 'wp-list-reusable-block', 'rtl', 'replace' );
384 +
385 + gutenberg_override_style(
386 + $styles,
387 + 'wp-edit-navigation',
388 + gutenberg_url( 'build/edit-navigation/style.css' ),
389 + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks' ),
390 + $version
391 + );
392 + $styles->add_data( 'wp-edit-navigation', 'rtl', 'replace' );
393 +
394 + gutenberg_override_style(
395 + $styles,
396 + 'wp-edit-site',
397 + gutenberg_url( 'build/edit-site/style.css' ),
398 + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks' ),
399 + $version
400 + );
401 + $styles->add_data( 'wp-edit-site', 'rtl', 'replace' );
402 +
403 + gutenberg_override_style(
404 + $styles,
405 + 'wp-edit-widgets',
406 + gutenberg_url( 'build/edit-widgets/style.css' ),
407 + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-reusable-blocks', 'wp-widgets' ),
408 + $version
409 + );
410 + $styles->add_data( 'wp-edit-widgets', 'rtl', 'replace' );
411 +
412 + gutenberg_override_style(
413 + $styles,
414 + 'wp-block-directory',
415 + gutenberg_url( 'build/block-directory/style.css' ),
416 + array( 'wp-block-editor', 'wp-components' ),
417 + $version
418 + );
419 + $styles->add_data( 'wp-block-directory', 'rtl', 'replace' );
420 +
421 + gutenberg_override_style(
422 + $styles,
423 + 'wp-customize-widgets',
424 + gutenberg_url( 'build/customize-widgets/style.css' ),
425 + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-widgets' ),
426 + $version
427 + );
428 + $styles->add_data( 'wp-customize-widgets', 'rtl', 'replace' );
429 +
430 + gutenberg_override_style(
431 + $styles,
432 + 'wp-reusable-blocks',
433 + gutenberg_url( 'build/reusable-blocks/style.css' ),
434 + array( 'wp-components' ),
435 + $version
436 + );
437 + $styles->add_data( 'wp-reusable-block', 'rtl', 'replace' );
438 +
439 + gutenberg_override_style(
440 + $styles,
441 + 'wp-widgets',
442 + gutenberg_url( 'build/widgets/style.css' ),
443 + array( 'wp-components' )
444 + );
445 + $styles->add_data( 'wp-widgets', 'rtl', 'replace' );
282 446 }
283 -add_action( 'wp_default_styles', 'gutenberg_register_packages_styles', 15 );
447 +add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' );
284 448
285 449 /**
286 450 * Fetches, processes and compiles stored core styles, then combines and renders them to the page.
287 451 * Styles are stored via the Style Engine API.
@@ -288,12 +452,10 @@
288 452 *
289 453 * This hook also exists, and should be backported to Core in future versions.
290 454 * However, it is envisaged that Gutenberg will continue to use the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes to aid continuous development.
291 455 *
292 - * @since 6.1
456 + * See: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/
293 457 *
294 - * @link https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/
295 - *
296 458 * @param array $options {
297 459 * Optional. An array of options to pass to gutenberg_style_engine_get_stylesheet_from_context(). Default empty array.
298 460 *
299 461 * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
@@ -299,8 +461,10 @@
299 461 * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
300 462 * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
301 463 * }
302 464 *
465 + * @since 6.1
466 + *
303 467 * @return void
304 468 */
305 469 function gutenberg_enqueue_stored_styles( $options = array() ) {
306 470 $is_block_theme = wp_is_block_theme();
@@ -321,9 +485,9 @@
321 485 $compiled_core_stylesheet = '';
322 486 $style_tag_id = 'core';
323 487 foreach ( $core_styles_keys as $style_key ) {
324 488 // Adds comment if code is prettified to identify core styles sections in debugging.
325 - $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : SCRIPT_DEBUG;
489 + $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
326 490 if ( $should_prettify ) {
327 491 $compiled_core_stylesheet .= "/**\n * Core styles: $style_key\n */\n";
328 492 }
329 493 // Chains core store ids to signify what the styles contain.
@@ -332,9 +496,9 @@
332 496 }
333 497
334 498 // Combines Core styles.
335 499 if ( ! empty( $compiled_core_stylesheet ) ) {
336 - wp_register_style( $style_tag_id, false, array(), true );
500 + wp_register_style( $style_tag_id, false, array(), true, true );
337 501 wp_add_inline_style( $style_tag_id, $compiled_core_stylesheet );
338 502 wp_enqueue_style( $style_tag_id );
339 503 }
340 504
@@ -355,9 +519,9 @@
355 519 }
356 520 $styles = gutenberg_style_engine_get_stylesheet_from_context( $store_name, $options );
357 521 if ( ! empty( $styles ) ) {
358 522 $key = "wp-style-engine-$store_name";
359 - wp_register_style( $key, false, array(), true );
523 + wp_register_style( $key, false, array(), true, true );
360 524 wp_add_inline_style( $key, $styles );
361 525 wp_enqueue_style( $key );
362 526 }
363 527 }
@@ -362,83 +526,9 @@
362 526 }
363 527 }
364 528 }
365 529
366 -/**
367 - * Registers vendor JavaScript files to be used as dependencies of the editor
368 - * and plugins.
369 - *
370 - * This function is called from a script during the plugin build process, so it
371 - * should not call any WordPress PHP functions.
372 - *
373 - * @since 13.0
374 - *
375 - * @param WP_Scripts $scripts WP_Scripts instance.
376 - */
377 -function gutenberg_register_vendor_scripts( $scripts ) {
378 - $extension = SCRIPT_DEBUG ? '.js' : '.min.js';
379 - $vendors_dir = gutenberg_dir_path() . 'build/scripts/vendors/';
380 -
381 - // When the React 19 experiment is enabled, register React 19 vendor
382 - // scripts under the `react`, `react-dom`, and `react-jsx-runtime` handles.
383 - $use_react_19 = gutenberg_is_experiment_enabled( 'gutenberg-react-19' );
384 -
385 - $vendor_handles = array( 'react', 'react-dom', 'react-jsx-runtime' );
386 -
387 - foreach ( $vendor_handles as $handle ) {
388 - $source = $use_react_19 ? $handle . '-19' : $handle;
389 - $asset_file = $vendors_dir . $source . '.min.asset.php';
390 - $asset = file_exists( $asset_file ) ? require $asset_file : array();
391 - $dependencies = $asset['dependencies'] ?? array();
392 - $version = $asset['version'] ?? '0';
393 -
394 - gutenberg_override_script(
395 - $scripts,
396 - $handle,
397 - gutenberg_url( 'build/scripts/vendors/' . $source . $extension ),
398 - $dependencies,
399 - $version
400 - );
401 - }
402 -
403 - // WordPress Core in `wp_register_development_scripts` sets `wp-react-refresh-entry`
404 - // as a dependency to `react` when `SCRIPT_DEBUG` is true. Preserve that here.
405 - if ( SCRIPT_DEBUG ) {
406 - $react = $scripts->query( 'react', 'registered' );
407 - if ( $react && ! in_array( 'wp-react-refresh-entry', $react->deps, true ) ) {
408 - $react->deps[] = 'wp-react-refresh-entry';
409 - }
410 - }
411 -}
412 -add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );
413 -
414 -/**
415 - * Registers or re-registers Gutenberg Script Modules.
416 - *
417 - * Script modules that are registered by Core will be re-registered by Gutenberg.
418 - *
419 - * @since 19.3.0
420 - */
421 -function gutenberg_define_interactivity_modules_support() {
422 - // Load the auto-generated module registry.
423 - $modules_registry_file = gutenberg_dir_path() . 'build/modules/index.php';
424 - if ( ! file_exists( $modules_registry_file ) ) {
425 - return;
426 - }
427 -
428 - $modules = require $modules_registry_file;
429 -
430 - // Add client navigation support to block library modules.
431 - foreach ( $modules as $module ) {
432 - if ( str_starts_with( $module['id'], '@wordpress/block-library' ) && method_exists( 'WP_Interactivity_API', 'add_client_navigation_support_to_script_module' ) ) {
433 - wp_interactivity()->add_client_navigation_support_to_script_module( $module['id'] );
434 - }
435 - }
436 -}
437 -remove_action( 'wp_default_scripts', 'wp_define_interactivity_modules_support' );
438 -add_action( 'wp_default_scripts', 'gutenberg_define_interactivity_modules_support' );
439 -
440 -/**
530 +/*
441 531 * Always remove the Core action hook while gutenberg_enqueue_stored_styles() exists to avoid styles being printed twice.
442 532 * This is also because gutenberg_enqueue_stored_styles uses the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes,
443 533 * which are in continuous development and generally ahead of Core.
444 534 */
@@ -447,43 +537,4 @@
447 537
448 538 // Enqueue stored styles.
449 539 add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_stored_styles' );
450 540 add_action( 'wp_footer', 'gutenberg_enqueue_stored_styles', 1 );
451 -
452 -/**
453 - * Enqueues the LaTeX to MathML loader script module in the block editor.
454 - */
455 -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_latex_to_mathml_loader' );
456 -function gutenberg_enqueue_latex_to_mathml_loader() {
457 - wp_enqueue_script_module( '@wordpress/latex-to-mathml/loader' );
458 -}
459 -
460 -/**
461 - * Enqueue the vips loader script module in the block editor.
462 - *
463 - * This registers @wordpress/vips/worker as a dynamic dependency in the import map,
464 - * enabling on-demand loading of the ~3.8MB WASM-based image processing module
465 - * when client-side media processing is triggered via @wordpress/upload-media.
466 - *
467 - * @see packages/vips/src/loader.ts
468 - */
469 -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_vips_loader' );
470 -function gutenberg_enqueue_vips_loader() {
471 - wp_enqueue_script_module( '@wordpress/vips/loader' );
472 -}
473 -
474 -/**
475 - * Enqueue the video-conversion loader script module in the block editor.
476 - *
477 - * This registers @wordpress/video-conversion/worker as a dynamic dependency
478 - * in the import map, enabling on-demand loading of the WebCodecs-based
479 - * GIF-to-video processing module when animated GIF conversion is triggered
480 - * via @wordpress/upload-media.
481 - *
482 - * @see packages/video-conversion/src/loader.ts
483 - */
484 -if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
485 - add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_video_conversion_loader' );
486 -}
487 -function gutenberg_enqueue_video_conversion_loader() {
488 - wp_enqueue_script_module( '@wordpress/video-conversion/loader' );
489 -}