Skip to content

Commit

Permalink
Avoid breaking Gutenberg Navigation blocks (#66)
Browse files Browse the repository at this point in the history
Restore `viewScript` support for non-gutenberg blocks by removing the array item before Gutenberg processes it badly.

Reverts 169a0c4

See #35
  • Loading branch information
dd32 committed Feb 22, 2023
1 parent 440cbe8 commit b2a8675
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions wporg-two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,20 @@ function get_edit_account_url() : string {
}

// Temp fix for TOTP QR code being broken, see: https://meta.trac.wordpress.org/timeline?from=2023-02-21T04%3A40%3A07Z&precision=second.
remove_filter( 'block_type_metadata', 'gutenberg_block_type_metadata_multiple_view_scripts' );
remove_filter( 'block_type_metadata_settings', 'gutenberg_block_type_metadata_view_script', 10, 2 );
// Hotfix for https://github.com/WordPress/gutenberg/pull/48268
add_filter( 'block_type_metadata', function( $metadata ) {
if ( isset( $metadata['viewScript'] ) && ! empty( $metadata['file'] ) && ! str_contains( $metadata['file'], 'plugins/gutenberg/' ) ) {
$metadata['_viewScript'] = $metadata['viewScript'];
$metadata['viewScript'] = [];
}

return $metadata;
}, 9 );
add_filter( 'block_type_metadata', function( $metadata ) {
if ( isset( $metadata['_viewScript'] ) ) {
$metadata['viewScript'] = $metadata['_viewScript'];
unset( $metadata['_viewScript'] );
}

return $metadata;
}, 11 );

0 comments on commit b2a8675

Please sign in to comment.