PluginProbe
Gutenberg / 7.7.2
Gutenberg v7.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/compat.php +85 -50 12.6.07.7.2 View file →
@@ -8,73 +8,108 @@
8 8 * @package gutenberg
9 9 */
10 10
11 11 /**
12 - * Update allowed inline style attributes list.
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`.
13 16 *
14 - * Note: This should be removed when the minimum required WP version is >= 5.9.
17 + * This can be removed when plugin support requires WordPress 5.4.0+.
15 18 *
16 - * @param string[] $attrs Array of allowed CSS attributes.
17 - * @return string[] CSS attributes.
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/
22 + *
23 + * @since 7.3.0
24 + *
25 + * @param WP_Scripts $scripts WP_Scripts object.
18 26 */
19 -function gutenberg_safe_style_attrs( $attrs ) {
20 - $attrs[] = 'object-position';
21 - $attrs[] = 'border-top-left-radius';
22 - $attrs[] = 'border-top-right-radius';
23 - $attrs[] = 'border-bottom-right-radius';
24 - $attrs[] = 'border-bottom-left-radius';
25 - $attrs[] = 'filter';
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 + }
26 35
27 - return $attrs;
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 + );
28 53 }
29 -add_filter( 'safe_style_css', 'gutenberg_safe_style_attrs' );
54 +add_action( 'wp_default_scripts', 'gutenberg_add_url_polyfill', 20 );
30 55
31 56 /**
32 - * The new gallery block format is not compatible with the use_BalanceTags option
33 - * in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130.
34 - * This method adds a variable to the wp namespace to indicate if the new gallery block
35 - * format can be enabled or not. It needs to be added this early and to the wp namespace
36 - * as it needs to be available when the initial block parsing runs on editor load, and most of
37 - * the editor store and standard flags are not loaded yet at that point
57 + * Adds a polyfill for DOMRect in environments which do not support it.
38 58 *
39 - * @since 12.1.0
40 - * @todo This should be removed when the minimum required WP version is >= 5.9.
59 + * This can be removed when plugin support requires WordPress 5.4.0+.
41 60 *
42 - * @return void.
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.
43 69 */
44 -function gutenberg_check_gallery_block_v2_compatibility() {
45 - $use_balance_tags = (int) get_option( 'use_balanceTags' );
46 - $v2_gallery_enabled = boolval( 1 !== $use_balance_tags || is_wp_version_compatible( '5.9' ) ) ? 'true' : 'false';
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 + }
47 78
48 - wp_add_inline_script(
49 - 'wp-dom-ready',
50 - 'wp.galleryBlockV2Enabled = ' . $v2_gallery_enabled . ';',
51 - 'after'
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'
52 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 + );
53 96 }
54 -add_action( 'init', 'gutenberg_check_gallery_block_v2_compatibility' );
97 +add_action( 'wp_default_scripts', 'gutenberg_add_dom_rect_polyfill', 20 );
55 98
56 99 /**
57 - * Prevent use_balanceTags being enabled on WordPress 5.8 or earlier as it breaks
58 - * the layout of the new Gallery block.
100 + * Sets the current post for usage in template blocks.
59 101 *
60 - * @since 12.1.0
61 - * @todo This should be removed when the minimum required WP version is >= 5.9.
62 - *
63 - * @param int $new_value The new value for use_balanceTags.
102 + * @return WP_Post|null The post if any, or null otherwise.
64 103 */
65 -function gutenberg_use_balancetags_check( $new_value ) {
66 - global $wp_version;
67 -
68 - if ( 1 === (int) $new_value && version_compare( $wp_version, '5.9', '<' ) ) {
69 - /* translators: %s: Minimum required version */
70 - $message = sprintf( __( 'Gutenberg requires WordPress %s or later in order to enable the &#8220;Correct invalidly nested XHTML automatically&#8221; option. Please upgrade WordPress before enabling.', 'gutenberg' ), '5.9' );
71 - add_settings_error( 'gutenberg_use_balancetags_check', 'gutenberg_use_balancetags_check', $message, 'error' );
72 - if ( class_exists( 'WP_CLI' ) ) {
73 - WP_CLI::error( $message );
74 - }
75 - return 0;
104 +function gutenberg_get_post_from_context() {
105 + // TODO: Without this temporary fix, an infinite loop can occur where
106 + // posts with post content blocks render themselves recursively.
107 + if ( is_admin() || defined( 'REST_REQUEST' ) ) {
108 + return null;
76 109 }
77 -
78 - return $new_value;
110 + if ( ! in_the_loop() ) {
111 + rewind_posts();
112 + the_post();
113 + }
114 + return get_post();
79 115 }
80 -add_filter( 'pre_update_option_use_balanceTags', 'gutenberg_use_balancetags_check' );