From afee26086fea307c2a5c31c0e2018cb6acd598f7 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 15 Jun 2021 21:36:07 +0000 Subject: [PATCH] Editor: Check if `supports` metadata key is defined before migrating typography keys. This avoids an "Undefined index" PHP notice on blocks without a `supports` key in `block.json`. Follow-up to [51089], [51153], [51159]. Props walbo. Fixes #53416. git-svn-id: https://develop.svn.wordpress.org/trunk@51167 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index d4a0554fc0..1c1de18254 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -986,6 +986,10 @@ function block_has_support( $block_type, $feature, $default = false ) { * @return array Filtered metadata for registering a block type. */ function wp_migrate_old_typography_shape( $metadata ) { + if ( ! isset( $metadata['supports'] ) ) { + return $metadata; + } + $typography_keys = array( '__experimentalFontFamily', '__experimentalFontStyle', @@ -996,8 +1000,10 @@ function wp_migrate_old_typography_shape( $metadata ) { 'fontSize', 'lineHeight', ); + foreach ( $typography_keys as $typography_key ) { $support_for_key = _wp_array_get( $metadata['supports'], array( $typography_key ), null ); + if ( null !== $support_for_key ) { _doing_it_wrong( 'register_block_type_from_metadata()', @@ -1012,10 +1018,12 @@ function wp_migrate_old_typography_shape( $metadata ) { ), '5.8.0' ); + _wp_array_set( $metadata['supports'], array( 'typography', $typography_key ), $support_for_key ); unset( $metadata['supports'][ $typography_key ] ); } } + return $metadata; }