Make WordPress Core

Changeset 61431


Ignore:
Timestamp:
01/05/2026 05:22:14 AM (10 months ago)
Author:
westonruter
Message:

Code Modernization: Editor: Use null coalescing operator instead of isset() ternaries.

Developed as a subset of ​https://github.com/WordPress/wordpress-develop/pull/10654
Initially developed in ​https://github.com/WordPress/wordpress-develop/pull/4886

Follow-up to [61430], [61429], [61424], [61404], [61403].

Props costdev, westonruter.
See #58874, #63430.

Location:
trunk/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-advanced.php

    r60043 r61431  
    7070$post_ID = isset( $post_ID ) ? (int) $post_ID : 0;
    7171$user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
    72 $action  = isset( $action ) ? $action : '';
     72$action  = $action ?? '';
    7373
    7474if ( (int) get_option( 'page_for_posts' ) === $post->ID && empty( $post->post_content ) ) {
  • trunk/src/wp-admin/site-editor.php

    r61178 r61431  
    288288wp_add_inline_script(
    289289        'wp-blocks',
    290         sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( isset( $editor_settings['blockCategories'] ) ? $editor_settings['blockCategories'] : array(), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ),
     290        sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( $editor_settings['blockCategories'] ?? array(), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ),
    291291        'after'
    292292);
  • trunk/src/wp-includes/block-editor.php

    r60807 r61431  
    567567        if ( isset( $editor_settings['__experimentalFeatures']['color']['palette'] ) ) {
    568568                $colors_by_origin          = $editor_settings['__experimentalFeatures']['color']['palette'];
    569                 $editor_settings['colors'] = isset( $colors_by_origin['custom'] ) ?
    570                         $colors_by_origin['custom'] : (
    571                                 isset( $colors_by_origin['theme'] ) ?
    572                                         $colors_by_origin['theme'] :
    573                                         $colors_by_origin['default']
    574                         );
     569                $editor_settings['colors'] = $colors_by_origin['custom'] ?? $colors_by_origin['theme'] ?? $colors_by_origin['default'];
    575570        }
    576571        if ( isset( $editor_settings['__experimentalFeatures']['color']['gradients'] ) ) {
    577572                $gradients_by_origin          = $editor_settings['__experimentalFeatures']['color']['gradients'];
    578                 $editor_settings['gradients'] = isset( $gradients_by_origin['custom'] ) ?
    579                         $gradients_by_origin['custom'] : (
    580                                 isset( $gradients_by_origin['theme'] ) ?
    581                                         $gradients_by_origin['theme'] :
    582                                         $gradients_by_origin['default']
    583                         );
     573                $editor_settings['gradients'] = $gradients_by_origin['custom'] ?? $gradients_by_origin['theme'] ?? $gradients_by_origin['default'];
    584574        }
    585575        if ( isset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
    586576                $font_sizes_by_origin         = $editor_settings['__experimentalFeatures']['typography']['fontSizes'];
    587                 $editor_settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ?
    588                         $font_sizes_by_origin['custom'] : (
    589                                 isset( $font_sizes_by_origin['theme'] ) ?
    590                                         $font_sizes_by_origin['theme'] :
    591                                         $font_sizes_by_origin['default']
    592                         );
     577                $editor_settings['fontSizes'] = $font_sizes_by_origin['custom'] ?? $font_sizes_by_origin['theme'] ?? $font_sizes_by_origin['default'];
    593578        }
    594579        if ( isset( $editor_settings['__experimentalFeatures']['color']['custom'] ) ) {
    … …  
    623608        if ( isset( $editor_settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) {
    624609                $spacing_sizes_by_origin         = $editor_settings['__experimentalFeatures']['spacing']['spacingSizes'];
    625                 $editor_settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ?
    626                         $spacing_sizes_by_origin['custom'] : (
    627                                 isset( $spacing_sizes_by_origin['theme'] ) ?
    628                                         $spacing_sizes_by_origin['theme'] :
    629                                         $spacing_sizes_by_origin['default']
    630                         );
     610                $editor_settings['spacingSizes'] = $spacing_sizes_by_origin['custom'] ?? $spacing_sizes_by_origin['theme'] ?? $spacing_sizes_by_origin['default'];
    631611        }
    632612
  • trunk/src/wp-includes/block-template-utils.php

    r61178 r61431  
    383383
    384384        // Prepare metadata from $query.
    385         $slugs_to_include = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
    386         $slugs_to_skip    = isset( $query['slug__not_in'] ) ? $query['slug__not_in'] : array();
    387         $area             = isset( $query['area'] ) ? $query['area'] : null;
    388         $post_type        = isset( $query['post_type'] ) ? $query['post_type'] : '';
     385        $slugs_to_include = $query['slug__in'] ?? array();
     386        $slugs_to_skip    = $query['slug__not_in'] ?? array();
     387        $area             = $query['area'] ?? null;
     388        $post_type        = $query['post_type'] ?? '';
    389389
    390390        $stylesheet = get_stylesheet();
    … …  
    11161116        }
    11171117
    1118         $post_type     = isset( $query['post_type'] ) ? $query['post_type'] : '';
     1118        $post_type     = $query['post_type'] ?? '';
    11191119        $wp_query_args = array(
    11201120                'post_status'         => array( 'auto-draft', 'draft', 'publish' ),
    … …  
    17031703        }
    17041704
    1705         $meta  = isset( $changes->meta_input ) ? $changes->meta_input : array();
    1706         $terms = isset( $changes->tax_input ) ? $changes->tax_input : array();
     1705        $meta  = $changes->meta_input ?? array();
     1706        $terms = $changes->tax_input ?? array();
    17071707
    17081708        if ( empty( $changes->ID ) ) {
  • trunk/src/wp-includes/block-template.php

    r61178 r61431  
    374374
    375375        // Pages.
    376         $page_id = isset( $wp_query->query['page_id'] ) ? $wp_query->query['page_id'] : null;
     376        $page_id = $wp_query->query['page_id'] ?? null;
    377377
    378378        // Posts, including custom post types.
    379         $p = isset( $wp_query->query['p'] ) ? $wp_query->query['p'] : null;
     379        $p = $wp_query->query['p'] ?? null;
    380380
    381381        $post_id = $page_id ? $page_id : $p;
  • trunk/src/wp-includes/blocks.php

    r61019 r61431  
    172172
    173173        $module_asset        = ! empty( $module_asset_path ) ? require $module_asset_path : array();
    174         $module_dependencies = isset( $module_asset['dependencies'] ) ? $module_asset['dependencies'] : array();
    175         $block_version       = isset( $metadata['version'] ) ? $metadata['version'] : false;
    176         $module_version      = isset( $module_asset['version'] ) ? $module_asset['version'] : $block_version;
     174        $module_dependencies = $module_asset['dependencies'] ?? array();
     175        $block_version       = $metadata['version'] ?? false;
     176        $module_version      = $module_asset['version'] ?? $block_version;
    177177
    178178        $supports_interactivity_true = isset( $metadata['supports']['interactivity'] ) && true === $metadata['supports']['interactivity'];
    … …  
    249249        // Asset file for blocks is optional. See https://core.trac.wordpress.org/ticket/60460.
    250250        $script_asset  = ! empty( $script_asset_path ) ? require $script_asset_path : array();
    251         $script_handle = isset( $script_asset['handle'] ) ?
    252                 $script_asset['handle'] :
     251        $script_handle = $script_asset['handle'] ??
    253252                generate_block_asset_handle( $metadata['name'], $field_name, $index );
    254253        if ( wp_script_is( $script_handle, 'registered' ) ) {
    … …  
    258257        $script_path_norm    = wp_normalize_path( realpath( $path . '/' . $script_path ) );
    259258        $script_uri          = get_block_asset_url( $script_path_norm );
    260         $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
    261         $block_version       = isset( $metadata['version'] ) ? $metadata['version'] : false;
    262         $script_version      = isset( $script_asset['version'] ) ? $script_asset['version'] : $block_version;
     259        $script_dependencies = $script_asset['dependencies'] ?? array();
     260        $block_version       = $metadata['version'] ?? false;
     261        $script_version      = $script_asset['version'] ?? $block_version;
    263262        $script_args         = array();
    264263        if ( 'viewScript' === $field_name && $script_uri ) {
    … …  
    10691068        }
    10701069
    1071         $previously_ignored_hooked_blocks = isset( $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] )
    1072                 ? $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks']
    1073                 : array();
     1070        $previously_ignored_hooked_blocks = $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ?? array();
    10741071
    10751072        $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array_unique(
    … …  
    14051402        $root_block       = parse_blocks( $serialized_block )[0];
    14061403
    1407         $ignored_hooked_blocks = isset( $root_block['attrs']['metadata']['ignoredHookedBlocks'] )
    1408                 ? $root_block['attrs']['metadata']['ignoredHookedBlocks']
    1409                 : array();
     1404        $ignored_hooked_blocks = $root_block['attrs']['metadata']['ignoredHookedBlocks'] ?? array();
    14101405
    14111406        if ( ! empty( $ignored_hooked_blocks ) ) {
    … …  
    18241819
    18251820                        $block_content .= traverse_and_serialize_block( $inner_block, $pre_callback, $post_callback );
    1826                         $block_content .= isset( $post_markup ) ? $post_markup : '';
     1821                        $block_content .= $post_markup ?? '';
    18271822
    18281823                        ++$block_index;
    … …  
    19841979
    19851980                $result .= traverse_and_serialize_block( $block, $pre_callback, $post_callback );
    1986                 $result .= isset( $post_markup ) ? $post_markup : '';
     1981                $result .= $post_markup ?? '';
    19871982        }
    19881983
    … …  
    25992594
    26002595        foreach ( $typography_keys as $typography_key ) {
    2601                 $support_for_key = isset( $metadata['supports'][ $typography_key ] ) ? $metadata['supports'][ $typography_key ] : null;
     2596                $support_for_key = $metadata['supports'][ $typography_key ] ?? null;
    26022597
    26032598                if ( null !== $support_for_key ) {
  • trunk/src/wp-includes/class-wp-block-metadata-registry.php

    r59938 r61431  
    179179                $block_name = self::default_identifier_callback( $file_or_folder );
    180180
    181                 return isset( $collection['metadata'][ $block_name ] ) ? $collection['metadata'][ $block_name ] : null;
     181                return $collection['metadata'][ $block_name ] ?? null;
    182182        }
    183183
  • trunk/src/wp-includes/class-wp-block-templates-registry.php

    r61090 r61431  
    7676                        $template->plugin      = $plugin;
    7777                        $template->author      = null;
    78                         $template->content     = isset( $args['content'] ) ? $args['content'] : '';
     78                        $template->content     = $args['content'] ?? '';
    7979                        $template->source      = 'plugin';
    8080                        $template->slug        = $slug;
    8181                        $template->type        = 'wp_template';
    82                         $template->title       = isset( $args['title'] ) ? $args['title'] : $template_name;
    83                         $template->description = isset( $args['description'] ) ? $args['description'] : '';
     82                        $template->title       = $args['title'] ?? $template_name;
     83                        $template->description = $args['description'] ?? '';
    8484                        $template->status      = 'publish';
    8585                        $template->origin      = 'plugin';
    8686                        $template->is_custom   = ! isset( $default_template_types[ $template_name ] );
    87                         $template->post_types  = isset( $args['post_types'] ) ? $args['post_types'] : array();
     87                        $template->post_types  = $args['post_types'] ?? array();
    8888                }
    8989
  • trunk/src/wp-includes/class-wp-block-type.php

    r58073 r61431  
    384384                        return $this->{$new_name};
    385385                }
    386                 return isset( $this->{$new_name}[0] ) ? $this->{$new_name}[0] : null;
     386                return $this->{$new_name}[0] ?? null;
    387387        }
    388388
  • trunk/src/wp-includes/class-wp-block.php

    r60983 r61431  
    223223        public function __get( $name ) {
    224224                if ( 'attributes' === $name ) {
    225                         $this->attributes = isset( $this->parsed_block['attrs'] ) ?
    226                                 $this->parsed_block['attrs'] :
     225                        $this->attributes = $this->parsed_block['attrs'] ??
    227226                                array();
    228227
    … …  
    313312                        foreach ( $supported_block_attributes as $attribute_name ) {
    314313                                // Retain any non-pattern override bindings that might be present.
    315                                 $updated_bindings[ $attribute_name ] = isset( $bindings[ $attribute_name ] )
    316                                         ? $bindings[ $attribute_name ]
    317                                         : array( 'source' => 'core/pattern-overrides' );
     314                                $updated_bindings[ $attribute_name ] = $bindings[ $attribute_name ] ?? array( 'source' => 'core/pattern-overrides' );
    318315                        }
    319316                        $bindings = $updated_bindings;
  • trunk/src/wp-includes/class-wp-classic-to-block-menu-converter.php

    r60325 r61431  
    4545                $menu_items_by_parent_id = static::group_by_parent_id( $menu_items );
    4646
    47                 $first_menu_item = isset( $menu_items_by_parent_id[0] )
    48                         ? $menu_items_by_parent_id[0]
    49                         : array();
     47                $first_menu_item = $menu_items_by_parent_id[0] ?? array();
    5048
    5149                $inner_blocks = static::to_blocks(
  • trunk/src/wp-includes/class-wp-theme-json.php

    r61190 r61431  
    12051205                        // Keep backwards compatibility for support.color.__experimentalDuotone.
    12061206                        if ( null === $duotone_selector ) {
    1207                                 $duotone_support = isset( $block_type->supports['color']['__experimentalDuotone'] )
    1208                                         ? $block_type->supports['color']['__experimentalDuotone']
    1209                                         : null;
     1207                                $duotone_support = $block_type->supports['color']['__experimentalDuotone'] ?? null;
    12101208
    12111209                                if ( $duotone_support ) {
    … …  
    15211519                _deprecated_function( __METHOD__, '6.7.0', 'get_stylesheet' );
    15221520                // Add the global styles root CSS.
    1523                 $stylesheet = isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : '';
     1521                $stylesheet = $this->theme_json['styles']['css'] ?? '';
    15241522
    15251523                // Add the global styles block CSS.
    15261524                if ( isset( $this->theme_json['styles']['blocks'] ) ) {
    15271525                        foreach ( $this->theme_json['styles']['blocks'] as $name => $node ) {
    1528                                 $custom_block_css = isset( $this->theme_json['styles']['blocks'][ $name ]['css'] )
    1529                                         ? $this->theme_json['styles']['blocks'][ $name ]['css']
    1530                                         : null;
     1526                                $custom_block_css = $this->theme_json['styles']['blocks'][ $name ]['css'] ?? null;
    15311527                                if ( $custom_block_css ) {
    15321528                                        $selector    = static::$blocks_metadata[ $name ]['selector'];
    … …  
    15551551                        if ( isset( $item['name'] ) ) {
    15561552                                $custom_templates[ $item['name'] ] = array(
    1557                                         'title'     => isset( $item['title'] ) ? $item['title'] : '',
    1558                                         'postTypes' => isset( $item['postTypes'] ) ? $item['postTypes'] : array( 'page' ),
     1553                                        'title'     => $item['title'] ?? '',
     1554                                        'postTypes' => $item['postTypes'] ?? array( 'page' ),
    15591555                                );
    15601556                        }
    … …  
    15791575                        if ( isset( $item['name'] ) ) {
    15801576                                $template_parts[ $item['name'] ] = array(
    1581                                         'title' => isset( $item['title'] ) ? $item['title'] : '',
    1582                                         'area'  => isset( $item['area'] ) ? $item['area'] : '',
     1577                                        'title' => $item['title'] ?? '',
     1578                                        'area'  => $item['area'] ?? '',
    15831579                                );
    15841580                        }
    … …  
    16501646                }
    16511647
    1652                 $selector                 = isset( $block_metadata['selector'] ) ? $block_metadata['selector'] : '';
     1648                $selector                 = $block_metadata['selector'] ?? '';
    16531649                $has_block_gap_support    = isset( $this->theme_json['settings']['spacing']['blockGap'] );
    16541650                $has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
    … …  
    16671663                                $block_gap_value = static::ROOT_BLOCK_SELECTOR === $selector ? '0.5em' : null;
    16681664                                if ( ! empty( $block_type ) ) {
    1669                                         $block_gap_value = isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] )
    1670                                                 ? $block_type->supports['spacing']['blockGap']['__experimentalDefault']
    1671                                                 : null;
     1665                                        $block_gap_value = $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ?? null;
    16721666                                }
    16731667                        } else {
    … …  
    16951689                                        }
    16961690
    1697                                         $class_name    = isset( $layout_definition['className'] ) ? $layout_definition['className'] : false;
    1698                                         $spacing_rules = isset( $layout_definition['spacingStyles'] ) ? $layout_definition['spacingStyles'] : array();
     1691                                        $class_name    = $layout_definition['className'] ?? false;
     1692                                        $spacing_rules = $layout_definition['spacingStyles'] ?? array();
    16991693
    17001694                                        if (
    … …  
    17521746                        $valid_display_modes = array( 'block', 'flex', 'grid' );
    17531747                        foreach ( $layout_definitions as $layout_definition ) {
    1754                                 $class_name       = isset( $layout_definition['className'] ) ? $layout_definition['className'] : false;
    1755                                 $base_style_rules = isset( $layout_definition['baseStyles'] ) ? $layout_definition['baseStyles'] : array();
     1748                                $class_name       = $layout_definition['className'] ?? false;
     1749                                $base_style_rules = $layout_definition['baseStyles'] ?? array();
    17561750
    17571751                                if (
    … …  
    22352229        protected static function compute_theme_vars( $settings ) {
    22362230                $declarations  = array();
    2237                 $custom_values = isset( $settings['custom'] ) ? $settings['custom'] : array();
     2231                $custom_values = $settings['custom'] ?? array();
    22382232                $css_vars      = static::flatten_tree( $custom_values );
    22392233                foreach ( $css_vars as $key => $value ) {
    … …  
    28452839                $use_root_padding     = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
    28462840                $selector             = $block_metadata['selector'];
    2847                 $settings             = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array();
     2841                $settings             = $this->theme_json['settings'] ?? array();
    28482842                $feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $node );
    28492843                $is_root_selector     = static::ROOT_BLOCK_SELECTOR === $selector;
    … …  
    29262920                );
    29272921
    2928                 $pseudo_selector = isset( $pseudo_matches[0] ) ? $pseudo_matches[0] : null;
     2922                $pseudo_selector = $pseudo_matches[0] ?? null;
    29292923
    29302924                /*
    … …  
    30693063        public function get_root_layout_rules( $selector, $block_metadata ) {
    30703064                $css              = '';
    3071                 $settings         = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array();
     3065                $settings         = $this->theme_json['settings'] ?? array();
    30723066                $use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
    30733067
    … …  
    30773071                 */
    30783072                if ( isset( $settings['layout']['contentSize'] ) || isset( $settings['layout']['wideSize'] ) ) {
    3079                         $content_size = isset( $settings['layout']['contentSize'] ) ? $settings['layout']['contentSize'] : $settings['layout']['wideSize'];
     3073                        $content_size = $settings['layout']['contentSize'] ?? $settings['layout']['wideSize'];
    30803074                        $content_size = static::is_safe_css_declaration( 'max-width', $content_size ) ? $content_size : 'initial';
    3081                         $wide_size    = isset( $settings['layout']['wideSize'] ) ? $settings['layout']['wideSize'] : $settings['layout']['contentSize'];
     3075                        $wide_size    = $settings['layout']['wideSize'] ?? $settings['layout']['contentSize'];
    30823076                        $wide_size    = static::is_safe_css_declaration( 'max-width', $wide_size ) ? $wide_size : 'initial';
    30833077                        $css         .= static::ROOT_CSS_PROPERTIES_SELECTOR . ' { --wp--style--global--content-size: ' . $content_size . ';';
    … …  
    40664060                _deprecated_function( __METHOD__, '6.6.0' );
    40674061
    4068                 $spacing_scale = isset( $this->theme_json['settings']['spacing']['spacingScale'] )
    4069                         ? $this->theme_json['settings']['spacing']['spacingScale']
    4070                         : array();
     4062                $spacing_scale = $this->theme_json['settings']['spacing']['spacingScale'] ?? array();
    40714063
    40724064                if ( ! isset( $spacing_scale['steps'] )
    … …  
    44024394                }
    44034395
    4404                 $settings = isset( $this->theme_json['settings'] )
    4405                         ? $this->theme_json['settings']
    4406                         : array();
     4396                $settings = $this->theme_json['settings'] ?? array();
    44074397
    44084398                foreach ( $metadata['selectors'] as $feature => $feature_selectors ) {
    … …  
    45334523                                                        ),
    45344524                                                        array(
    4535                                                                 isset( $values[ $key_in_values ] ) ? $values[ $key_in_values ] : $rule_to_replace,
    4536                                                                 isset( $values[ $fallback ] ) ? $values[ $fallback ] : $fallback,
     4525                                                                $values[ $key_in_values ] ?? $rule_to_replace,
     4526                                                                $values[ $fallback ] ?? $fallback,
    45374527                                                        ),
    45384528                                                        $resolved_style
Note: See TracChangeset for help on using the changeset viewer.