diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 0abef6b636102..2229e4a584ac1 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -820,13 +820,13 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n $schema['settings']['blocks'] = $schema_settings_blocks; // For settings.typography.fontFamilies, make the $schema have all indexes present in the $input. - if ( isset( $input['settings']['typography']['fontFamilies'] )){ - foreach( $input['settings']['typography']['fontFamilies'] as $font_family_key => $value ){ - $schema['settings']['typography']['fontFamilies'][$font_family_key] = static::VALID_SETTINGS['typography']['fontFamilies'][0]; + if ( isset( $input['settings']['typography']['fontFamilies'] ) ) { + foreach ( $input['settings']['typography']['fontFamilies'] as $font_family_key => $value ) { + $schema['settings']['typography']['fontFamilies'][ $font_family_key ] = static::VALID_SETTINGS['typography']['fontFamilies'][0]; // Do the same for fontFace. - if ( isset( $input['settings']['typography']['fontFamilies'][$font_family_key]['fontFace']) ){ - foreach( $input['settings']['typography']['fontFamilies'][$font_family_key]['fontFace'] as $font_face_key => $value2 ){ - $schema['settings']['typography']['fontFamilies'][$font_family_key]['fontFace'][$font_face_key] = static::VALID_SETTINGS['typography']['fontFamilies'][0]['fontFace'][0]; + if ( isset( $input['settings']['typography']['fontFamilies'][ $font_family_key ]['fontFace'] ) ) { + foreach ( $input['settings']['typography']['fontFamilies'][ $font_family_key ]['fontFace'] as $font_face_key => $value2 ) { + $schema['settings']['typography']['fontFamilies'][ $font_family_key ]['fontFace'][ $font_face_key ] = static::VALID_SETTINGS['typography']['fontFamilies'][0]['fontFace'][0]; } } } diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index e27a5c60f18ce..419ae1ef1a728 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -896,7 +896,7 @@ public function test_remove_invalid_element_pseudo_selectors() { $this->assertEqualSetsWithIndex( $expected, $actual ); } - public function test_sanitize_invalid_typography_settings(){ + public function test_sanitize_invalid_typography_settings() { $theme_json = new WP_Theme_JSON_Gutenberg( array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, @@ -907,7 +907,7 @@ public function test_sanitize_invalid_typography_settings(){ array( 'name' => 'Piazzolla', 'slug' => 'piazzolla', - 'badKey' => 'I am invalid', + 'badKey' => 'I am invalid', 'fontFamily' => 'Piazzolla', 'fontFace' => array( array( @@ -920,7 +920,7 @@ public function test_sanitize_invalid_typography_settings(){ ), ), ), - 'src' => 'https://example.com/font.ttf', + 'src' => 'https://example.com/font.ttf', ), ), ) @@ -946,8 +946,8 @@ public function test_sanitize_invalid_typography_settings(){ 'slug' => 'piazzolla', ), ), - ) - ) + ), + ), ); $this->assertSameSetsWithIndex( $expected, $sanitized_theme_json, 'Sanitized theme.json settings do not match.' ); }