Commit 6fb31cc42b for wordpress.org
commit 6fb31cc42b08072532c3e9e03bfb456207d0ca08
Author: jonsurrell <jonsurrell@git.wordpress.org>
Date: Mon Sep 7 05:56:50 2026 +0000
Editor: Reuse a common block schema during theme.json sanitization.
`WP_Theme_JSON::sanitize()` rebuilt an identical settings and styles schema for every valid block name. Both schemas are now built once and reused, with block-specific pseudo-selector and custom state entries still added per block. The sanitized output is unchanged.
Backported from https://github.com/WordPress/gutenberg/pull/82203.
Developed in: https://github.com/WordPress/wordpress-develop/pull/13337
Props mreishus.
Fixes #66003.
Built from https://develop.svn.wordpress.org/trunk@63512
git-svn-id: http://core.svn.wordpress.org/trunk@62688 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php
index e600160539..ae6bcff379 100644
--- a/wp-includes/class-wp-theme-json.php
+++ b/wp-includes/class-wp-theme-json.php
@@ -1330,6 +1330,14 @@ class WP_Theme_JSON {
$schema_styles_blocks = array();
$schema_settings_blocks = array();
+ $breakpoint_states = array_keys( $responsive_media_queries );
+
+ $common_block_settings = static::VALID_SETTINGS;
+ // `viewport` and `blockVisibility` are global-only settings and cannot be set per block for now.
+ unset(
+ $common_block_settings['viewport'],
+ $common_block_settings['blockVisibility']
+ );
/*
* Generate a schema for blocks.
@@ -1340,21 +1348,27 @@ class WP_Theme_JSON {
*
* As each variation needs both a `blocks` schema and responsive `blocks` schemas
* for further nested inner `blocks`, the overall schema is generated in multiple passes.
+ *
+ * All blocks start with the same style schema. Build that common schema
+ * once, then add block-specific pseudo and custom states below.
*/
+ $responsive_block_schema = $styles_non_top_level;
+ $responsive_block_schema['elements'] = $schema_styles_elements;
+
+ $common_block_schema = $styles_non_top_level;
+ $common_block_schema['elements'] = $schema_styles_elements;
+
+ foreach ( $breakpoint_states as $breakpoint_state ) {
+ $common_block_schema[ $breakpoint_state ] = $responsive_block_schema;
+ }
+
foreach ( $valid_block_names as $block ) {
- $schema_settings_blocks[ $block ] = static::VALID_SETTINGS;
- // `viewport` and `blockVisibility` are global-only settings and cannot be set per block for now.
- unset( $schema_settings_blocks[ $block ]['viewport'] );
- unset( $schema_settings_blocks[ $block ]['blockVisibility'] );
- $schema_styles_blocks[ $block ] = $styles_non_top_level;
- $schema_styles_blocks[ $block ]['elements'] = $schema_styles_elements;
-
- // Add responsive breakpoint states for all blocks.
- foreach ( array_keys( $responsive_media_queries ) as $breakpoint_state ) {
- $schema_styles_blocks[ $block ][ $breakpoint_state ] = $styles_non_top_level;
- $schema_styles_blocks[ $block ][ $breakpoint_state ]['elements'] = $schema_styles_elements;
+ $schema_settings_blocks[ $block ] = $common_block_settings;
+ $schema_styles_blocks[ $block ] = $common_block_schema;
- if ( isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] ) ) {
+ // Add responsive pseudo-selectors only to blocks that support them.
+ if ( isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] ) ) {
+ foreach ( $breakpoint_states as $breakpoint_state ) {
foreach ( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block ] as $pseudo_selector ) {
$schema_styles_blocks[ $block ][ $breakpoint_state ][ $pseudo_selector ] = $styles_non_top_level;
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index d5a5fecdc7..8c94678239 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63511';
+$wp_version = '7.2-alpha-63512';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.