PluginProbe
Gutenberg / 12.6.0
Gutenberg v12.6.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 7.4.0 All 402 releases
gutenberg / lib / client-assets.php

client-assets.php in Gutenberg 12.6.0, at lib/client-assets.php

678 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions to register client-side assets (scripts and stylesheets) for the
4 * Gutenberg editor plugin.
5 *
6 * @package gutenberg
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 die( 'Silence is golden.' );
11 }
12
13 /**
14 * Retrieves the root plugin path.
15 *
16 * @return string Root path to the gutenberg plugin.
17 *
18 * @since 0.1.0
19 */
20 function gutenberg_dir_path() {
21 return plugin_dir_path( __DIR__ );
22 }
23
24 /**
25 * Retrieves a URL to a file in the gutenberg plugin.
26 *
27 * @param string $path Relative path of the desired file.
28 *
29 * @return string Fully qualified URL pointing to the desired file.
30 *
31 * @since 0.1.0
32 */
33 function gutenberg_url( $path ) {
34 return plugins_url( $path, __DIR__ );
35 }
36
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 $script = $scripts->query( $handle, 'registered' );
58 if ( $script ) {
59 /*
60 * In many ways, this is a reimplementation of `wp_register_script` but
61 * bypassing consideration of whether a script by the given handle had
62 * already been registered.
63 */
64
65 // See: `_WP_Dependency::__construct` .
66 $script->src = $src;
67 $script->deps = $deps;
68 $script->ver = $ver;
69 $script->args = $in_footer;
70
71 /*
72 * The script's `group` designation is an indication of whether it is
73 * to be printed in the header or footer. The behavior here defers to
74 * the arguments as passed. Specifically, group data is not assigned
75 * for a script unless it is designated to be printed in the footer.
76 */
77
78 // See: `wp_register_script` .
79 unset( $script->extra['group'] );
80 if ( $in_footer ) {
81 $script->add_data( 'group', 1 );
82 }
83 } else {
84 $scripts->add( $handle, $src, $deps, $ver, $in_footer );
85 }
86
87 /*
88 * `WP_Dependencies::set_translations` will fall over on itself if setting
89 * translations on the `wp-i18n` handle, since it internally adds `wp-i18n`
90 * as a dependency of itself, exhausting memory. The same applies for the
91 * polyfill and hooks scripts, which are dependencies _of_ `wp-i18n`.
92 *
93 * See: https://core.trac.wordpress.org/ticket/46089
94 */
95 if ( ! in_array( $handle, array( 'wp-i18n', 'wp-polyfill', 'wp-hooks' ), true ) ) {
96 $scripts->set_translations( $handle, 'default' );
97 }
98
99 /*
100 * Wp-editor module is exposed as window.wp.editor.
101 * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
102 * Solution: fuse the two objects together to maintain backward compatibility.
103 * For more context, see https://github.com/WordPress/gutenberg/issues/33203
104 */
105 if ( 'wp-editor' === $handle ) {
106 $scripts->add_inline_script(
107 'wp-editor',
108 'Object.assign( window.wp.editor, window.wp.oldEditor );',
109 'after'
110 );
111 }
112 }
113
114 /**
115 * Filters the default translation file load behavior to load the Gutenberg
116 * plugin translation file, if available.
117 *
118 * @param string|false $file Path to the translation file to load. False if
119 * there isn't one.
120 * @param string $handle Name of the script to register a translation
121 * domain to.
122 *
123 * @return string|false Filtered path to the Gutenberg translation file, if
124 * available.
125 */
126 function gutenberg_override_translation_file( $file, $handle ) {
127 if ( ! $file ) {
128 return $file;
129 }
130
131 // Ignore scripts whose handle does not have the "wp-" prefix.
132 if ( 'wp-' !== substr( $handle, 0, 3 ) ) {
133 return $file;
134 }
135
136 // Ignore scripts that are not found in the expected `build/` location.
137 $script_path = gutenberg_dir_path() . 'build/' . substr( $handle, 3 ) . '/index.min.js';
138 if ( ! file_exists( $script_path ) ) {
139 return $file;
140 }
141
142 /*
143 * The default file will be in the plugins language directory, omitting the
144 * domain since Gutenberg assigns the script translations as the default.
145 *
146 * Example: /www/wp-content/languages/plugins/de_DE-07d88e6a803e01276b9bfcc1203e862e.json
147 *
148 * The logic of `load_script_textdomain` is such that it will assume to
149 * search in the plugins language directory, since the assigned source of
150 * the overridden Gutenberg script originates in the plugins directory.
151 *
152 * The plugin translation files each begin with the slug of the plugin, so
153 * it's a simple matter of prepending the Gutenberg plugin slug.
154 */
155 $path_parts = pathinfo( $file );
156 $plugin_translation_file = (
157 $path_parts['dirname'] .
158 '/gutenberg-' .
159 $path_parts['basename']
160 );
161
162 return $plugin_translation_file;
163 }
164 add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 );
165
166 /**
167 * Registers a style according to `wp_register_style`. Honors this request by
168 * deregistering any style by the same handler before registration.
169 *
170 * @since 4.1.0
171 *
172 * @param WP_Styles $styles WP_Styles instance.
173 * @param string $handle Name of the stylesheet. Should be unique.
174 * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
175 * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
176 * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
177 * as a query string for cache busting purposes. If version is set to false, a version
178 * number is automatically added equal to current installed WordPress version.
179 * If set to null, no version is added.
180 * @param string $media Optional. The media for which this stylesheet has been defined.
181 * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
182 * '(orientation: portrait)' and '(max-width: 640px)'.
183 */
184 function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
185 $style = $styles->query( $handle, 'registered' );
186 if ( $style ) {
187 $styles->remove( $handle );
188 }
189 $styles->add( $handle, $src, $deps, $ver, $media );
190 }
191
192 /**
193 * Registers vendor JavaScript files to be used as dependencies of the editor
194 * and plugins.
195 *
196 * This function is called from a script during the plugin build process, so it
197 * should not call any WordPress PHP functions.
198 *
199 * @since 0.1.0
200 *
201 * @param WP_Scripts $scripts WP_Scripts instance.
202 */
203 function gutenberg_register_vendor_scripts( $scripts ) {
204 $suffix = SCRIPT_DEBUG ? '' : '.min';
205
206 $react_suffix = ( SCRIPT_DEBUG ? '.development' : '.production' ) . $suffix;
207 gutenberg_register_vendor_script(
208 $scripts,
209 'react',
210 'https://unpkg.com/react@17.0.1/umd/react' . $react_suffix . '.js',
211 // See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react.
212 SCRIPT_DEBUG ? array( 'wp-react-refresh-entry', 'wp-polyfill' ) : array( 'wp-polyfill' )
213 );
214 gutenberg_register_vendor_script(
215 $scripts,
216 'react-dom',
217 'https://unpkg.com/react-dom@17.0.1/umd/react-dom' . $react_suffix . '.js',
218 array( 'react' )
219 );
220 }
221 add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );
222
223 /**
224 * Registers all the WordPress packages scripts that are in the standardized
225 * `build/` location.
226 *
227 * @since 4.5.0
228 *
229 * @param WP_Scripts $scripts WP_Scripts instance.
230 */
231 function gutenberg_register_packages_scripts( $scripts ) {
232 // When in production, use the plugin's version as the default asset version;
233 // else (for development or test) default to use the current time.
234 $default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time();
235
236 foreach ( glob( gutenberg_dir_path() . 'build/*/index.min.js' ) as $path ) {
237 // Prefix `wp-` to package directory to get script handle.
238 // For example, `…/build/a11y/index.min.js` becomes `wp-a11y`.
239 $handle = 'wp-' . basename( dirname( $path ) );
240
241 // Replace extension with `.asset.php` to find the generated dependencies file.
242 $asset_file = substr( $path, 0, -( strlen( '.js' ) ) ) . '.asset.php';
243 $asset = file_exists( $asset_file )
244 ? require( $asset_file )
245 : null;
246 $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
247 $version = isset( $asset['version'] ) ? $asset['version'] : $default_version;
248
249 // Add dependencies that cannot be detected and generated by build tools.
250 switch ( $handle ) {
251 case 'wp-block-library':
252 array_push( $dependencies, 'editor' );
253 break;
254
255 case 'wp-edit-post':
256 array_push( $dependencies, 'media-models', 'media-views', 'postbox' );
257 break;
258
259 case 'wp-edit-site':
260 array_push( $dependencies, 'wp-dom-ready' );
261 break;
262 }
263
264 // Get the path from Gutenberg directory as expected by `gutenberg_url`.
265 $gutenberg_path = substr( $path, strlen( gutenberg_dir_path() ) );
266
267 gutenberg_override_script(
268 $scripts,
269 $handle,
270 gutenberg_url( $gutenberg_path ),
271 $dependencies,
272 $version,
273 true
274 );
275 }
276 }
277 add_action( 'wp_default_scripts', 'gutenberg_register_packages_scripts' );
278
279 /**
280 * Registers all the WordPress packages styles that are in the standardized
281 * `build/` location.
282 *
283 * @since 6.7.0
284
285 * @param WP_Styles $styles WP_Styles instance.
286 */
287 function gutenberg_register_packages_styles( $styles ) {
288 // When in production, use the plugin's version as the asset version;
289 // else (for development or test) default to use the current time.
290 $version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time();
291
292 // Editor Styles.
293 gutenberg_override_style(
294 $styles,
295 'wp-block-editor',
296 gutenberg_url( 'build/block-editor/style.css' ),
297 array( 'wp-components' ),
298 $version
299 );
300 $styles->add_data( 'wp-block-editor', 'rtl', 'replace' );
301
302 gutenberg_override_style(
303 $styles,
304 'wp-editor',
305 gutenberg_url( 'build/editor/style.css' ),
306 array( 'wp-components', 'wp-block-editor', 'wp-nux', 'wp-reusable-blocks' ),
307 $version
308 );
309 $styles->add_data( 'wp-editor', 'rtl', 'replace' );
310
311 gutenberg_override_style(
312 $styles,
313 'wp-edit-post',
314 gutenberg_url( 'build/edit-post/style.css' ),
315 array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-block-library', 'wp-nux' ),
316 $version
317 );
318 $styles->add_data( 'wp-edit-post', 'rtl', 'replace' );
319
320 gutenberg_override_style(
321 $styles,
322 'wp-components',
323 gutenberg_url( 'build/components/style.css' ),
324 array( 'dashicons' ),
325 $version
326 );
327 $styles->add_data( 'wp-components', 'rtl', 'replace' );
328
329 $block_library_filename = wp_should_load_separate_core_block_assets() ? 'common' : 'style';
330 gutenberg_override_style(
331 $styles,
332 'wp-block-library',
333 gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ),
334 array(),
335 $version
336 );
337 $styles->add_data( 'wp-block-library', 'rtl', 'replace' );
338 $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/block-library/' . $block_library_filename . '.css' );
339
340 gutenberg_override_style(
341 $styles,
342 'wp-format-library',
343 gutenberg_url( 'build/format-library/style.css' ),
344 array( 'wp-block-editor', 'wp-components' ),
345 $version
346 );
347 $styles->add_data( 'wp-format-library', 'rtl', 'replace' );
348
349 $wp_edit_blocks_dependencies = array(
350 'wp-components',
351 'wp-editor',
352 // This need to be added before the block library styles,
353 // The block library styles override the "reset" styles.
354 'wp-reset-editor-styles',
355 'wp-block-library',
356 'wp-reusable-blocks',
357 );
358
359 // Only load the default layout and margin styles for themes without theme.json file.
360 if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
361 $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
362 }
363
364 global $editor_styles;
365 if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) {
366 // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken.
367 $wp_edit_blocks_dependencies[] = 'wp-block-library-theme';
368 }
369
370 gutenberg_override_style(
371 $styles,
372 'wp-reset-editor-styles',
373 gutenberg_url( 'build/block-library/reset.css' ),
374 array( 'common', 'forms' ), // Make sure the reset is loaded after the default WP Admin styles.
375 $version
376 );
377 $styles->add_data( 'wp-reset-editor-styles', 'rtl', 'replace' );
378
379 gutenberg_override_style(
380 $styles,
381 'wp-editor-classic-layout-styles',
382 gutenberg_url( 'build/edit-post/classic.css' ),
383 array(),
384 $version
385 );
386 $styles->add_data( 'wp-editor-classic-layout-styles', 'rtl', 'replace' );
387
388 gutenberg_override_style(
389 $styles,
390 'wp-edit-blocks',
391 gutenberg_url( 'build/block-library/editor.css' ),
392 $wp_edit_blocks_dependencies,
393 $version
394 );
395 $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' );
396
397 gutenberg_override_style(
398 $styles,
399 'wp-nux',
400 gutenberg_url( 'build/nux/style.css' ),
401 array( 'wp-components' ),
402 $version
403 );
404 $styles->add_data( 'wp-nux', 'rtl', 'replace' );
405
406 gutenberg_override_style(
407 $styles,
408 'wp-block-library-theme',
409 gutenberg_url( 'build/block-library/theme.css' ),
410 array(),
411 $version
412 );
413 $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' );
414
415 gutenberg_override_style(
416 $styles,
417 'wp-list-reusable-blocks',
418 gutenberg_url( 'build/list-reusable-blocks/style.css' ),
419 array( 'wp-components' ),
420 $version
421 );
422 $styles->add_data( 'wp-list-reusable-block', 'rtl', 'replace' );
423
424 gutenberg_override_style(
425 $styles,
426 'wp-edit-navigation',
427 gutenberg_url( 'build/edit-navigation/style.css' ),
428 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
429 $version
430 );
431 $styles->add_data( 'wp-edit-navigation', 'rtl', 'replace' );
432
433 gutenberg_override_style(
434 $styles,
435 'wp-edit-site',
436 gutenberg_url( 'build/edit-site/style.css' ),
437 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
438 $version
439 );
440 $styles->add_data( 'wp-edit-site', 'rtl', 'replace' );
441
442 gutenberg_override_style(
443 $styles,
444 'wp-edit-widgets',
445 gutenberg_url( 'build/edit-widgets/style.css' ),
446 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks', 'wp-reusable-blocks', 'wp-widgets' ),
447 $version
448 );
449 $styles->add_data( 'wp-edit-widgets', 'rtl', 'replace' );
450
451 gutenberg_override_style(
452 $styles,
453 'wp-block-directory',
454 gutenberg_url( 'build/block-directory/style.css' ),
455 array( 'wp-block-editor', 'wp-components' ),
456 $version
457 );
458 $styles->add_data( 'wp-block-directory', 'rtl', 'replace' );
459
460 gutenberg_override_style(
461 $styles,
462 'wp-customize-widgets',
463 gutenberg_url( 'build/customize-widgets/style.css' ),
464 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks', 'wp-widgets' ),
465 $version
466 );
467 $styles->add_data( 'wp-customize-widgets', 'rtl', 'replace' );
468
469 gutenberg_override_style(
470 $styles,
471 'wp-reusable-blocks',
472 gutenberg_url( 'build/reusable-blocks/style.css' ),
473 array( 'wp-components' ),
474 $version
475 );
476 $styles->add_data( 'wp-reusable-block', 'rtl', 'replace' );
477
478 gutenberg_override_style(
479 $styles,
480 'wp-widgets',
481 gutenberg_url( 'build/widgets/style.css' ),
482 array( 'wp-components' )
483 );
484 $styles->add_data( 'wp-widgets', 'rtl', 'replace' );
485 }
486 add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' );
487
488 /**
489 * Retrieves a unique and reasonably short and human-friendly filename for a
490 * vendor script based on a URL and the script handle.
491 *
492 * @param string $handle The name of the script.
493 * @param string $src Full URL of the external script.
494 *
495 * @return string Script filename suitable for local caching.
496 *
497 * @since 0.1.0
498 */
499 function gutenberg_vendor_script_filename( $handle, $src ) {
500 $filename = basename( $src );
501 $match = preg_match(
502 '/^'
503 . '(?P<ignore>.*?)'
504 . '(?P<suffix>\.min)?'
505 . '(?P<extension>\.js)'
506 . '(?P<extra>.*)'
507 . '$/',
508 $filename,
509 $filename_pieces
510 );
511
512 $prefix = $handle;
513 $suffix = $match ? $filename_pieces['suffix'] : '';
514 $hash = substr( md5( $src ), 0, 8 );
515
516 return "${prefix}${suffix}.${hash}.js";
517 }
518
519 /**
520 * Registers a vendor script from a URL, preferring a locally cached version if
521 * possible, or downloading it if the cached version is unavailable or
522 * outdated.
523 *
524 * @param WP_Scripts $scripts WP_Scripts instance.
525 * @param string $handle Name of the script.
526 * @param string $src Full URL of the external script.
527 * @param array $deps Optional. An array of registered script handles this
528 * script depends on.
529 * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
530 * as a query string for cache busting purposes. If version is set to false, a version
531 * number is automatically added equal to current installed WordPress version.
532 * If set to null, no version is added.
533 * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
534 * Default 'false'.
535 *
536 * @since 0.1.0
537 */
538 function gutenberg_register_vendor_script( $scripts, $handle, $src, $deps = array(), $ver = null, $in_footer = false ) {
539 if ( defined( 'GUTENBERG_LOAD_VENDOR_SCRIPTS' ) && ! GUTENBERG_LOAD_VENDOR_SCRIPTS ) {
540 return;
541 }
542
543 $filename = gutenberg_vendor_script_filename( $handle, $src );
544
545 if ( defined( 'GUTENBERG_LIST_VENDOR_ASSETS' ) && GUTENBERG_LIST_VENDOR_ASSETS ) {
546 echo "$src|$filename\n";
547 return;
548 }
549
550 $full_path = gutenberg_dir_path() . 'vendor/' . $filename;
551
552 $needs_fetch = (
553 defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && (
554 ! file_exists( $full_path ) ||
555 time() - filemtime( $full_path ) >= DAY_IN_SECONDS
556 )
557 );
558
559 if ( $needs_fetch ) {
560 // Determine whether we can write to this file. If not, don't waste
561 // time doing a network request.
562 // @codingStandardsIgnoreStart
563
564 $is_writable = is_writable( $full_path );
565 if ( $is_writable ) {
566 $f = @fopen( $full_path, 'a' );
567 if ( ! $f ) {
568 $is_writable = false;
569 } else {
570 fclose( $f );
571 }
572 }
573
574 // @codingStandardsIgnoreEnd
575 if ( ! $is_writable ) {
576 // Failed to open the file for writing, probably due to server
577 // permissions. Enqueue the script directly from the URL instead.
578 gutenberg_override_script( $scripts, $handle, $src, $deps, $ver, $in_footer );
579 return;
580 }
581
582 $response = wp_remote_get( $src );
583 if ( wp_remote_retrieve_response_code( $response ) === 200 ) {
584 $f = fopen( $full_path, 'w' );
585 fwrite( $f, wp_remote_retrieve_body( $response ) );
586 fclose( $f );
587 } elseif ( ! filesize( $full_path ) ) {
588 // The request failed. If the file is already cached, continue to
589 // use this file. If not, then unlink the 0 byte file, and enqueue
590 // the script directly from the URL.
591 gutenberg_override_script( $scripts, $handle, $src, $deps, $ver, $in_footer );
592 unlink( $full_path );
593 return;
594 }
595 }
596 gutenberg_override_script(
597 $scripts,
598 $handle,
599 gutenberg_url( 'vendor/' . $filename ),
600 $deps,
601 $ver,
602 $in_footer
603 );
604 }
605
606 /**
607 * Sets the editor styles to be consumed by JS.
608 */
609 function gutenberg_resolve_assets() {
610 global $pagenow;
611
612 $script_handles = array();
613 $style_handles = array(
614 'wp-block-editor',
615 'wp-block-library',
616 'wp-block-library-theme',
617 'wp-edit-blocks',
618 );
619
620 if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
621 $style_handles[] = 'wp-widgets';
622 $style_handles[] = 'wp-edit-widgets';
623 }
624
625 $block_registry = WP_Block_Type_Registry::get_instance();
626
627 foreach ( $block_registry->get_all_registered() as $block_type ) {
628 if ( ! empty( $block_type->style ) ) {
629 $style_handles[] = $block_type->style;
630 }
631
632 if ( ! empty( $block_type->editor_style ) ) {
633 $style_handles[] = $block_type->editor_style;
634 }
635
636 if ( ! empty( $block_type->script ) ) {
637 $script_handles[] = $block_type->script;
638 }
639 }
640
641 $style_handles = array_unique( $style_handles );
642 $done = wp_styles()->done;
643
644 ob_start();
645
646 // We do not need reset styles for the iframed editor.
647 wp_styles()->done = array( 'wp-reset-editor-styles' );
648 wp_styles()->do_items( $style_handles );
649 wp_styles()->done = $done;
650
651 $styles = ob_get_clean();
652
653 $script_handles = array_unique( $script_handles );
654 $done = wp_scripts()->done;
655
656 ob_start();
657
658 wp_scripts()->done = array();
659 wp_scripts()->do_items( $script_handles );
660 wp_scripts()->done = $done;
661
662 $scripts = ob_get_clean();
663
664 return array(
665 'styles' => $styles,
666 'scripts' => $scripts,
667 );
668 }
669
670 add_filter(
671 'block_editor_settings_all',
672 function( $settings ) {
673 // In the future we can allow WP Dependency handles to be passed.
674 $settings['__unstableResolvedAssets'] = gutenberg_resolve_assets();
675 return $settings;
676 }
677 );
678