PluginProbe
Gutenberg / 8.5.1
Gutenberg v8.5.1
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 +266 -190 12.6.08.5.1 View file →
@@ -17,9 +17,9 @@
17 17 *
18 18 * @since 0.1.0
19 19 */
20 20 function gutenberg_dir_path() {
21 - return plugin_dir_path( __DIR__ );
21 + return plugin_dir_path( dirname( __FILE__ ) );
22 22 }
23 23
24 24 /**
25 25 * Retrieves a URL to a file in the gutenberg plugin.
@@ -30,9 +30,9 @@
30 30 *
31 31 * @since 0.1.0
32 32 */
33 33 function gutenberg_url( $path ) {
34 - return plugins_url( $path, __DIR__ );
34 + return plugins_url( $path, dirname( __FILE__ ) );
35 35 }
36 36
37 37 /**
38 38 * Registers a script according to `wp_register_script`. Honors this request by
@@ -87,29 +87,15 @@
87 87 /*
88 88 * `WP_Dependencies::set_translations` will fall over on itself if setting
89 89 * translations on the `wp-i18n` handle, since it internally adds `wp-i18n`
90 90 * as a dependency of itself, exhausting memory. The same applies for the
91 - * polyfill and hooks scripts, which are dependencies _of_ `wp-i18n`.
91 + * polyfill script, which is a dependency _of_ `wp-i18n`.
92 92 *
93 93 * See: https://core.trac.wordpress.org/ticket/46089
94 94 */
95 - if ( ! in_array( $handle, array( 'wp-i18n', 'wp-polyfill', 'wp-hooks' ), true ) ) {
95 + if ( 'wp-i18n' !== $handle && 'wp-polyfill' !== $handle ) {
96 96 $scripts->set_translations( $handle, 'default' );
97 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 98 }
113 99
114 100 /**
115 101 * Filters the default translation file load behavior to load the Gutenberg
@@ -133,9 +119,9 @@
133 119 return $file;
134 120 }
135 121
136 122 // Ignore scripts that are not found in the expected `build/` location.
137 - $script_path = gutenberg_dir_path() . 'build/' . substr( $handle, 3 ) . '/index.min.js';
123 + $script_path = gutenberg_dir_path() . 'build/' . substr( $handle, 3 ) . '/index.js';
138 124 if ( ! file_exists( $script_path ) ) {
139 125 return $file;
140 126 }
141 127
@@ -163,8 +149,27 @@
163 149 }
164 150 add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 );
165 151
166 152 /**
153 + * Filters the default labels for common post types to change the case style
154 + * from capitalized (e.g. "Featured Image") to sentence-style (e.g. "Featured
155 + * image").
156 + *
157 + * See: https://github.com/WordPress/gutenberg/pull/18758
158 + *
159 + * @param object $labels Object with all the labels as member variables.
160 + *
161 + * @return object Object with all the labels, including overridden ones.
162 + */
163 +function gutenberg_override_posttype_labels( $labels ) {
164 + $labels->featured_image = __( 'Featured image', 'gutenberg' );
165 + return $labels;
166 +}
167 +foreach ( array( 'post', 'page' ) as $post_type ) {
168 + add_filter( "post_type_labels_{$post_type}", 'gutenberg_override_posttype_labels' );
169 +}
170 +
171 +/**
167 172 * Registers a style according to `wp_register_style`. Honors this request by
168 173 * deregistering any style by the same handler before registration.
169 174 *
170 175 * @since 4.1.0
@@ -202,21 +207,34 @@
202 207 */
203 208 function gutenberg_register_vendor_scripts( $scripts ) {
204 209 $suffix = SCRIPT_DEBUG ? '' : '.min';
205 210
206 - $react_suffix = ( SCRIPT_DEBUG ? '.development' : '.production' ) . $suffix;
211 + /*
212 + * This script registration and the corresponding function should be removed
213 + * once the plugin is updated to support WordPress 5.4.0 and newer.
214 + *
215 + * See: `gutenberg_add_url_polyfill`
216 + */
207 217 gutenberg_register_vendor_script(
208 218 $scripts,
209 - 'react',
210 - 'https://unpkg.com/[email protected]/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' )
219 + 'wp-polyfill-url',
220 + 'https://unpkg.com/[email protected]/url' . $suffix . '.js',
221 + array(),
222 + '3.6.4'
213 223 );
224 +
225 + /*
226 + * This script registration and the corresponding function should be removed
227 + * removed once the plugin is updated to support WordPress 5.4.0 and newer.
228 + *
229 + * See: `gutenberg_add_dom_rect_polyfill`
230 + */
214 231 gutenberg_register_vendor_script(
215 232 $scripts,
216 - 'react-dom',
217 - 'https://unpkg.com/[email protected]/umd/react-dom' . $react_suffix . '.js',
218 - array( 'react' )
233 + 'wp-polyfill-dom-rect',
234 + 'https://unpkg.com/[email protected]/polyfills/DOMRect/polyfill.js',
235 + array(),
236 + '3.42.0'
219 237 );
220 238 }
221 239 add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );
222 240
@@ -228,24 +246,20 @@
228 246 *
229 247 * @param WP_Scripts $scripts WP_Scripts instance.
230 248 */
231 249 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 ) {
250 + foreach ( glob( gutenberg_dir_path() . 'build/*/index.js' ) as $path ) {
237 251 // Prefix `wp-` to package directory to get script handle.
238 - // For example, `…/build/a11y/index.min.js` becomes `wp-a11y`.
252 + // For example, `…/build/a11y/index.js` becomes `wp-a11y`.
239 253 $handle = 'wp-' . basename( dirname( $path ) );
240 254
241 - // Replace extension with `.asset.php` to find the generated dependencies file.
242 - $asset_file = substr( $path, 0, -( strlen( '.js' ) ) ) . '.asset.php';
255 + // Replace `.js` extension with `.asset.php` to find the generated dependencies file.
256 + $asset_file = substr( $path, 0, -3 ) . '.asset.php';
243 257 $asset = file_exists( $asset_file )
244 258 ? require( $asset_file )
245 259 : null;
246 260 $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
247 - $version = isset( $asset['version'] ) ? $asset['version'] : $default_version;
261 + $version = isset( $asset['version'] ) ? $asset['version'] : filemtime( $path );
248 262
249 263 // Add dependencies that cannot be detected and generated by build tools.
250 264 switch ( $handle ) {
251 265 case 'wp-block-library':
@@ -284,19 +298,15 @@
284 298
285 299 * @param WP_Styles $styles WP_Styles instance.
286 300 */
287 301 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 302 // Editor Styles.
293 303 gutenberg_override_style(
294 304 $styles,
295 305 'wp-block-editor',
296 306 gutenberg_url( 'build/block-editor/style.css' ),
297 - array( 'wp-components' ),
298 - $version
307 + array( 'wp-components', 'wp-editor-font' ),
308 + filemtime( gutenberg_dir_path() . 'build/editor/style.css' )
299 309 );
300 310 $styles->add_data( 'wp-block-editor', 'rtl', 'replace' );
301 311
302 312 gutenberg_override_style(
@@ -302,10 +312,10 @@
302 312 gutenberg_override_style(
303 313 $styles,
304 314 'wp-editor',
305 315 gutenberg_url( 'build/editor/style.css' ),
306 - array( 'wp-components', 'wp-block-editor', 'wp-nux', 'wp-reusable-blocks' ),
307 - $version
316 + array( 'wp-components', 'wp-block-editor', 'wp-nux' ),
317 + filemtime( gutenberg_dir_path() . 'build/editor/style.css' )
308 318 );
309 319 $styles->add_data( 'wp-editor', 'rtl', 'replace' );
310 320
311 321 gutenberg_override_style(
@@ -312,9 +322,9 @@
312 322 $styles,
313 323 'wp-edit-post',
314 324 gutenberg_url( 'build/edit-post/style.css' ),
315 325 array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-block-library', 'wp-nux' ),
316 - $version
326 + filemtime( gutenberg_dir_path() . 'build/edit-post/style.css' )
317 327 );
318 328 $styles->add_data( 'wp-edit-post', 'rtl', 'replace' );
319 329
320 330 gutenberg_override_style(
@@ -320,23 +330,21 @@
320 330 gutenberg_override_style(
321 331 $styles,
322 332 'wp-components',
323 333 gutenberg_url( 'build/components/style.css' ),
324 - array( 'dashicons' ),
325 - $version
334 + array(),
335 + filemtime( gutenberg_dir_path() . 'build/components/style.css' )
326 336 );
327 337 $styles->add_data( 'wp-components', 'rtl', 'replace' );
328 338
329 - $block_library_filename = wp_should_load_separate_core_block_assets() ? 'common' : 'style';
330 339 gutenberg_override_style(
331 340 $styles,
332 341 'wp-block-library',
333 - gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ),
342 + gutenberg_url( 'build/block-library/style.css' ),
334 343 array(),
335 - $version
344 + filemtime( gutenberg_dir_path() . 'build/block-library/style.css' )
336 345 );
337 346 $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 347
340 348 gutenberg_override_style(
341 349 $styles,
342 350 'wp-format-library',
@@ -341,57 +349,24 @@
341 349 $styles,
342 350 'wp-format-library',
343 351 gutenberg_url( 'build/format-library/style.css' ),
344 352 array( 'wp-block-editor', 'wp-components' ),
345 - $version
353 + filemtime( gutenberg_dir_path() . 'build/format-library/style.css' )
346 354 );
347 355 $styles->add_data( 'wp-format-library', 'rtl', 'replace' );
348 356
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 357 gutenberg_override_style(
371 358 $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 359 'wp-edit-blocks',
391 360 gutenberg_url( 'build/block-library/editor.css' ),
392 - $wp_edit_blocks_dependencies,
393 - $version
361 + array(
362 + 'wp-components',
363 + 'wp-editor',
364 + 'wp-block-library',
365 + // Always include visual styles so the editor never appears broken.
366 + 'wp-block-library-theme',
367 + ),
368 + filemtime( gutenberg_dir_path() . 'build/block-library/editor.css' )
394 369 );
395 370 $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' );
396 371
397 372 gutenberg_override_style(
@@ -398,9 +373,9 @@
398 373 $styles,
399 374 'wp-nux',
400 375 gutenberg_url( 'build/nux/style.css' ),
401 376 array( 'wp-components' ),
402 - $version
377 + filemtime( gutenberg_dir_path() . 'build/nux/style.css' )
403 378 );
404 379 $styles->add_data( 'wp-nux', 'rtl', 'replace' );
405 380
406 381 gutenberg_override_style(
@@ -407,9 +382,9 @@
407 382 $styles,
408 383 'wp-block-library-theme',
409 384 gutenberg_url( 'build/block-library/theme.css' ),
410 385 array(),
411 - $version
386 + filemtime( gutenberg_dir_path() . 'build/block-library/theme.css' )
412 387 );
413 388 $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' );
414 389
415 390 gutenberg_override_style(
@@ -416,9 +391,9 @@
416 391 $styles,
417 392 'wp-list-reusable-blocks',
418 393 gutenberg_url( 'build/list-reusable-blocks/style.css' ),
419 394 array( 'wp-components' ),
420 - $version
395 + filemtime( gutenberg_dir_path() . 'build/list-reusable-blocks/style.css' )
421 396 );
422 397 $styles->add_data( 'wp-list-reusable-block', 'rtl', 'replace' );
423 398
424 399 gutenberg_override_style(
@@ -425,9 +400,9 @@
425 400 $styles,
426 401 'wp-edit-navigation',
427 402 gutenberg_url( 'build/edit-navigation/style.css' ),
428 403 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
429 - $version
404 + filemtime( gutenberg_dir_path() . 'build/edit-navigation/style.css' )
430 405 );
431 406 $styles->add_data( 'wp-edit-navigation', 'rtl', 'replace' );
432 407
433 408 gutenberg_override_style(
@@ -434,9 +409,9 @@
434 409 $styles,
435 410 'wp-edit-site',
436 411 gutenberg_url( 'build/edit-site/style.css' ),
437 412 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
438 - $version
413 + filemtime( gutenberg_dir_path() . 'build/edit-site/style.css' )
439 414 );
440 415 $styles->add_data( 'wp-edit-site', 'rtl', 'replace' );
441 416
442 417 gutenberg_override_style(
@@ -442,10 +417,10 @@
442 417 gutenberg_override_style(
443 418 $styles,
444 419 'wp-edit-widgets',
445 420 gutenberg_url( 'build/edit-widgets/style.css' ),
446 - array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks', 'wp-reusable-blocks', 'wp-widgets' ),
447 - $version
421 + array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
422 + filemtime( gutenberg_dir_path() . 'build/edit-widgets/style.css' )
448 423 );
449 424 $styles->add_data( 'wp-edit-widgets', 'rtl', 'replace' );
450 425
451 426 gutenberg_override_style(
@@ -452,39 +427,31 @@
452 427 $styles,
453 428 'wp-block-directory',
454 429 gutenberg_url( 'build/block-directory/style.css' ),
455 430 array( 'wp-block-editor', 'wp-components' ),
456 - $version
431 + filemtime( gutenberg_dir_path() . 'build/block-directory/style.css' )
457 432 );
458 433 $styles->add_data( 'wp-block-directory', 'rtl', 'replace' );
434 +}
435 +add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' );
459 436
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' );
437 +/**
438 + * Registers common scripts and styles to be used as dependencies of the editor
439 + * and plugins.
440 + *
441 + * @since 0.1.0
442 + */
443 +function gutenberg_enqueue_block_editor_assets() {
444 + if ( defined( 'GUTENBERG_LIVE_RELOAD' ) && GUTENBERG_LIVE_RELOAD ) {
445 + $live_reload_url = ( GUTENBERG_LIVE_RELOAD === true ) ? 'http://localhost:35729/livereload.js' : GUTENBERG_LIVE_RELOAD;
468 446
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' );
447 + wp_enqueue_script(
448 + 'gutenberg-live-reload',
449 + $live_reload_url
450 + );
451 + }
485 452 }
486 -add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' );
453 +add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_block_editor_assets' );
487 454
488 455 /**
489 456 * Retrieves a unique and reasonably short and human-friendly filename for a
490 457 * vendor script based on a URL and the script handle.
@@ -559,27 +526,17 @@
559 526 if ( $needs_fetch ) {
560 527 // Determine whether we can write to this file. If not, don't waste
561 528 // time doing a network request.
562 529 // @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 -
530 + $f = @fopen( $full_path, 'a' );
574 531 // @codingStandardsIgnoreEnd
575 - if ( ! $is_writable ) {
532 + if ( ! $f ) {
576 533 // Failed to open the file for writing, probably due to server
577 534 // permissions. Enqueue the script directly from the URL instead.
578 535 gutenberg_override_script( $scripts, $handle, $src, $deps, $ver, $in_footer );
579 536 return;
580 537 }
581 -
538 + fclose( $f );
582 539 $response = wp_remote_get( $src );
583 540 if ( wp_remote_retrieve_response_code( $response ) === 200 ) {
584 541 $f = fopen( $full_path, 'w' );
585 542 fwrite( $f, wp_remote_retrieve_body( $response ) );
@@ -603,75 +560,194 @@
603 560 );
604 561 }
605 562
606 563 /**
607 - * Sets the editor styles to be consumed by JS.
564 + * Extends block editor settings to include Gutenberg's `editor-styles.css` as
565 + * taking precedent those styles shipped with core.
566 + *
567 + * @param array $settings Default editor settings.
568 + *
569 + * @return array Filtered editor settings.
608 570 */
609 -function gutenberg_resolve_assets() {
610 - global $pagenow;
571 +function gutenberg_extend_block_editor_styles( $settings ) {
572 + $editor_styles_file = gutenberg_dir_path() . 'build/editor/editor-styles.css';
611 573
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',
574 + /*
575 + * If, for whatever reason, the built editor styles do not exist, avoid
576 + * override and fall back to the default.
577 + */
578 + if ( ! file_exists( $editor_styles_file ) ) {
579 + return $settings;
580 + }
581 +
582 + if ( empty( $settings['styles'] ) ) {
583 + $settings['styles'] = array();
584 + } else {
585 + /*
586 + * The styles setting is an array of CSS strings, so there is no direct
587 + * way to find the default styles. To maximize stability, load (again)
588 + * the default styles from disk and find its place in the array.
589 + *
590 + * See: https://github.com/WordPress/wordpress-develop/blob/5.0.3/src/wp-admin/edit-form-blocks.php#L168-L175
591 + */
592 +
593 + $default_styles = file_get_contents(
594 + ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
595 + );
596 +
597 + /*
598 + * Iterate backwards from the end of the array since the preferred
599 + * insertion point in case not found is prepended as first entry.
600 + */
601 + for ( $i = count( $settings['styles'] ) - 1; $i >= 0; $i-- ) {
602 + if ( isset( $settings['styles'][ $i ]['css'] ) &&
603 + $default_styles === $settings['styles'][ $i ]['css'] ) {
604 + break;
605 + }
606 + }
607 + }
608 +
609 + $editor_styles = array(
610 + 'css' => file_get_contents( $editor_styles_file ),
618 611 );
619 612
620 - if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
621 - $style_handles[] = 'wp-widgets';
622 - $style_handles[] = 'wp-edit-widgets';
613 + // Substitute default styles if found. Otherwise, prepend to setting array.
614 + if ( isset( $i ) && $i >= 0 ) {
615 + $settings['styles'][ $i ] = $editor_styles;
616 + } else {
617 + array_unshift( $settings['styles'], $editor_styles );
623 618 }
624 619
625 - $block_registry = WP_Block_Type_Registry::get_instance();
620 + return $settings;
621 +}
622 +add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
626 623
627 - foreach ( $block_registry->get_all_registered() as $block_type ) {
628 - if ( ! empty( $block_type->style ) ) {
629 - $style_handles[] = $block_type->style;
630 - }
624 +/**
625 + * Load a block pattern by name.
626 + *
627 + * @param string $name Block Pattern File name.
628 + *
629 + * @return array Block Pattern Array.
630 + */
631 +function gutenberg_load_block_pattern( $name ) {
632 + return require( __DIR__ . '/patterns/' . $name . '.php' );
633 +}
631 634
632 - if ( ! empty( $block_type->editor_style ) ) {
633 - $style_handles[] = $block_type->editor_style;
634 - }
635 +/**
636 + * Extends block editor settings to include a list of default patterns.
637 + *
638 + * @param array $settings Default editor settings.
639 + *
640 + * @return array Filtered editor settings.
641 + */
642 +function gutenberg_extend_settings_block_patterns( $settings ) {
643 + if ( empty( $settings['__experimentalBlockPatterns'] ) ) {
644 + $settings['__experimentalBlockPatterns'] = array();
645 + }
635 646
636 - if ( ! empty( $block_type->script ) ) {
637 - $script_handles[] = $block_type->script;
638 - }
647 + $settings['__experimentalBlockPatterns'] = array_merge(
648 + WP_Block_Patterns_Registry::get_instance()->get_all_registered(),
649 + $settings['__experimentalBlockPatterns']
650 + );
651 +
652 + if ( empty( $settings['__experimentalBlockPatternCategories'] ) ) {
653 + $settings['__experimentalBlockPatternCategories'] = array();
639 654 }
640 655
641 - $style_handles = array_unique( $style_handles );
642 - $done = wp_styles()->done;
656 + $settings['__experimentalBlockPatternCategories'] = array_merge(
657 + WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(),
658 + $settings['__experimentalBlockPatternCategories']
659 + );
643 660
644 - ob_start();
661 + return $settings;
662 +}
663 +add_filter( 'block_editor_settings', 'gutenberg_extend_settings_block_patterns', 0 );
645 664
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;
665 +/**
666 + * Extends block editor settings to determine whether to use custom line height controls.
667 + *
668 + * @param array $settings Default editor settings.
669 + *
670 + * @return array Filtered editor settings.
671 + */
672 +function gutenberg_extend_settings_custom_line_height( $settings ) {
673 + $settings['__experimentalDisableCustomLineHeight'] = get_theme_support( 'disable-custom-line-height' );
674 + return $settings;
675 +}
676 +add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_line_height' );
650 677
651 - $styles = ob_get_clean();
678 +/**
679 + * Extends block editor settings to determine whether to use custom unit controls.
680 + * Currently experimental.
681 + *
682 + * @param array $settings Default editor settings.
683 + *
684 + * @return array Filtered editor settings.
685 + */
686 +function gutenberg_extend_settings_custom_units( $settings ) {
687 + $settings['__experimentalDisableCustomUnits'] = get_theme_support( 'experimental-custom-units' );
688 + return $settings;
689 +}
690 +add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_units' );
652 691
653 - $script_handles = array_unique( $script_handles );
654 - $done = wp_scripts()->done;
692 +/**
693 + * Extends block editor settings to determine whether to use custom spacing controls.
694 + * Currently experimental.
695 + *
696 + * @param array $settings Default editor settings.
697 + *
698 + * @return array Filtered editor settings.
699 + */
700 +function gutenberg_extend_settings_custom_spacing( $settings ) {
701 + $settings['__experimentalEnableCustomSpacing'] = get_theme_support( 'experimental-custom-spacing' );
702 + return $settings;
703 +}
704 +add_filter( 'block_editor_settings', 'gutenberg_extend_settings_custom_spacing' );
655 705
656 - ob_start();
657 706
658 - wp_scripts()->done = array();
659 - wp_scripts()->do_items( $script_handles );
660 - wp_scripts()->done = $done;
707 +/**
708 + * Extends block editor settings to determine whether to use custom spacing controls.
709 + * Currently experimental.
710 + *
711 + * @param array $settings Default editor settings.
712 + *
713 + * @return array Filtered editor settings.
714 + */
715 +function gutenberg_extend_settings_link_color( $settings ) {
716 + $settings['__experimentalEnableLinkColor'] = get_theme_support( 'experimental-link-color' );
717 + return $settings;
718 +}
719 +add_filter( 'block_editor_settings', 'gutenberg_extend_settings_link_color' );
661 720
662 - $scripts = ob_get_clean();
721 +/*
722 + * Register default patterns if not registered in Core already.
723 + *
724 + * This can be removed when plugin support requires WordPress 5.5.0+.
725 + *
726 + * @see https://core.trac.wordpress.org/ticket/50550
727 + */
728 +if ( class_exists( 'WP_Block_Patterns_Registry' ) && ! WP_Block_Patterns_Registry::get_instance()->is_registered( 'text-two-columns' ) ) {
729 + register_block_pattern( 'core/text-two-columns', gutenberg_load_block_pattern( 'text-two-columns' ) );
730 + register_block_pattern( 'core/two-buttons', gutenberg_load_block_pattern( 'two-buttons' ) );
731 + register_block_pattern( 'core/two-images', gutenberg_load_block_pattern( 'two-images' ) );
732 + register_block_pattern( 'core/text-two-columns-with-images', gutenberg_load_block_pattern( 'text-two-columns-with-images' ) );
733 + register_block_pattern( 'core/text-three-columns-buttons', gutenberg_load_block_pattern( 'text-three-columns-buttons' ) );
734 + register_block_pattern( 'core/large-header', gutenberg_load_block_pattern( 'large-header' ) );
735 + register_block_pattern( 'core/large-header-paragraph', gutenberg_load_block_pattern( 'large-header-paragraph' ) );
736 + register_block_pattern( 'core/three-buttons', gutenberg_load_block_pattern( 'three-buttons' ) );
737 + register_block_pattern( 'core/quote', gutenberg_load_block_pattern( 'quote' ) );
738 +}
663 739
664 - return array(
665 - 'styles' => $styles,
666 - 'scripts' => $scripts,
667 - );
740 +/*
741 + * Register default pattern categories if not registered in Core already.
742 + *
743 + * This can be removed when plugin support requires WordPress 5.5.0+.
744 + *
745 + * @see https://core.trac.wordpress.org/ticket/50550
746 + */
747 +if ( class_exists( 'WP_Block_Pattern_Categories_Registry' ) ) {
748 + register_block_pattern_category( 'buttons', array( 'label' => _x( 'Buttons', 'Block pattern category', 'gutenberg' ) ) );
749 + register_block_pattern_category( 'columns', array( 'label' => _x( 'Columns', 'Block pattern category', 'gutenberg' ) ) );
750 + register_block_pattern_category( 'gallery', array( 'label' => _x( 'Gallery', 'Block pattern category', 'gutenberg' ) ) );
751 + register_block_pattern_category( 'header', array( 'label' => _x( 'Headers', 'Block pattern category', 'gutenberg' ) ) );
752 + register_block_pattern_category( 'text', array( 'label' => _x( 'Text', 'Block pattern category', 'gutenberg' ) ) );
668 753 }
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 -);