PluginProbe
Gutenberg / 9.7.2
Gutenberg v9.7.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 +76 -90 7.4.09.7.2 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( dirname( __FILE__ ) );
21 + return plugin_dir_path( __DIR__ );
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, dirname( __FILE__ ) );
34 + return plugins_url( $path, __DIR__ );
35 35 }
36 36
37 37 /**
38 38 * Registers a script according to `wp_register_script`. Honors this request by
@@ -41,9 +41,9 @@
41 41 * avoid losing inline scripts which may have been attached.
42 42 *
43 43 * @since 4.1.0
44 44 *
45 - * @param WP_Scripts $scripts WP_Scripts instance (passed by reference).
45 + * @param WP_Scripts $scripts WP_Scripts instance.
46 46 * @param string $handle Name of the script. Should be unique.
47 47 * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
48 48 * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
49 49 * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
@@ -52,9 +52,9 @@
52 52 * If set to null, no version is added.
53 53 * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
54 54 * Default 'false'.
55 55 */
56 -function gutenberg_override_script( &$scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
56 +function gutenberg_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
57 57 $script = $scripts->query( $handle, 'registered' );
58 58 if ( $script ) {
59 59 /*
60 60 * In many ways, this is a reimplementation of `wp_register_script` but
@@ -173,9 +173,9 @@
173 173 * deregistering any style by the same handler before registration.
174 174 *
175 175 * @since 4.1.0
176 176 *
177 - * @param WP_Styles $styles WP_Styles instance (passed by reference).
177 + * @param WP_Styles $styles WP_Styles instance.
178 178 * @param string $handle Name of the stylesheet. Should be unique.
179 179 * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
180 180 * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
181 181 * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
@@ -185,9 +185,9 @@
185 185 * @param string $media Optional. The media for which this stylesheet has been defined.
186 186 * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
187 187 * '(orientation: portrait)' and '(max-width: 640px)'.
188 188 */
189 -function gutenberg_override_style( &$styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
189 +function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
190 190 $style = $styles->query( $handle, 'registered' );
191 191 if ( $style ) {
192 192 $styles->remove( $handle );
193 193 }
@@ -202,40 +202,37 @@
202 202 * should not call any WordPress PHP functions.
203 203 *
204 204 * @since 0.1.0
205 205 *
206 - * @param WP_Scripts $scripts WP_Scripts instance (passed by reference).
206 + * @param WP_Scripts $scripts WP_Scripts instance.
207 207 */
208 -function gutenberg_register_vendor_scripts( &$scripts ) {
208 +function gutenberg_register_vendor_scripts( $scripts ) {
209 209 $suffix = SCRIPT_DEBUG ? '' : '.min';
210 210
211 - // Vendor Scripts.
212 211 $react_suffix = ( SCRIPT_DEBUG ? '.development' : '.production' ) . $suffix;
213 -
214 - // TODO: Overrides for react, react-dom and lodash are necessary
215 - // until WordPress 5.3 is released.
216 212 gutenberg_register_vendor_script(
217 213 $scripts,
218 214 'react',
219 - 'https://unpkg.com/react@16.9.0/umd/react' . $react_suffix . '.js',
220 - array( 'wp-polyfill' ),
221 - '16.9.0',
222 - true
215 + 'https://unpkg.com/react@16.13.1/umd/react' . $react_suffix . '.js',
216 + array( 'wp-polyfill' )
223 217 );
224 218 gutenberg_register_vendor_script(
225 219 $scripts,
226 220 'react-dom',
227 - 'https://unpkg.com/react-dom@16.9.0/umd/react-dom' . $react_suffix . '.js',
228 - array( 'react' ),
229 - '16.9.0',
230 - true
221 + 'https://unpkg.com/react-dom@16.13.1/umd/react-dom' . $react_suffix . '.js',
222 + array( 'react' )
231 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.6.0 and newer.
228 + */
232 229 gutenberg_register_vendor_script(
233 230 $scripts,
234 231 'lodash',
235 - 'https://unpkg.com/lodash@4.17.15/lodash' . $suffix . '.js',
232 + 'https://unpkg.com/lodash@4.17.19/lodash.js',
236 233 array(),
237 - '4.17.15',
234 + '4.17.19',
238 235 true
239 236 );
240 237 }
241 238 add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );
@@ -245,11 +242,11 @@
245 242 * `build/` location.
246 243 *
247 244 * @since 4.5.0
248 245 *
249 - * @param WP_Scripts $scripts WP_Scripts instance (passed by reference).
246 + * @param WP_Scripts $scripts WP_Scripts instance.
250 247 */
251 -function gutenberg_register_packages_scripts( &$scripts ) {
248 +function gutenberg_register_packages_scripts( $scripts ) {
252 249 foreach ( glob( gutenberg_dir_path() . 'build/*/index.js' ) as $path ) {
253 250 // Prefix `wp-` to package directory to get script handle.
254 251 // For example, `…/build/a11y/index.js` becomes `wp-a11y`.
255 252 $handle = 'wp-' . basename( dirname( $path ) );
@@ -297,11 +294,11 @@
297 294 * `build/` location.
298 295 *
299 296 * @since 6.7.0
300 297
301 - * @param WP_Styles $styles WP_Styles instance (passed by reference).
298 + * @param WP_Styles $styles WP_Styles instance.
302 299 */
303 -function gutenberg_register_packages_styles( &$styles ) {
300 +function gutenberg_register_packages_styles( $styles ) {
304 301 // Editor Styles.
305 302 gutenberg_override_style(
306 303 $styles,
307 304 'wp-block-editor',
@@ -332,19 +329,20 @@
332 329 gutenberg_override_style(
333 330 $styles,
334 331 'wp-components',
335 332 gutenberg_url( 'build/components/style.css' ),
336 - array(),
333 + array( 'dashicons' ),
337 334 filemtime( gutenberg_dir_path() . 'build/components/style.css' )
338 335 );
339 336 $styles->add_data( 'wp-components', 'rtl', 'replace' );
340 337
338 + $block_library_filename = gutenberg_should_load_separate_block_styles() ? 'common' : 'style';
341 339 gutenberg_override_style(
342 340 $styles,
343 341 'wp-block-library',
344 - gutenberg_url( 'build/block-library/style.css' ),
342 + gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ),
345 343 array(),
346 - filemtime( gutenberg_dir_path() . 'build/block-library/style.css' )
344 + filemtime( gutenberg_dir_path() . 'build/block-library/' . $block_library_filename . '.css' )
347 345 );
348 346 $styles->add_data( 'wp-block-library', 'rtl', 'replace' );
349 347
350 348 gutenberg_override_style(
@@ -399,8 +397,17 @@
399 397 $styles->add_data( 'wp-list-reusable-block', 'rtl', 'replace' );
400 398
401 399 gutenberg_override_style(
402 400 $styles,
401 + 'wp-edit-navigation',
402 + gutenberg_url( 'build/edit-navigation/style.css' ),
403 + array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
404 + filemtime( gutenberg_dir_path() . 'build/edit-navigation/style.css' )
405 + );
406 + $styles->add_data( 'wp-edit-navigation', 'rtl', 'replace' );
407 +
408 + gutenberg_override_style(
409 + $styles,
403 410 'wp-edit-site',
404 411 gutenberg_url( 'build/edit-site/style.css' ),
405 412 array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
406 413 filemtime( gutenberg_dir_path() . 'build/edit-site/style.css' )
@@ -433,21 +440,8 @@
433 440 *
434 441 * @since 0.1.0
435 442 */
436 443 function gutenberg_enqueue_block_editor_assets() {
437 - wp_add_inline_script(
438 - 'wp-api-fetch',
439 - sprintf(
440 - 'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );' .
441 - 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );' .
442 - 'wp.apiFetch.nonceEndpoint = "%s";' .
443 - 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );',
444 - ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
445 - admin_url( 'admin-ajax.php?action=gutenberg_rest_nonce' )
446 - ),
447 - 'after'
448 - );
449 -
450 444 if ( defined( 'GUTENBERG_LIVE_RELOAD' ) && GUTENBERG_LIVE_RELOAD ) {
451 445 $live_reload_url = ( GUTENBERG_LIVE_RELOAD === true ) ? 'http://localhost:35729/livereload.js' : GUTENBERG_LIVE_RELOAD;
452 446
453 447 wp_enqueue_script(
@@ -493,9 +487,9 @@
493 487 * Registers a vendor script from a URL, preferring a locally cached version if
494 488 * possible, or downloading it if the cached version is unavailable or
495 489 * outdated.
496 490 *
497 - * @param WP_Scripts $scripts WP_Scripts instance (passed by reference).
491 + * @param WP_Scripts $scripts WP_Scripts instance.
498 492 * @param string $handle Name of the script.
499 493 * @param string $src Full URL of the external script.
500 494 * @param array $deps Optional. An array of registered script handles this
501 495 * script depends on.
@@ -507,9 +501,9 @@
507 501 * Default 'false'.
508 502 *
509 503 * @since 0.1.0
510 504 */
511 -function gutenberg_register_vendor_script( &$scripts, $handle, $src, $deps = array(), $ver = null, $in_footer = false ) {
505 +function gutenberg_register_vendor_script( $scripts, $handle, $src, $deps = array(), $ver = null, $in_footer = false ) {
512 506 if ( defined( 'GUTENBERG_LOAD_VENDOR_SCRIPTS' ) && ! GUTENBERG_LOAD_VENDOR_SCRIPTS ) {
513 507 return;
514 508 }
515 509
@@ -532,17 +526,27 @@
532 526 if ( $needs_fetch ) {
533 527 // Determine whether we can write to this file. If not, don't waste
534 528 // time doing a network request.
535 529 // @codingStandardsIgnoreStart
536 - $f = @fopen( $full_path, 'a' );
530 +
531 + $is_writable = is_writable( $full_path );
532 + if ( $is_writable ) {
533 + $f = @fopen( $full_path, 'a' );
534 + if ( ! $f ) {
535 + $is_writable = false;
536 + } else {
537 + fclose( $f );
538 + }
539 + }
540 +
537 541 // @codingStandardsIgnoreEnd
538 - if ( ! $f ) {
542 + if ( ! $is_writable ) {
539 543 // Failed to open the file for writing, probably due to server
540 544 // permissions. Enqueue the script directly from the URL instead.
541 545 gutenberg_override_script( $scripts, $handle, $src, $deps, $ver, $in_footer );
542 546 return;
543 547 }
544 - fclose( $f );
548 +
545 549 $response = wp_remote_get( $src );
546 550 if ( wp_remote_retrieve_response_code( $response ) === 200 ) {
547 551 $f = fopen( $full_path, 'w' );
548 552 fwrite( $f, wp_remote_retrieve_body( $response ) );
@@ -627,53 +631,35 @@
627 631 }
628 632 add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
629 633
630 634 /**
631 - * Extends block editor preload paths to preload additional data. Note that any
632 - * additions here should be complemented with a corresponding core ticket to
633 - * reconcile the change upstream for future removal from Gutenberg.
635 + * Load the default editor styles.
636 + * These styles are used if the "no theme styles" options is triggered.
634 637 *
635 - * @param array $preload_paths Array of paths to preload.
636 - * @param WP_Post $post Post being edited.
638 + * @param array $settings Default editor settings.
637 639 *
638 - * @return array Filtered array of paths to preload.
640 + * @return array Filtered editor settings.
639 641 */
640 -function gutenberg_extend_block_editor_preload_paths( $preload_paths, $post ) {
641 - /*
642 - * Preload any autosaves for the post. (see https://github.com/WordPress/gutenberg/pull/7945)
643 - *
644 - * Trac ticket: https://core.trac.wordpress.org/ticket/46974
645 - *
646 - * At the time of writing, the change is not committed or released
647 - * in core. This path should be removed from Gutenberg when the code is
648 - * released in core, and the corresponding release version becomes
649 - * the minimum supported version.
650 - */
651 - $post_type_object = get_post_type_object( $post->post_type );
642 +function gutenberg_extend_block_editor_settings_with_default_editor_styles( $settings ) {
643 + $editor_styles_file = gutenberg_dir_path() . 'build/editor/editor-styles.css';
644 + $settings['defaultEditorStyles'] = array(
645 + array(
646 + 'css' => file_get_contents( $editor_styles_file ),
647 + ),
648 + );
652 649
653 - if ( isset( $post_type_object ) ) {
654 - $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
655 - $autosaves_path = sprintf( '/wp/v2/%s/%d/autosaves?context=edit', $rest_base, $post->ID );
650 + return $settings;
651 +}
652 +add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_settings_with_default_editor_styles' );
656 653
657 - if ( ! in_array( $autosaves_path, $preload_paths, true ) ) {
658 - $preload_paths[] = $autosaves_path;
659 - }
660 - }
661 -
662 - /*
663 - * Used in considering user permissions for creating and updating blocks,
664 - * as condition for displaying relevant actions in the interface.
665 - *
666 - * Trac ticket: https://core.trac.wordpress.org/ticket/46429
667 - *
668 - * This is present in WordPress 5.2 and should be removed from Gutenberg
669 - * once WordPress 5.2 is the minimum supported version.
670 - */
671 - $blocks_path = array( '/wp/v2/blocks', 'OPTIONS' );
672 -
673 - if ( ! in_array( $blocks_path, $preload_paths, true ) ) {
674 - $preload_paths[] = $blocks_path;
675 - }
676 -
677 - return $preload_paths;
654 +/**
655 + * Adds a flag to the editor settings to know whether we're in FSE theme or not.
656 + *
657 + * @param array $settings Default editor settings.
658 + *
659 + * @return array Filtered editor settings.
660 + */
661 +function gutenberg_extend_block_editor_settings_with_fse_theme_flag( $settings ) {
662 + $settings['isFSETheme'] = gutenberg_is_fse_theme();
663 + return $settings;
678 664 }
679 -add_filter( 'block_editor_preload_paths', 'gutenberg_extend_block_editor_preload_paths', 10, 2 );
665 +add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_settings_with_fse_theme_flag' );