Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gallery block: turn on auto-migration of v1 Gallery blocks to v2 format when edited #36191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
af87cc0
Update experimental flag to block sites with use_BalanceTags option e…
Nov 4, 2021
09077a8
Remove update gallery modal
Nov 29, 2021
69b0899
Add check for gallery v2 compat to editor init so it is available whe…
Nov 5, 2021
ea46fd4
Remove references to gallery experimental flag
Nov 5, 2021
d1743b6
Revert "Remove references to gallery experimental flag"
Nov 9, 2021
cba6433
Abstract out the check for v2 gallery support and use the existing ex…
Nov 10, 2021
6e6e643
Add missing transformation updates
Nov 10, 2021
5e8db76
Update fixture to be compat with v2 of gallery block
Nov 10, 2021
40af59f
Fix unit tests
Nov 10, 2021
f5bed90
Fix issue with link destination not being set when block migrated
Nov 11, 2021
6cbc1f7
Check that we have a v1 gallery block before we send content through …
Nov 16, 2021
e79cdbe
Use `window.wp` global instead of store for gallery flag
mkevins Nov 16, 2021
857d01b
Remove unnecessary destructuring
mkevins Nov 16, 2021
970f717
Move the setting of wp.galleryBlockV2Enabled to directly after wp-dom…
Nov 16, 2021
2054a31
Add optional chaining operator to prevent error if images attribute n…
Nov 17, 2021
3b416e8
Simplify deprecations, etc. by always using using v1 methods if use_b…
Nov 17, 2021
d191bcb
Fix potential issue with attributes not being returned from v6 deprec…
Nov 17, 2021
7700d5c
Move assignment of gallery global flag to native Editor
mkevins Nov 19, 2021
9f06d77
Move mocking of the galleryBlockV2Enabled flag to the jest globals file
Nov 21, 2021
9774355
Explicitly check for galleryBlockV2Enabled being false and default to…
Nov 21, 2021
5bc1aa2
Fail early if window.wp.galleryBlockV2Enabled is not a boolean
Nov 22, 2021
de9d187
Default to `true` for gallery flag when not yet cached
mkevins Nov 23, 2021
9504e11
Only update gallery flag if fetch result is explicitly boolean
mkevins Nov 24, 2021
a6bfee5
Update editor settings response to the editor to include gallery flag
mkevins Nov 24, 2021
f2df281
Leave gallery flag `undefined` when not cached
mkevins Nov 25, 2021
2226e57
Update the wording of the mobile warning
Nov 28, 2021
06b540c
Add filter to prevent use_balanceTags being enabled on WP < 5.9
Nov 29, 2021
ad7ec30
Switch to using settings_error for use_balanceTags notice
Nov 29, 2021
cff2300
Add a CLI error message
Nov 29, 2021
c752d64
Fix linting error
Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,54 @@ function gutenberg_safe_style_attrs( $attrs ) {
return $attrs;
}
add_filter( 'safe_style_css', 'gutenberg_safe_style_attrs' );

/**
* The new gallery block format is not compatible with the use_BalanceTags option
* in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130.
* This method adds a variable to the wp namespace to indicate if the new gallery block
* format can be enabled or not. It needs to be added this early and to the wp namespace
* as it needs to be available when the intial block parsing runs on editor load, and most of
* the editor store and standard flags are not loaded yet at that point
*
* @since 12.1.0
* @todo This should be removed when the minimum required WP version is >= 5.9.
*
* @return void.
*/
function gutenberg_check_gallery_block_v2_compatibility() {
$use_balance_tags = (int) get_option( 'use_balanceTags' );
$v2_gallery_enabled = boolval( 1 !== $use_balance_tags || is_wp_version_compatible( '5.9' ) ) ? 'true' : 'false';

wp_add_inline_script(
'wp-dom-ready',
'wp.galleryBlockV2Enabled = ' . $v2_gallery_enabled . ';',
'after'
);
}
add_action( 'init', 'gutenberg_check_gallery_block_v2_compatibility' );

/**
* Prevent use_balanceTags being enabled on WordPress 5.8 or earlier as it breaks
* the layout of the new Gallery block.
*
* @since 12.1.0
* @todo This should be removed when the minimum required WP version is >= 5.9.
*
* @param int $new_value The new value for use_balanceTags.
*/
function gutenberg_use_balancetags_check( $new_value ) {
global $wp_version;

if ( 1 === (int) $new_value && version_compare( $wp_version, '5.9', '<' ) ) {
/* translators: %s: Minimum required version */
$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' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a biggie, but would it possible to strip or replace the HTML entities for the CLI?

Screen Shot 2021-11-30 at 11 36 00 am

Copy link
Contributor Author

@glendaviesnz glendaviesnz Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chance of somebody toggling on this option via CLI with gutenberg 12.1+ on WP < 5.9 is so slim as to not warrant the bother of adding a string replace method here in my view.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair enough to me 👍

add_settings_error( 'gutenberg_use_balancetags_check', 'gutenberg_use_balancetags_check', $message, 'error' );
if ( class_exists( 'WP_CLI' ) ) {
WP_CLI::error( $message );
}
return 0;
}

return $new_value;
}
add_filter( 'pre_update_option_use_balanceTags', 'gutenberg_use_balancetags_check' );
2 changes: 1 addition & 1 deletion lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function gutenberg_experiments_editor_settings( $settings ) {
// This bypass needs to remain in place until this is resolved and a patch released.
// https://core.trac.wordpress.org/ticket/54130.
$experiments_settings = array(
'__unstableGalleryWithImageBlocks' => (int) get_option( 'use_balanceTags' ) !== 1,
'__unstableGalleryWithImageBlocks' => (int) get_option( 'use_balanceTags' ) !== 1 || is_wp_version_compatible( '5.9' ),
);
return array_merge( $settings, $experiments_settings );
}
Expand Down
Loading