| @@ -8,28 +8,94 @@ | ||
| 8 | 8 | * @package gutenberg |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * Filters allowed CSS attributes to include `flex-basis`, included in saved | |
| 13 | - * markup of the Column block. | |
| 12 | + * Adds a polyfill for the WHATWG URL in environments which do not support it. | |
| 13 | + * The intention in how this action is handled is under the assumption that this | |
| 14 | + * code would eventually be placed at `wp_default_packages_vendor`, which is | |
| 15 | + * called as a result of `wp_default_packages` via the `wp_default_scripts`. | |
| 14 | 16 | * |
| 15 | - * This can be removed when plugin support requires WordPress 5.3.0+. | |
| 17 | + * This can be removed when plugin support requires WordPress 5.4.0+. | |
| 16 | 18 | * |
| 17 | - * @see https://core.trac.wordpress.org/ticket/47281 | |
| 18 | - * @see https://core.trac.wordpress.org/changeset/45363 | |
| 19 | + * @see https://core.trac.wordpress.org/ticket/49360 | |
| 20 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/URL | |
| 21 | + * @see https://developer.wordpress.org/reference/functions/wp_default_packages_vendor/ | |
| 19 | 22 | * |
| 20 | - * @since 5.7.0 | |
| 23 | + * @since 7.3.0 | |
| 21 | 24 | * |
| 22 | - * @param string[] $attr Array of allowed CSS attributes. | |
| 25 | + * @param WP_Scripts $scripts WP_Scripts object. | |
| 26 | + */ | |
| 27 | +function gutenberg_add_url_polyfill( $scripts ) { | |
| 28 | + // Only register polyfill if not already registered. This prevents handling | |
| 29 | + // in an environment where core has updated to manage the polyfill. This | |
| 30 | + // depends on the action being handled after default script registration. | |
| 31 | + $is_polyfill_script_registered = (bool) $scripts->query( 'wp-polyfill-url', 'registered' ); | |
| 32 | + if ( $is_polyfill_script_registered ) { | |
| 33 | + return; | |
| 34 | + } | |
| 35 | + | |
| 36 | + gutenberg_register_vendor_script( | |
| 37 | + $scripts, | |
| 38 | + 'wp-polyfill-url', | |
| 39 | + 'https://unpkg.com/[email protected]/polyfills/URL/polyfill.js', | |
| 40 | + array(), | |
| 41 | + '3.42.0' | |
| 42 | + ); | |
| 43 | + | |
| 44 | + did_action( 'init' ) && $scripts->add_inline_script( | |
| 45 | + 'wp-polyfill', | |
| 46 | + wp_get_script_polyfill( | |
| 47 | + $scripts, | |
| 48 | + array( | |
| 49 | + '\'URL\' in window' => 'wp-polyfill-url', | |
| 50 | + ) | |
| 51 | + ) | |
| 52 | + ); | |
| 53 | +} | |
| 54 | +add_action( 'wp_default_scripts', 'gutenberg_add_url_polyfill', 20 ); | |
| 55 | + | |
| 56 | +/** | |
| 57 | + * Adds a polyfill for DOMRect in environments which do not support it. | |
| 23 | 58 | * |
| 24 | - * @return string[] Filtered array of allowed CSS attributes. | |
| 59 | + * This can be removed when plugin support requires WordPress 5.4.0+. | |
| 60 | + * | |
| 61 | + * @see gutenberg_add_url_polyfill | |
| 62 | + * @see https://core.trac.wordpress.org/ticket/49360 | |
| 63 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect | |
| 64 | + * @see https://developer.wordpress.org/reference/functions/wp_default_packages_vendor/ | |
| 65 | + * | |
| 66 | + * @since 7.5.0 | |
| 67 | + * | |
| 68 | + * @param WP_Scripts $scripts WP_Scripts object. | |
| 25 | 69 | */ |
| 26 | -function gutenberg_safe_style_css_column_flex_basis( $attr ) { | |
| 27 | - $attr[] = 'flex-basis'; | |
| 70 | +function gutenberg_add_dom_rect_polyfill( $scripts ) { | |
| 71 | + // Only register polyfill if not already registered. This prevents handling | |
| 72 | + // in an environment where core has updated to manage the polyfill. This | |
| 73 | + // depends on the action being handled after default script registration. | |
| 74 | + $is_polyfill_script_registered = (bool) $scripts->query( 'wp-polyfill-dom-rect', 'registered' ); | |
| 75 | + if ( $is_polyfill_script_registered ) { | |
| 76 | + return; | |
| 77 | + } | |
| 28 | 78 | |
| 29 | - return $attr; | |
| 79 | + gutenberg_register_vendor_script( | |
| 80 | + $scripts, | |
| 81 | + 'wp-polyfill-dom-rect', | |
| 82 | + 'https://unpkg.com/[email protected]/polyfills/DOMRect/polyfill.js', | |
| 83 | + array(), | |
| 84 | + '3.42.0' | |
| 85 | + ); | |
| 86 | + | |
| 87 | + did_action( 'init' ) && $scripts->add_inline_script( | |
| 88 | + 'wp-polyfill', | |
| 89 | + wp_get_script_polyfill( | |
| 90 | + $scripts, | |
| 91 | + array( | |
| 92 | + 'window.DOMRect' => 'wp-polyfill-dom-rect', | |
| 93 | + ) | |
| 94 | + ) | |
| 95 | + ); | |
| 30 | 96 | } |
| 31 | -add_filter( 'safe_style_css', 'gutenberg_safe_style_css_column_flex_basis' ); | |
| 97 | +add_action( 'wp_default_scripts', 'gutenberg_add_dom_rect_polyfill', 20 ); | |
| 32 | 98 | |
| 33 | 99 | /** |
| 34 | 100 | * Sets the current post for usage in template blocks. |
| 35 | 101 | * |