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 +272 -208 23.5.314.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
28 - *
29 27 * @param string $path Relative path of the desired file.
30 28 *
31 29 * @return string Fully qualified URL pointing to the desired file.
30 + *
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,129 +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)
129 - $styles->query( 'wp-components', 'registered' )->deps[] = 'dashicons';
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' );
130 263
131 - // wp-edit-post: add wp-edit-blocks (custom handle not auto-inferred)
132 - $styles->query( 'wp-edit-post', 'registered' )->deps[] = 'wp-edit-blocks';
133 -
134 - // wp-edit-site: add core WP styles and custom handles
135 - $edit_site_style = $styles->query( 'wp-edit-site', 'registered' );
136 - $edit_site_style->deps[] = 'common';
137 - $edit_site_style->deps[] = 'forms';
138 - $edit_site_style->deps[] = 'wp-block-library-editor';
139 -
140 - // wp-edit-widgets: add wp-edit-blocks (custom handle not auto-inferred)
141 - $styles->query( 'wp-edit-widgets', 'registered' )->deps[] = 'wp-edit-blocks';
142 -
143 - // wp-customize-widgets: add wp-edit-blocks (custom handle not auto-inferred)
144 - $styles->query( 'wp-customize-widgets', 'registered' )->deps[] = 'wp-edit-blocks';
145 -
146 - // Register wp-theme (Design System tokens from @wordpress/theme) as a
147 - // dependency of wp-base-styles so its `:root` token block loads
148 - // everywhere wp-base-styles does, including the editor iframe via
149 - // $wp_edit_blocks_dependencies below.
150 264 gutenberg_override_style(
151 265 $styles,
152 - 'wp-theme',
153 - gutenberg_url( 'build/styles/theme/design-tokens' . $suffix . '.css' ),
154 - array(),
266 + 'wp-editor',
267 + gutenberg_url( 'build/editor/style.css' ),
268 + array( 'wp-components', 'wp-block-editor', 'wp-nux', 'wp-reusable-blocks' ),
155 269 $version
156 270 );
157 - $styles->add_data( 'wp-theme', 'rtl', 'replace' );
158 - $styles->add_data( 'wp-theme', 'suffix', $suffix );
159 - $styles->add_data( 'wp-theme', 'path', gutenberg_dir_path() . 'build/styles/theme/design-tokens' . $suffix . '.css' );
271 + $styles->add_data( 'wp-editor', 'rtl', 'replace' );
160 272
161 - // Register wp-base-styles and add it to the already registered wp-admin stylesheet
162 273 gutenberg_override_style(
163 274 $styles,
164 - 'wp-base-styles',
165 - gutenberg_url( 'build/styles/base-styles/admin-schemes' . $suffix . '.css' ),
166 - array( 'wp-theme' ),
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' ),
167 278 $version
168 279 );
169 - $styles->add_data( 'wp-base-styles', 'rtl', 'replace' );
170 - $styles->add_data( 'wp-base-styles', 'suffix', $suffix );
171 - $styles->add_data( 'wp-base-styles', 'path', gutenberg_dir_path() . 'build/styles/base-styles/admin-schemes' . $suffix . '.css' );
172 - $styles->query( 'wp-admin', 'registered' )->deps[] = 'wp-base-styles';
280 + $styles->add_data( 'wp-edit-post', 'rtl', 'replace' );
173 281
174 282 gutenberg_override_style(
175 283 $styles,
176 - 'wp-block-editor-content',
177 - gutenberg_url( 'build/styles/block-editor/content' . $suffix . '.css' ),
178 - array( 'wp-components' ),
284 + 'wp-components',
285 + gutenberg_url( 'build/components/style.css' ),
286 + array( 'dashicons' ),
179 287 $version
180 288 );
181 - $styles->add_data( 'wp-block-editor-content', 'rtl', 'replace' );
182 - $styles->add_data( 'wp-block-editor-content', 'suffix', $suffix );
289 + $styles->add_data( 'wp-components', 'rtl', 'replace' );
183 290
184 291 $block_library_filename = wp_should_load_separate_core_block_assets() ? 'common' : 'style';
185 292 gutenberg_override_style(
186 293 $styles,
187 294 'wp-block-library',
188 - gutenberg_url( 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' ),
295 + gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ),
189 296 array(),
190 297 $version
191 298 );
192 299 $styles->add_data( 'wp-block-library', 'rtl', 'replace' );
193 - $styles->add_data( 'wp-block-library', 'suffix', $suffix );
194 - $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' );
195 301
196 - // 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 +
197 311 $wp_edit_blocks_dependencies = array(
198 - // Design System tokens load first so the `:root` CSS custom
199 - // properties are defined before any consuming stylesheet reads
200 - // them inside the editor iframe.
201 - 'wp-theme',
202 312 'wp-components',
203 313 // This need to be added before the block library styles,
204 314 // The block library styles override the "reset" styles.
205 315 'wp-reset-editor-styles',
206 316 'wp-block-library',
207 - // Until #37466, we can't specifically add them as editor styles yet,
208 - // so we must hard-code it here as a dependency.
209 - 'wp-block-editor-content',
210 - 'wp-base-styles',
317 + 'wp-reusable-blocks',
211 318 );
212 319
213 320 // Only load the default layout and margin styles for themes without theme.json file.
214 321 if ( ! wp_theme_has_theme_json() ) {
@@ -223,67 +330,122 @@
223 330
224 331 gutenberg_override_style(
225 332 $styles,
226 333 'wp-reset-editor-styles',
227 - gutenberg_url( 'build/styles/block-library/reset' . $suffix . '.css' ),
334 + gutenberg_url( 'build/block-library/reset.css' ),
228 335 array( 'common', 'forms' ), // Make sure the reset is loaded after the default WP Admin styles.
229 336 $version
230 337 );
231 338 $styles->add_data( 'wp-reset-editor-styles', 'rtl', 'replace' );
232 - $styles->add_data( 'wp-reset-editor-styles', 'suffix', $suffix );
233 339
234 340 gutenberg_override_style(
235 341 $styles,
236 342 'wp-editor-classic-layout-styles',
237 - gutenberg_url( 'build/styles/edit-post/classic' . $suffix . '.css' ),
343 + gutenberg_url( 'build/edit-post/classic.css' ),
238 344 array(),
239 345 $version
240 346 );
241 347 $styles->add_data( 'wp-editor-classic-layout-styles', 'rtl', 'replace' );
242 - $styles->add_data( 'wp-editor-classic-layout-styles', 'suffix', $suffix );
243 348
244 349 gutenberg_override_style(
245 350 $styles,
246 - 'wp-block-library-editor',
247 - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ),
248 - array(),
351 + 'wp-edit-blocks',
352 + gutenberg_url( 'build/block-library/editor.css' ),
353 + $wp_edit_blocks_dependencies,
249 354 $version
250 355 );
251 - $styles->add_data( 'wp-block-library-editor', 'rtl', 'replace' );
252 - $styles->add_data( 'wp-block-library-editor', 'suffix', $suffix );
356 + $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' );
253 357
254 358 gutenberg_override_style(
255 359 $styles,
256 - 'wp-edit-blocks',
257 - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ),
258 - $wp_edit_blocks_dependencies,
360 + 'wp-nux',
361 + gutenberg_url( 'build/nux/style.css' ),
362 + array( 'wp-components' ),
259 363 $version
260 364 );
261 - $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' );
262 - $styles->add_data( 'wp-edit-blocks', 'suffix', $suffix );
365 + $styles->add_data( 'wp-nux', 'rtl', 'replace' );
263 366
264 367 gutenberg_override_style(
265 368 $styles,
266 369 'wp-block-library-theme',
267 - gutenberg_url( 'build/styles/block-library/theme' . $suffix . '.css' ),
370 + gutenberg_url( 'build/block-library/theme.css' ),
268 371 array(),
269 372 $version
270 373 );
271 374 $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' );
272 - $styles->add_data( 'wp-block-library-theme', 'suffix', $suffix );
273 375
274 376 gutenberg_override_style(
275 377 $styles,
276 - 'classic-theme-styles',
277 - gutenberg_url( 'build/styles/block-library/classic' . $suffix . '.css' ),
278 - array(),
378 + 'wp-list-reusable-blocks',
379 + gutenberg_url( 'build/list-reusable-blocks/style.css' ),
380 + array( 'wp-components' ),
279 381 $version
280 382 );
281 - $styles->add_data( 'classic-theme-styles', 'rtl', 'replace' );
282 - $styles->add_data( 'classic-theme-styles', 'suffix', $suffix );
283 - $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' );
284 446 }
285 -add_action( 'wp_default_styles', 'gutenberg_register_packages_styles', 15 );
447 +add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' );
286 448
287 449 /**
288 450 * Fetches, processes and compiles stored core styles, then combines and renders them to the page.
289 451 * Styles are stored via the Style Engine API.
@@ -290,12 +452,10 @@
290 452 *
291 453 * This hook also exists, and should be backported to Core in future versions.
292 454 * However, it is envisaged that Gutenberg will continue to use the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes to aid continuous development.
293 455 *
294 - * @since 6.1
456 + * See: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/
295 457 *
296 - * @link https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/
297 - *
298 458 * @param array $options {
299 459 * Optional. An array of options to pass to gutenberg_style_engine_get_stylesheet_from_context(). Default empty array.
300 460 *
301 461 * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
@@ -301,8 +461,10 @@
301 461 * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
302 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.
303 463 * }
304 464 *
465 + * @since 6.1
466 + *
305 467 * @return void
306 468 */
307 469 function gutenberg_enqueue_stored_styles( $options = array() ) {
308 470 $is_block_theme = wp_is_block_theme();
@@ -323,9 +485,9 @@
323 485 $compiled_core_stylesheet = '';
324 486 $style_tag_id = 'core';
325 487 foreach ( $core_styles_keys as $style_key ) {
326 488 // Adds comment if code is prettified to identify core styles sections in debugging.
327 - $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : SCRIPT_DEBUG;
489 + $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
328 490 if ( $should_prettify ) {
329 491 $compiled_core_stylesheet .= "/**\n * Core styles: $style_key\n */\n";
330 492 }
331 493 // Chains core store ids to signify what the styles contain.
@@ -334,9 +496,9 @@
334 496 }
335 497
336 498 // Combines Core styles.
337 499 if ( ! empty( $compiled_core_stylesheet ) ) {
338 - wp_register_style( $style_tag_id, false, array(), true );
500 + wp_register_style( $style_tag_id, false, array(), true, true );
339 501 wp_add_inline_style( $style_tag_id, $compiled_core_stylesheet );
340 502 wp_enqueue_style( $style_tag_id );
341 503 }
342 504
@@ -357,9 +519,9 @@
357 519 }
358 520 $styles = gutenberg_style_engine_get_stylesheet_from_context( $store_name, $options );
359 521 if ( ! empty( $styles ) ) {
360 522 $key = "wp-style-engine-$store_name";
361 - wp_register_style( $key, false, array(), true );
523 + wp_register_style( $key, false, array(), true, true );
362 524 wp_add_inline_style( $key, $styles );
363 525 wp_enqueue_style( $key );
364 526 }
365 527 }
@@ -364,83 +526,9 @@
364 526 }
365 527 }
366 528 }
367 529
368 -/**
369 - * Registers vendor JavaScript files to be used as dependencies of the editor
370 - * and plugins.
371 - *
372 - * This function is called from a script during the plugin build process, so it
373 - * should not call any WordPress PHP functions.
374 - *
375 - * @since 13.0
376 - *
377 - * @param WP_Scripts $scripts WP_Scripts instance.
378 - */
379 -function gutenberg_register_vendor_scripts( $scripts ) {
380 - $extension = SCRIPT_DEBUG ? '.js' : '.min.js';
381 - $vendors_dir = gutenberg_dir_path() . 'build/scripts/vendors/';
382 -
383 - // When the React 19 experiment is enabled, register React 19 vendor
384 - // scripts under the `react`, `react-dom`, and `react-jsx-runtime` handles.
385 - $use_react_19 = gutenberg_is_experiment_enabled( 'gutenberg-react-19' );
386 -
387 - $vendor_handles = array( 'react', 'react-dom', 'react-jsx-runtime' );
388 -
389 - foreach ( $vendor_handles as $handle ) {
390 - $source = $use_react_19 ? $handle . '-19' : $handle;
391 - $asset_file = $vendors_dir . $source . '.min.asset.php';
392 - $asset = file_exists( $asset_file ) ? require $asset_file : array();
393 - $dependencies = $asset['dependencies'] ?? array();
394 - $version = $asset['version'] ?? '0';
395 -
396 - gutenberg_override_script(
397 - $scripts,
398 - $handle,
399 - gutenberg_url( 'build/scripts/vendors/' . $source . $extension ),
400 - $dependencies,
401 - $version
402 - );
403 - }
404 -
405 - // WordPress Core in `wp_register_development_scripts` sets `wp-react-refresh-entry`
406 - // as a dependency to `react` when `SCRIPT_DEBUG` is true. Preserve that here.
407 - if ( SCRIPT_DEBUG ) {
408 - $react = $scripts->query( 'react', 'registered' );
409 - if ( $react && ! in_array( 'wp-react-refresh-entry', $react->deps, true ) ) {
410 - $react->deps[] = 'wp-react-refresh-entry';
411 - }
412 - }
413 -}
414 -add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );
415 -
416 -/**
417 - * Registers or re-registers Gutenberg Script Modules.
418 - *
419 - * Script modules that are registered by Core will be re-registered by Gutenberg.
420 - *
421 - * @since 19.3.0
422 - */
423 -function gutenberg_define_interactivity_modules_support() {
424 - // Load the auto-generated module registry.
425 - $modules_registry_file = gutenberg_dir_path() . 'build/modules/index.php';
426 - if ( ! file_exists( $modules_registry_file ) ) {
427 - return;
428 - }
429 -
430 - $modules = require $modules_registry_file;
431 -
432 - // Add client navigation support to block library modules.
433 - foreach ( $modules as $module ) {
434 - if ( str_starts_with( $module['id'], '@wordpress/block-library' ) && method_exists( 'WP_Interactivity_API', 'add_client_navigation_support_to_script_module' ) ) {
435 - wp_interactivity()->add_client_navigation_support_to_script_module( $module['id'] );
436 - }
437 - }
438 -}
439 -remove_action( 'wp_default_scripts', 'wp_define_interactivity_modules_support' );
440 -add_action( 'wp_default_scripts', 'gutenberg_define_interactivity_modules_support' );
441 -
442 -/**
530 +/*
443 531 * Always remove the Core action hook while gutenberg_enqueue_stored_styles() exists to avoid styles being printed twice.
444 532 * This is also because gutenberg_enqueue_stored_styles uses the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes,
445 533 * which are in continuous development and generally ahead of Core.
446 534 */
@@ -449,28 +537,4 @@
449 537
450 538 // Enqueue stored styles.
451 539 add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_stored_styles' );
452 540 add_action( 'wp_footer', 'gutenberg_enqueue_stored_styles', 1 );
453 -
454 -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_latex_to_mathml_loader' );
455 -function gutenberg_enqueue_latex_to_mathml_loader() {
456 - wp_enqueue_script_module( '@wordpress/latex-to-mathml/loader' );
457 -}
458 -
459 -/**
460 - * Enqueue the vips loader script module in the block editor.
461 - *
462 - * This registers @wordpress/vips/worker as a dynamic dependency in the import map,
463 - * enabling on-demand loading of the ~3.8MB WASM-based image processing module
464 - * when client-side media processing is triggered via @wordpress/upload-media.
465 - *
466 - * @see packages/vips/src/loader.ts
467 - */
468 -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_vips_loader' );
469 -function gutenberg_enqueue_vips_loader() {
470 - wp_enqueue_script_module( '@wordpress/vips/loader' );
471 -}
472 -
473 -add_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_core_abilities' );
474 -function gutenberg_enqueue_core_abilities() {
475 - wp_enqueue_script_module( '@wordpress/core-abilities' );
476 -}