PluginProbe
Gutenberg / 6.6.0
Gutenberg v6.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 6.6.0, at lib/client-assets.php

639 lines 21.4 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( dirname( __FILE__ ) );
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, dirname( __FILE__ ) );
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 string $handle Name of the script. Should be unique.
46 * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
47 * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
48 * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
49 * as a query string for cache busting purposes. If version is set to false, a version
50 * number is automatically added equal to current installed WordPress version.
51 * If set to null, no version is added.
52 * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
53 * Default 'false'.
54 */
55 function gutenberg_override_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
56 global $wp_scripts;
57
58 $script = $wp_scripts->query( $handle, 'registered' );
59 if ( $script ) {
60 /*
61 * In many ways, this is a reimplementation of `wp_register_script` but
62 * bypassing consideration of whether a script by the given handle had
63 * already been registered.
64 */
65
66 // See: `_WP_Dependency::__construct` .
67 $script->src = $src;
68 $script->deps = $deps;
69 $script->ver = $ver;
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 wp_register_script( $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 script, which is a dependency _of_ `wp-i18n`.
92 *
93 * See: https://core.trac.wordpress.org/ticket/46089
94 */
95 if ( 'wp-i18n' !== $handle && 'wp-polyfill' !== $handle ) {
96 wp_set_script_translations( $handle, 'default' );
97 }
98 }
99
100 /**
101 * Filters the default translation file load behavior to load the Gutenberg
102 * plugin translation file, if available.
103 *
104 * @param string|false $file Path to the translation file to load. False if
105 * there isn't one.
106 * @param string $handle Name of the script to register a translation
107 * domain to.
108 *
109 * @return string|false Filtered path to the Gutenberg translation file, if
110 * available.
111 */
112 function gutenberg_override_translation_file( $file, $handle ) {
113 if ( ! $file ) {
114 return $file;
115 }
116
117 // Ignore scripts whose handle does not have the "wp-" prefix.
118 if ( 'wp-' !== substr( $handle, 0, 3 ) ) {
119 return $file;
120 }
121
122 // Ignore scripts that are not found in the expected `build/` location.
123 $script_path = gutenberg_dir_path() . 'build/' . substr( $handle, 3 ) . '/index.js';
124 if ( ! file_exists( $script_path ) ) {
125 return $file;
126 }
127
128 /*
129 * The default file will be in the plugins language directory, omitting the
130 * domain since Gutenberg assigns the script translations as the default.
131 *
132 * Example: /www/wp-content/languages/plugins/de_DE-07d88e6a803e01276b9bfcc1203e862e.json
133 *
134 * The logic of `load_script_textdomain` is such that it will assume to
135 * search in the plugins language directory, since the assigned source of
136 * the overridden Gutenberg script originates in the plugins directory.
137 *
138 * The plugin translation files each begin with the slug of the plugin, so
139 * it's a simple matter of prepending the Gutenberg plugin slug.
140 */
141 $path_parts = pathinfo( $file );
142 $plugin_translation_file = (
143 $path_parts['dirname'] .
144 '/gutenberg-' .
145 $path_parts['basename']
146 );
147
148 if ( ! is_readable( $plugin_translation_file ) ) {
149 return $file;
150 }
151
152 return $plugin_translation_file;
153 }
154 add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 );
155
156 /**
157 * Registers a style according to `wp_register_style`. Honors this request by
158 * deregistering any style by the same handler before registration.
159 *
160 * @since 4.1.0
161 *
162 * @param string $handle Name of the stylesheet. Should be unique.
163 * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
164 * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
165 * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
166 * as a query string for cache busting purposes. If version is set to false, a version
167 * number is automatically added equal to current installed WordPress version.
168 * If set to null, no version is added.
169 * @param string $media Optional. The media for which this stylesheet has been defined.
170 * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
171 * '(orientation: portrait)' and '(max-width: 640px)'.
172 */
173 function gutenberg_override_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
174 wp_deregister_style( $handle );
175 wp_register_style( $handle, $src, $deps, $ver, $media );
176 }
177
178 /**
179 * Registers all the WordPress packages scripts that are in the standardized
180 * `build/` location.
181 *
182 * @since 4.5.0
183 */
184 function gutenberg_register_packages_scripts() {
185 foreach ( glob( gutenberg_dir_path() . 'build/*/index.js' ) as $path ) {
186 // Prefix `wp-` to package directory to get script handle.
187 // For example, `…/build/a11y/index.js` becomes `wp-a11y`.
188 $handle = 'wp-' . basename( dirname( $path ) );
189
190 // Replace `.js` extension with `.asset.php` to find the generated dependencies file.
191 $asset_file = substr( $path, 0, -3 ) . '.asset.php';
192 $asset = file_exists( $asset_file )
193 ? require_once( $asset_file )
194 : null;
195 $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
196 $version = isset( $asset['version'] ) ? $asset['version'] : filemtime( $path );
197
198 // Add dependencies that cannot be detected and generated by build tools.
199 switch ( $handle ) {
200 case 'wp-block-library':
201 array_push( $dependencies, 'editor' );
202 break;
203
204 case 'wp-edit-post':
205 array_push( $dependencies, 'media-models', 'media-views', 'postbox' );
206 break;
207 }
208
209 // Get the path from Gutenberg directory as expected by `gutenberg_url`.
210 $gutenberg_path = substr( $path, strlen( gutenberg_dir_path() ) );
211
212 gutenberg_override_script(
213 $handle,
214 gutenberg_url( $gutenberg_path ),
215 $dependencies,
216 $version,
217 true
218 );
219 }
220 }
221
222 /**
223 * Registers common scripts and styles to be used as dependencies of the editor
224 * and plugins.
225 *
226 * @since 0.1.0
227 */
228 function gutenberg_register_scripts_and_styles() {
229 global $wp_scripts;
230
231 gutenberg_register_vendor_scripts();
232 gutenberg_register_packages_scripts();
233
234 // Add nonce middleware which accounts for the absence of the heartbeat
235 // listener. This relies on API Fetch implementation running middlewares in
236 // order of last added, and that the original nonce middleware would defer
237 // to an X-WP-Nonce header already being present. This inline script should
238 // be removed once the following Core ticket is resolved in assigning the
239 // nonce received from heartbeat to the created middleware.
240 //
241 // See: https://core.trac.wordpress.org/ticket/46107 .
242 // See: https://github.com/WordPress/gutenberg/pull/13451 .
243 if ( isset( $wp_scripts->registered['wp-api-fetch'] ) ) {
244 $wp_scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
245 }
246 wp_add_inline_script(
247 'wp-api-fetch',
248 sprintf(
249 'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );' .
250 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );' .
251 'wp.apiFetch.nonceEndpoint = "%s";',
252 ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
253 admin_url( 'admin-ajax.php?action=gutenberg_rest_nonce' )
254 ),
255 'after'
256 );
257
258 // TEMPORARY: Core does not (yet) provide persistence migration from the
259 // introduction of the block editor and still calls the data plugins.
260 // We unset the existing inline scripts first.
261 $wp_scripts->registered['wp-data']->extra['after'] = array();
262 wp_add_inline_script(
263 'wp-data',
264 implode(
265 "\n",
266 array(
267 '( function() {',
268 ' var userId = ' . get_current_user_ID() . ';',
269 ' var storageKey = "WP_DATA_USER_" + userId;',
270 ' wp.data',
271 ' .use( wp.data.plugins.persistence, { storageKey: storageKey } );',
272 ' wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );',
273 '} )();',
274 )
275 )
276 );
277
278 // Editor Styles.
279 // This empty stylesheet is defined to ensure backward compatibility.
280 gutenberg_override_style( 'wp-blocks', false );
281
282 gutenberg_override_style(
283 'wp-block-editor',
284 gutenberg_url( 'build/block-editor/style.css' ),
285 array( 'wp-components', 'wp-editor-font' ),
286 filemtime( gutenberg_dir_path() . 'build/editor/style.css' )
287 );
288 wp_style_add_data( 'wp-block-editor', 'rtl', 'replace' );
289
290 gutenberg_override_style(
291 'wp-editor',
292 gutenberg_url( 'build/editor/style.css' ),
293 array( 'wp-components', 'wp-block-editor', 'wp-nux', 'wp-block-directory' ),
294 filemtime( gutenberg_dir_path() . 'build/editor/style.css' )
295 );
296 wp_style_add_data( 'wp-editor', 'rtl', 'replace' );
297
298 gutenberg_override_style(
299 'wp-edit-post',
300 gutenberg_url( 'build/edit-post/style.css' ),
301 array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-block-library', 'wp-nux' ),
302 filemtime( gutenberg_dir_path() . 'build/edit-post/style.css' )
303 );
304 wp_style_add_data( 'wp-edit-post', 'rtl', 'replace' );
305
306 gutenberg_override_style(
307 'wp-components',
308 gutenberg_url( 'build/components/style.css' ),
309 array(),
310 filemtime( gutenberg_dir_path() . 'build/components/style.css' )
311 );
312 wp_style_add_data( 'wp-components', 'rtl', 'replace' );
313
314 gutenberg_override_style(
315 'wp-block-library',
316 gutenberg_url( 'build/block-library/style.css' ),
317 array(),
318 filemtime( gutenberg_dir_path() . 'build/block-library/style.css' )
319 );
320 wp_style_add_data( 'wp-block-library', 'rtl', 'replace' );
321
322 gutenberg_override_style(
323 'wp-format-library',
324 gutenberg_url( 'build/format-library/style.css' ),
325 array( 'wp-block-editor', 'wp-components' ),
326 filemtime( gutenberg_dir_path() . 'build/format-library/style.css' )
327 );
328 wp_style_add_data( 'wp-format-library', 'rtl', 'replace' );
329
330 gutenberg_override_style(
331 'wp-edit-blocks',
332 gutenberg_url( 'build/block-library/editor.css' ),
333 array(
334 'wp-components',
335 'wp-editor',
336 'wp-block-library',
337 // Always include visual styles so the editor never appears broken.
338 'wp-block-library-theme',
339 ),
340 filemtime( gutenberg_dir_path() . 'build/block-library/editor.css' )
341 );
342 wp_style_add_data( 'wp-edit-blocks', 'rtl', 'replace' );
343
344 gutenberg_override_style(
345 'wp-nux',
346 gutenberg_url( 'build/nux/style.css' ),
347 array( 'wp-components' ),
348 filemtime( gutenberg_dir_path() . 'build/nux/style.css' )
349 );
350 wp_style_add_data( 'wp-nux', 'rtl', 'replace' );
351
352 gutenberg_override_style(
353 'wp-block-library-theme',
354 gutenberg_url( 'build/block-library/theme.css' ),
355 array(),
356 filemtime( gutenberg_dir_path() . 'build/block-library/theme.css' )
357 );
358 wp_style_add_data( 'wp-block-library-theme', 'rtl', 'replace' );
359
360 gutenberg_override_style(
361 'wp-list-reusable-blocks',
362 gutenberg_url( 'build/list-reusable-blocks/style.css' ),
363 array( 'wp-components' ),
364 filemtime( gutenberg_dir_path() . 'build/list-reusable-blocks/style.css' )
365 );
366 wp_style_add_data( 'wp-list-reusable-block', 'rtl', 'replace' );
367
368 gutenberg_override_style(
369 'wp-edit-widgets',
370 gutenberg_url( 'build/edit-widgets/style.css' ),
371 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
372 filemtime( gutenberg_dir_path() . 'build/edit-widgets/style.css' )
373 );
374 wp_style_add_data( 'wp-edit-widgets', 'rtl', 'replace' );
375
376 gutenberg_override_style(
377 'wp-block-directory',
378 gutenberg_url( 'build/block-directory/style.css' ),
379 array( 'wp-components' ),
380 filemtime( gutenberg_dir_path() . 'build/block-directory/style.css' )
381 );
382 wp_style_add_data( 'wp-block-directory', 'rtl', 'replace' );
383
384 if ( defined( 'GUTENBERG_LIVE_RELOAD' ) && GUTENBERG_LIVE_RELOAD ) {
385 $live_reload_url = ( GUTENBERG_LIVE_RELOAD === true ) ? 'http://localhost:35729/livereload.js' : GUTENBERG_LIVE_RELOAD;
386
387 wp_enqueue_script(
388 'gutenberg-live-reload',
389 $live_reload_url
390 );
391 }
392 }
393 add_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5 );
394 add_action( 'admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5 );
395
396 /**
397 * Registers vendor JavaScript files to be used as dependencies of the editor
398 * and plugins.
399 *
400 * This function is called from a script during the plugin build process, so it
401 * should not call any WordPress PHP functions.
402 *
403 * @since 0.1.0
404 */
405 function gutenberg_register_vendor_scripts() {
406 $suffix = SCRIPT_DEBUG ? '' : '.min';
407
408 // Vendor Scripts.
409 $react_suffix = ( SCRIPT_DEBUG ? '.development' : '.production' ) . $suffix;
410
411 // TODO: Overrides for react, react-dom and lodash are necessary
412 // until WordPress 5.3 is released.
413 gutenberg_register_vendor_script(
414 'react',
415 'https://unpkg.com/react@16.9.0/umd/react' . $react_suffix . '.js',
416 array( 'wp-polyfill' )
417 );
418 gutenberg_register_vendor_script(
419 'react-dom',
420 'https://unpkg.com/react-dom@16.9.0/umd/react-dom' . $react_suffix . '.js',
421 array( 'react' )
422 );
423 gutenberg_register_vendor_script(
424 'lodash',
425 'https://unpkg.com/lodash@4.17.15/lodash' . $suffix . '.js'
426 );
427 }
428
429 /**
430 * Retrieves a unique and reasonably short and human-friendly filename for a
431 * vendor script based on a URL and the script handle.
432 *
433 * @param string $handle The name of the script.
434 * @param string $src Full URL of the external script.
435 *
436 * @return string Script filename suitable for local caching.
437 *
438 * @since 0.1.0
439 */
440 function gutenberg_vendor_script_filename( $handle, $src ) {
441 $filename = basename( $src );
442 $match = preg_match(
443 '/^'
444 . '(?P<ignore>.*?)'
445 . '(?P<suffix>\.min)?'
446 . '(?P<extension>\.js)'
447 . '(?P<extra>.*)'
448 . '$/',
449 $filename,
450 $filename_pieces
451 );
452
453 $prefix = $handle;
454 $suffix = $match ? $filename_pieces['suffix'] : '';
455 $hash = substr( md5( $src ), 0, 8 );
456
457 return "${prefix}${suffix}.${hash}.js";
458 }
459
460 /**
461 * Registers a vendor script from a URL, preferring a locally cached version if
462 * possible, or downloading it if the cached version is unavailable or
463 * outdated.
464 *
465 * @param string $handle Name of the script.
466 * @param string $src Full URL of the external script.
467 * @param array $deps Optional. An array of registered script handles this
468 * script depends on.
469 *
470 * @since 0.1.0
471 */
472 function gutenberg_register_vendor_script( $handle, $src, $deps = array() ) {
473 if ( defined( 'GUTENBERG_LOAD_VENDOR_SCRIPTS' ) && ! GUTENBERG_LOAD_VENDOR_SCRIPTS ) {
474 return;
475 }
476
477 $filename = gutenberg_vendor_script_filename( $handle, $src );
478
479 if ( defined( 'GUTENBERG_LIST_VENDOR_ASSETS' ) && GUTENBERG_LIST_VENDOR_ASSETS ) {
480 echo "$src|$filename\n";
481 return;
482 }
483
484 $full_path = gutenberg_dir_path() . 'vendor/' . $filename;
485
486 $needs_fetch = (
487 defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && (
488 ! file_exists( $full_path ) ||
489 time() - filemtime( $full_path ) >= DAY_IN_SECONDS
490 )
491 );
492
493 if ( $needs_fetch ) {
494 // Determine whether we can write to this file. If not, don't waste
495 // time doing a network request.
496 // @codingStandardsIgnoreStart
497 $f = @fopen( $full_path, 'a' );
498 // @codingStandardsIgnoreEnd
499 if ( ! $f ) {
500 // Failed to open the file for writing, probably due to server
501 // permissions. Enqueue the script directly from the URL instead.
502 gutenberg_override_script( $handle, $src, $deps, null );
503 return;
504 }
505 fclose( $f );
506 $response = wp_remote_get( $src );
507 if ( wp_remote_retrieve_response_code( $response ) === 200 ) {
508 $f = fopen( $full_path, 'w' );
509 fwrite( $f, wp_remote_retrieve_body( $response ) );
510 fclose( $f );
511 } elseif ( ! filesize( $full_path ) ) {
512 // The request failed. If the file is already cached, continue to
513 // use this file. If not, then unlink the 0 byte file, and enqueue
514 // the script directly from the URL.
515 gutenberg_override_script( $handle, $src, $deps, null );
516 unlink( $full_path );
517 return;
518 }
519 }
520 gutenberg_override_script(
521 $handle,
522 gutenberg_url( 'vendor/' . $filename ),
523 $deps,
524 null
525 );
526 }
527
528 /**
529 * Extends block editor settings to include Gutenberg's `editor-styles.css` as
530 * taking precedent those styles shipped with core.
531 *
532 * @param array $settings Default editor settings.
533 *
534 * @return array Filtered editor settings.
535 */
536 function gutenberg_extend_block_editor_styles( $settings ) {
537 $editor_styles_file = gutenberg_dir_path() . 'build/editor/editor-styles.css';
538
539 /*
540 * If, for whatever reason, the built editor styles do not exist, avoid
541 * override and fall back to the default.
542 */
543 if ( ! file_exists( $editor_styles_file ) ) {
544 return $settings;
545 }
546
547 if ( empty( $settings['styles'] ) ) {
548 $settings['styles'] = array();
549 } else {
550 /*
551 * The styles setting is an array of CSS strings, so there is no direct
552 * way to find the default styles. To maximize stability, load (again)
553 * the default styles from disk and find its place in the array.
554 *
555 * See: https://github.com/WordPress/wordpress-develop/blob/5.0.3/src/wp-admin/edit-form-blocks.php#L168-L175
556 */
557
558 $default_styles = file_get_contents(
559 ABSPATH . WPINC . '/css/dist/editor/editor-styles.css'
560 );
561
562 /*
563 * Iterate backwards from the end of the array since the preferred
564 * insertion point in case not found is prepended as first entry.
565 */
566 for ( $i = count( $settings['styles'] ) - 1; $i >= 0; $i-- ) {
567 if ( isset( $settings['styles'][ $i ]['css'] ) &&
568 $default_styles === $settings['styles'][ $i ]['css'] ) {
569 break;
570 }
571 }
572 }
573
574 $editor_styles = array(
575 'css' => file_get_contents( $editor_styles_file ),
576 );
577
578 // Substitute default styles if found. Otherwise, prepend to setting array.
579 if ( isset( $i ) && $i >= 0 ) {
580 $settings['styles'][ $i ] = $editor_styles;
581 } else {
582 array_unshift( $settings['styles'], $editor_styles );
583 }
584
585 return $settings;
586 }
587 add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
588
589 /**
590 * Extends block editor preload paths to preload additional data. Note that any
591 * additions here should be complemented with a corresponding core ticket to
592 * reconcile the change upstream for future removal from Gutenberg.
593 *
594 * @param array $preload_paths Array of paths to preload.
595 * @param WP_Post $post Post being edited.
596 *
597 * @return array Filtered array of paths to preload.
598 */
599 function gutenberg_extend_block_editor_preload_paths( $preload_paths, $post ) {
600 /*
601 * Preload any autosaves for the post. (see https://github.com/WordPress/gutenberg/pull/7945)
602 *
603 * Trac ticket: https://core.trac.wordpress.org/ticket/46974
604 *
605 * At the time of writing, the change is not committed or released
606 * in core. This path should be removed from Gutenberg when the code is
607 * released in core, and the corresponding release version becomes
608 * the minimum supported version.
609 */
610 $post_type_object = get_post_type_object( $post->post_type );
611
612 if ( isset( $post_type_object ) ) {
613 $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
614 $autosaves_path = sprintf( '/wp/v2/%s/%d/autosaves?context=edit', $rest_base, $post->ID );
615
616 if ( ! in_array( $autosaves_path, $preload_paths, true ) ) {
617 $preload_paths[] = $autosaves_path;
618 }
619 }
620
621 /*
622 * Used in considering user permissions for creating and updating blocks,
623 * as condition for displaying relevant actions in the interface.
624 *
625 * Trac ticket: https://core.trac.wordpress.org/ticket/46429
626 *
627 * This is present in WordPress 5.2 and should be removed from Gutenberg
628 * once WordPress 5.2 is the minimum supported version.
629 */
630 $blocks_path = array( '/wp/v2/blocks', 'OPTIONS' );
631
632 if ( ! in_array( $blocks_path, $preload_paths, true ) ) {
633 $preload_paths[] = $blocks_path;
634 }
635
636 return $preload_paths;
637 }
638 add_filter( 'block_editor_preload_paths', 'gutenberg_extend_block_editor_preload_paths', 10, 2 );
639