Skip to content

Commit 94079fd

Browse files
committed
Code Modernization: Use null coalescing operator and improve readability of conditional in WP_Theme_JSON::get_styles_for_block().
Developed in WordPress#10902 Follow-up to [61607]. Props soean, westonruter, sergeybiryukov, mukesh27. See #63430, #64263. git-svn-id: https://develop.svn.wordpress.org/trunk@61621 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3fe3acf commit 94079fd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/wp-includes/class-wp-theme-json.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,13 @@ static function ( $split_selector ) use ( $clean_style_variation_selector ) {
29412941
$style_variation_declarations[ $style_variation['selector'] ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json );
29422942

29432943
// Process pseudo-selectors for this variation (e.g., :hover, :focus)
2944-
$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 );
2944+
if ( isset( $block_metadata['name'] ) ) {
2945+
$block_name = $block_metadata['name'];
2946+
} elseif ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ) {
2947+
$block_name = $block_metadata['path'][2];
2948+
} else {
2949+
$block_name = null;
2950+
}
29452951
$variation_pseudo_declarations = static::process_pseudo_selectors( $style_variation_node, $style_variation['selector'], $settings, $block_name );
29462952
$style_variation_declarations = array_merge( $style_variation_declarations, $variation_pseudo_declarations );
29472953

@@ -3030,7 +3036,7 @@ static function ( $pseudo_selector ) use ( $selector ) {
30303036
// For block pseudo-selectors, we need to get the block data first, then access the pseudo-selector
30313037
$block_name = $block_metadata['path'][2]; // 'core/button'
30323038
$block_data = _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $block_name ), array() );
3033-
$pseudo_data = isset( $block_data[ $block_pseudo_selector ] ) ? $block_data[ $block_pseudo_selector ] : array();
3039+
$pseudo_data = $block_data[ $block_pseudo_selector ] ?? array();
30343040

30353041
$declarations = static::compute_style_properties( $pseudo_data, $settings, null, $this->theme_json, $selector, $use_root_padding );
30363042
} else {

0 commit comments

Comments
 (0)