Commit 7eb382fe4f for wordpress.org

commit 7eb382fe4ff50f9f4054815779a93d1f5b847055
Author: westonruter <westonruter@git.wordpress.org>
Date:   Tue Sep 8 06:05:53 2026 +0000

    Code Quality: Combine registered block styles with `array_merge()`.

    In `WP_REST_Block_Types_Controller` the block styles registered for a block are combined with `array_merge()`, where `wp_parse_args()` had been used erroneously on what are two lists. In support of this, a global `Block_Style_Properties` type alias is introduced for the shape of a registered block style.

    Developed in https://github.com/WordPress/wordpress-develop/pull/13432.
    Follow-up to r48173, r59760, r63522.

    Props westonruter, swissspidy.
    See #65817, #65860.

    Built from https://develop.svn.wordpress.org/trunk@63524


    git-svn-id: http://core.svn.wordpress.org/trunk@62700 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wp-block-styles-registry.php b/wp-includes/class-wp-block-styles-registry.php
index c802fab066..46ebc0c5a3 100644
--- a/wp-includes/class-wp-block-styles-registry.php
+++ b/wp-includes/class-wp-block-styles-registry.php
@@ -19,7 +19,8 @@ final class WP_Block_Styles_Registry {
 	 *
 	 * @since 5.3.0
 	 *
-	 * @var array[]
+	 * @var array<string, array<string, array<string, mixed>>>
+	 * @phpstan-var array<string, array<string, Block_Style_Properties>>
 	 */
 	private $registered_block_styles = array();

@@ -50,14 +51,14 @@ final class WP_Block_Styles_Registry {
 	 * @param array           $style_properties {
 	 *     Array containing the properties of the style.
 	 *
-	 *     @type string $name         The identifier of the style used to compute a CSS class.
-	 *     @type string $label        A human-readable label for the style.
-	 *     @type string $inline_style Inline CSS code that registers the CSS class required
-	 *                                for the style.
-	 *     @type string $style_handle The handle to an already registered style that should be
-	 *                                enqueued in places where block styles are needed.
-	 *     @type bool   $is_default   Whether this is the default style for the block type.
-	 *     @type array  $style_data   Theme.json-like object to generate CSS from.
+	 *     @type string               $name         The identifier of the style used to compute a CSS class.
+	 *     @type string               $label        A human-readable label for the style.
+	 *     @type string               $inline_style Inline CSS code that registers the CSS class required
+	 *                                              for the style.
+	 *     @type string               $style_handle The handle to an already registered style that should be
+	 *                                              enqueued in places where block styles are needed.
+	 *     @type bool                 $is_default   Whether this is the default style for the block type.
+	 *     @type array<string, mixed> $style_data   Theme.json-like object to generate CSS from.
 	 * }
 	 * @return bool True if the block style was registered with success and false otherwise.
 	 */
@@ -140,7 +141,8 @@ final class WP_Block_Styles_Registry {
 	 *
 	 * @param string $block_name       Block type name including namespace.
 	 * @param string $block_style_name Block style name.
-	 * @return array|null Registered block style properties or `null` if the block style is not registered.
+	 * @return array<string, mixed>|null Registered block style properties or `null` if the block style is not registered.
+	 * @phpstan-return Block_Style_Properties|null
 	 */
 	public function get_registered( $block_name, $block_style_name ) {
 		if ( ! $this->is_registered( $block_name, $block_style_name ) ) {
@@ -155,7 +157,9 @@ final class WP_Block_Styles_Registry {
 	 *
 	 * @since 5.3.0
 	 *
-	 * @return array[] Array of arrays containing the registered block styles properties grouped by block type.
+	 * @return array<string, array<string, array<string, mixed>>> Array of arrays containing the registered block styles
+	 *                                                            properties grouped by block type.
+	 * @phpstan-return array<string, array<string, Block_Style_Properties>>
 	 */
 	public function get_all_registered() {
 		return $this->registered_block_styles;
@@ -167,7 +171,9 @@ final class WP_Block_Styles_Registry {
 	 * @since 5.3.0
 	 *
 	 * @param string $block_name Block type name including namespace.
-	 * @return array[] Array whose keys are block style names and whose values are block style properties.
+	 * @return array<string, array<string, mixed>> Array whose keys are block style names and whose values are
+	 *                                             block style properties.
+	 * @phpstan-return array<string, Block_Style_Properties>
 	 */
 	public function get_registered_styles_for_block( $block_name ) {
 		return $this->registered_block_styles[ $block_name ] ?? array();
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
index 9b099a44a2..fa2dfd10d3 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
@@ -330,9 +330,21 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
 		}

 		if ( rest_is_field_included( 'styles', $fields ) ) {
-			$styles         = $this->style_registry->get_registered_styles_for_block( $block_type->name );
-			$styles         = array_values( $styles );
-			$data['styles'] = wp_parse_args( $styles, $data['styles'] );
+			$styles = $this->style_registry->get_registered_styles_for_block( $block_type->name );
+			$styles = array_values( $styles );
+
+			/*
+			 * The loop above assigns this key from rest_sanitize_value_from_schema(), whose
+			 * return is documented as `mixed|WP_Error`, so what the styles came back as has
+			 * to be restated here. A WP_Error is why the value is checked rather than cast.
+			 */
+			/**
+			 * @var array<string, mixed>[] $block_styles
+			 * @phpstan-var list<Block_Style_Properties> $block_styles
+			 */
+			$block_styles = isset( $data['styles'] ) && is_array( $data['styles'] ) ? $data['styles'] : array();
+
+			$data['styles'] = array_merge( $block_styles, $styles );
 			$data['styles'] = array_filter( $data['styles'] );
 		}

diff --git a/wp-includes/version.php b/wp-includes/version.php
index 3afaf21e26..33f04d0613 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-alpha-63523';
+$wp_version = '7.2-alpha-63524';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.