Make WordPress Core

Changeset 61621


Ignore:
Timestamp:
02/12/2026 07:40:48 AM (2 months ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r61620 r61621  
    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 );
     
    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 );
Note: See TracChangeset for help on using the changeset viewer.