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
This commit is contained in:
Weston Ruter
2026-02-12 07:41:40 +00:00
parent 7ea02a0d5f
commit d5eed3cfaf
2 changed files with 9 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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.