Make WordPress Core

Changeset 61403


Ignore:
Timestamp:
12/22/2025 11:12:59 PM (7 weeks ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Replace some isset() ternary checks with null coalescing.

Since PHP 7.0 introduced the null coalescing operator, and WordPress now requires at least PHP 7.2.24, isset( $var ) ? $var : null ternary checks can be safely replaced with the more concise $var ?? null syntax.

As some new code using the null coalescing operator has already been introduced into core in recent releases, this commit continues with the code modernization by implementing incremental changes for easier review.

Props seanwei, getsyash, krupalpanchal, wildworks, jorbin, SergeyBiryukov.
Fixes #63430. See #58874.

Location:
trunk/src/wp-includes
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment-query.php

    r61105 r61403  
    950950        $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
    951951
    952         $fields  = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    953         $join    = isset( $clauses['join'] ) ? $clauses['join'] : '';
    954         $where   = isset( $clauses['where'] ) ? $clauses['where'] : '';
    955         $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    956         $limits  = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
    957         $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
     952        $fields  = $clauses['fields'] ?? '';
     953        $join    = $clauses['join'] ?? '';
     954        $where   = $clauses['where'] ?? '';
     955        $orderby = $clauses['orderby'] ?? '';
     956        $limits  = $clauses['limits'] ?? '';
     957        $groupby = $clauses['groupby'] ?? '';
    958958
    959959        $this->filtered_where_clause = $where;
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r60909 r61403  
    12271227        $attachments      = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array();
    12281228        $posts            = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array();
    1229         $options          = isset( $starter_content['options'] ) ? $starter_content['options'] : array();
     1229        $options          = $starter_content['options'] ?? array();
    12301230        $nav_menus        = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array();
    1231         $theme_mods       = isset( $starter_content['theme_mods'] ) ? $starter_content['theme_mods'] : array();
     1231        $theme_mods       = $starter_content['theme_mods'] ?? array();
    12321232
    12331233        // Widgets.
     
    14961496                $nav_menu_setting_id,
    14971497                array(
    1498                     'name' => isset( $nav_menu['name'] ) ? $nav_menu['name'] : $nav_menu_location,
     1498                    'name' => $nav_menu['name'] ?? $nav_menu_location,
    14991499                )
    15001500            );
     
    52405240                    'section'       => 'title_tagline',
    52415241                    'priority'      => 8,
    5242                     'height'        => isset( $custom_logo_args[0]['height'] ) ? $custom_logo_args[0]['height'] : null,
    5243                     'width'         => isset( $custom_logo_args[0]['width'] ) ? $custom_logo_args[0]['width'] : null,
    5244                     'flex_height'   => isset( $custom_logo_args[0]['flex-height'] ) ? $custom_logo_args[0]['flex-height'] : null,
    5245                     'flex_width'    => isset( $custom_logo_args[0]['flex-width'] ) ? $custom_logo_args[0]['flex-width'] : null,
     5242                    'height'        => $custom_logo_args[0]['height'] ?? null,
     5243                    'width'         => $custom_logo_args[0]['width'] ?? null,
     5244                    'flex_height'   => $custom_logo_args[0]['flex-height'] ?? null,
     5245                    'flex_width'    => $custom_logo_args[0]['flex-width'] ?? null,
    52465246                    'button_labels' => array(
    52475247                        'select'       => __( 'Select logo' ),
  • trunk/src/wp-includes/class-wp-http-requests-response.php

    r56825 r61403  
    165165                    'name'      => $cookie->name,
    166166                    'value'     => urldecode( $cookie->value ),
    167                     'expires'   => isset( $cookie->attributes['expires'] ) ? $cookie->attributes['expires'] : null,
    168                     'path'      => isset( $cookie->attributes['path'] ) ? $cookie->attributes['path'] : null,
    169                     'domain'    => isset( $cookie->attributes['domain'] ) ? $cookie->attributes['domain'] : null,
    170                     'host_only' => isset( $cookie->flags['host-only'] ) ? $cookie->flags['host-only'] : null,
     167                    'expires'   => $cookie->attributes['expires'] ?? null,
     168                    'path'      => $cookie->attributes['path'] ?? null,
     169                    'domain'    => $cookie->attributes['domain'] ?? null,
     170                    'host_only' => $cookie->flags['host-only'] ?? null,
    171171                )
    172172            );
  • trunk/src/wp-includes/class-wp-network-query.php

    r60697 r61403  
    461461        $clauses = apply_filters_ref_array( 'networks_clauses', array( compact( $pieces ), &$this ) );
    462462
    463         $fields  = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    464         $join    = isset( $clauses['join'] ) ? $clauses['join'] : '';
    465         $where   = isset( $clauses['where'] ) ? $clauses['where'] : '';
    466         $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    467         $limits  = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
    468         $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
     463        $fields  = $clauses['fields'] ?? '';
     464        $join    = $clauses['join'] ?? '';
     465        $where   = $clauses['where'] ?? '';
     466        $orderby = $clauses['orderby'] ?? '';
     467        $limits  = $clauses['limits'] ?? '';
     468        $groupby = $clauses['groupby'] ?? '';
    469469
    470470        if ( $where ) {
  • trunk/src/wp-includes/class-wp-query.php

    r61387 r61403  
    30203020            $clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
    30213021
    3022             $where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
    3023             $groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
    3024             $join     = isset( $clauses['join'] ) ? $clauses['join'] : '';
    3025             $orderby  = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    3026             $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
    3027             $fields   = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    3028             $limits   = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
     3022            $where    = $clauses['where'] ?? '';
     3023            $groupby  = $clauses['groupby'] ?? '';
     3024            $join     = $clauses['join'] ?? '';
     3025            $orderby  = $clauses['orderby'] ?? '';
     3026            $distinct = $clauses['distinct'] ?? '';
     3027            $fields   = $clauses['fields'] ?? '';
     3028            $limits   = $clauses['limits'] ?? '';
    30293029        }
    30303030
     
    31543154            $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
    31553155
    3156             $where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
    3157             $groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
    3158             $join     = isset( $clauses['join'] ) ? $clauses['join'] : '';
    3159             $orderby  = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    3160             $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
    3161             $fields   = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    3162             $limits   = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
     3156            $where    = $clauses['where'] ?? '';
     3157            $groupby  = $clauses['groupby'] ?? '';
     3158            $join     = $clauses['join'] ?? '';
     3159            $orderby  = $clauses['orderby'] ?? '';
     3160            $distinct = $clauses['distinct'] ?? '';
     3161            $fields   = $clauses['fields'] ?? '';
     3162            $limits   = $clauses['limits'] ?? '';
    31633163        }
    31643164
  • trunk/src/wp-includes/class-wp-site-query.php

    r60697 r61403  
    675675        $clauses = apply_filters_ref_array( 'sites_clauses', array( compact( $pieces ), &$this ) );
    676676
    677         $fields  = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    678         $join    = isset( $clauses['join'] ) ? $clauses['join'] : '';
    679         $where   = isset( $clauses['where'] ) ? $clauses['where'] : '';
    680         $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    681         $limits  = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
    682         $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
     677        $fields  = $clauses['fields'] ?? '';
     678        $join    = $clauses['join'] ?? '';
     679        $where   = $clauses['where'] ?? '';
     680        $orderby = $clauses['orderby'] ?? '';
     681        $limits  = $clauses['limits'] ?? '';
     682        $groupby = $clauses['groupby'] ?? '';
    683683
    684684        if ( $where ) {
  • trunk/src/wp-includes/class-wp-term-query.php

    r61048 r61403  
    728728        $clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args );
    729729
    730         $fields   = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    731         $join     = isset( $clauses['join'] ) ? $clauses['join'] : '';
    732         $where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
    733         $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
    734         $orderby  = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    735         $order    = isset( $clauses['order'] ) ? $clauses['order'] : '';
    736         $limits   = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
     730        $fields   = $clauses['fields'] ?? '';
     731        $join     = $clauses['join'] ?? '';
     732        $where    = $clauses['where'] ?? '';
     733        $distinct = $clauses['distinct'] ?? '';
     734        $orderby  = $clauses['orderby'] ?? '';
     735        $order    = $clauses['order'] ?? '';
     736        $limits   = $clauses['limits'] ?? '';
    737737
    738738        $fields_is_filtered = implode( ', ', $selects ) !== $fields;
Note: See TracChangeset for help on using the changeset viewer.