From d5eed3cfaf986488b0e7ac30953de08574dcfd83 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 12 Feb 2026 07:41:40 +0000 Subject: [PATCH] Code Modernization: Use null coalescing operator and improve readability of conditional in `WP_Theme_JSON::get_styles_for_block()`. Developed in https://github.com/WordPress/wordpress-develop/pull/10902 Follow-up to [61607]. Props soean, westonruter, sergeybiryukov, mukesh27. See #63430, #64263. Built from https://develop.svn.wordpress.org/trunk@61621 git-svn-id: http://core.svn.wordpress.org/trunk@60932 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json.php | 10 ++++++++-- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index 9bec104aed..e5cd59ca73 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -2941,7 +2941,13 @@ class WP_Theme_JSON { $style_variation_declarations[ $style_variation['selector'] ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json ); // Process pseudo-selectors for this variation (e.g., :hover, :focus) - $block_name = isset( $block_metadata['name'] ) ? $block_metadata['name'] : ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ? $block_metadata['path'][2] : null ); + if ( isset( $block_metadata['name'] ) ) { + $block_name = $block_metadata['name']; + } elseif ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ) { + $block_name = $block_metadata['path'][2]; + } else { + $block_name = null; + } $variation_pseudo_declarations = static::process_pseudo_selectors( $style_variation_node, $style_variation['selector'], $settings, $block_name ); $style_variation_declarations = array_merge( $style_variation_declarations, $variation_pseudo_declarations ); @@ -3030,7 +3036,7 @@ class WP_Theme_JSON { // For block pseudo-selectors, we need to get the block data first, then access the pseudo-selector $block_name = $block_metadata['path'][2]; // 'core/button' $block_data = _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $block_name ), array() ); - $pseudo_data = isset( $block_data[ $block_pseudo_selector ] ) ? $block_data[ $block_pseudo_selector ] : array(); + $pseudo_data = $block_data[ $block_pseudo_selector ] ?? array(); $declarations = static::compute_style_properties( $pseudo_data, $settings, null, $this->theme_json, $selector, $use_root_padding ); } else { diff --git a/wp-includes/version.php b/wp-includes/version.php index 62d1cc1a1d..e07a676f1d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '7.0-alpha-61620'; +$wp_version = '7.0-alpha-61621'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.