PluginProbe
Gutenberg / 12.7.2
Gutenberg v12.7.2
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 / compat.php

compat.php in Gutenberg 12.7.2, at lib/compat.php

81 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Temporary compatibility shims for features present in Gutenberg, pending
4 * upstream commit to the WordPress core source repository. Functions here
5 * exist only as long as necessary for corresponding WordPress support, and
6 * each should be associated with a Trac ticket.
7 *
8 * @package gutenberg
9 */
10
11 /**
12 * Update allowed inline style attributes list.
13 *
14 * Note: This should be removed when the minimum required WP version is >= 5.9.
15 *
16 * @param string[] $attrs Array of allowed CSS attributes.
17 * @return string[] CSS attributes.
18 */
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';
26
27 return $attrs;
28 }
29 add_filter( 'safe_style_css', 'gutenberg_safe_style_attrs' );
30
31 /**
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
38 *
39 * @since 12.1.0
40 * @todo This should be removed when the minimum required WP version is >= 5.9.
41 *
42 * @return void.
43 */
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';
47
48 wp_add_inline_script(
49 'wp-dom-ready',
50 'wp.galleryBlockV2Enabled = ' . $v2_gallery_enabled . ';',
51 'after'
52 );
53 }
54 add_action( 'init', 'gutenberg_check_gallery_block_v2_compatibility' );
55
56 /**
57 * Prevent use_balanceTags being enabled on WordPress 5.8 or earlier as it breaks
58 * the layout of the new Gallery block.
59 *
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.
64 */
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;
76 }
77
78 return $new_value;
79 }
80 add_filter( 'pre_update_option_use_balanceTags', 'gutenberg_use_balancetags_check' );
81