Make WordPress Core

Changeset 61470


Ignore:
Timestamp:
01/11/2026 06:48:15 AM (8 months ago)
Author:
westonruter
Message:

Code Modernization: Replace if statements with null coalescing operator.

Developed in https://github.com/WordPress/wordpress-develop/pull/10703

Follow-up to [61464], [61463], [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

Props soean, westonruter, mukesh27.
See #58874.
Fixes #64488.

Location:
trunk/src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r61456 r61470  
    345345                        return $this->get_pagenum();
    346346                }
    347 
    348                 if ( isset( $this->_pagination_args[ $key ] ) ) {
    349                         return $this->_pagination_args[ $key ];
    350                 }
    351 
    352                 return 0;
     347                return $this->_pagination_args[ $key ] ?? 0;
    353348        }
    354349
  • trunk/src/wp-admin/includes/class-wp-screen.php

    r61456 r61470  
    555555                }
    556556                if ( $key ) {
    557                         if ( isset( $this->_options[ $option ][ $key ] ) ) {
    558                                 return $this->_options[ $option ][ $key ];
    559                         }
    560                         return null;
     557                        return $this->_options[ $option ][ $key ] ?? null;
    561558                }
    562559                return $this->_options[ $option ];
  • trunk/src/wp-admin/includes/file.php

    r61456 r61470  
    10981098         *  or this:
    10991099         */
    1100         $action = 'wp_handle_upload';
    1101         if ( isset( $overrides['action'] ) ) {
    1102                 $action = $overrides['action'];
    1103         }
    1104 
     1100        $action = $overrides['action'] ?? 'wp_handle_upload';
    11051101        return _wp_handle_upload( $file, $overrides, $time, $action );
    11061102}
     
    11291125         *  or this:
    11301126         */
    1131         $action = 'wp_handle_sideload';
    1132         if ( isset( $overrides['action'] ) ) {
    1133                 $action = $overrides['action'];
    1134         }
    1135 
     1127        $action = $overrides['action'] ?? 'wp_handle_sideload';
    11361128        return _wp_handle_upload( $file, $overrides, $time, $action );
    11371129}
  • trunk/src/wp-admin/includes/plugin.php

    r61270 r61470  
    19721972
    19731973        if ( ! empty( $parent_page ) && 'admin.php' !== $parent_page ) {
    1974                 if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) {
    1975                         $parent_page = $_wp_real_parent_file[ $parent_page ];
    1976                 }
    1977 
    1978                 return $parent_page;
     1974                return $_wp_real_parent_file[ $parent_page ] ?? $parent_page;
    19791975        }
    19801976
     
    19831979                        if ( $parent_menu[2] === $plugin_page ) {
    19841980                                $parent_file = $plugin_page;
    1985 
    1986                                 if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
    1987                                         $parent_file = $_wp_real_parent_file[ $parent_file ];
    1988                                 }
    1989 
    1990                                 return $parent_file;
     1981                                return $_wp_real_parent_file[ $parent_file ] ?? $parent_file;
    19911982                        }
    19921983                }
    19931984                if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
    19941985                        $parent_file = $plugin_page;
    1995 
    1996                         if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
    1997                                         $parent_file = $_wp_real_parent_file[ $parent_file ];
    1998                         }
    1999 
    2000                         return $parent_file;
     1986                        return $_wp_real_parent_file[ $parent_file ] ?? $parent_file;
    20011987                }
    20021988        }
     
    20041990        if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {
    20051991                $parent_file = $pagenow;
    2006 
    2007                 if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
    2008                         $parent_file = $_wp_real_parent_file[ $parent_file ];
    2009                 }
    2010 
    2011                 return $parent_file;
     1992                return $_wp_real_parent_file[ $parent_file ] ?? $parent_file;
    20121993        }
    20131994
  • trunk/src/wp-includes/class-wp-block-styles-registry.php

    r60904 r61470  
    171171         */
    172172        public function get_registered_styles_for_block( $block_name ) {
    173                 if ( isset( $this->registered_block_styles[ $block_name ] ) ) {
    174                         return $this->registered_block_styles[ $block_name ];
    175                 }
    176                 return array();
     173                return $this->registered_block_styles[ $block_name ] ?? array();
    177174        }
    178175
  • trunk/src/wp-includes/class-wp-comment.php

    r59805 r61470  
    324324         */
    325325        public function get_child( $child_id ) {
    326                 if ( isset( $this->children[ $child_id ] ) ) {
    327                         return $this->children[ $child_id ];
    328                 }
    329 
    330                 return false;
     326                return $this->children[ $child_id ] ?? false;
    331327        }
    332328
  • trunk/src/wp-includes/class-wp-dependencies.php

    r61358 r61470  
    478478                        case 'registered':
    479479                        case 'scripts': // Back compat.
    480                                 if ( isset( $this->registered[ $handle ] ) ) {
    481                                         return $this->registered[ $handle ];
    482                                 }
    483                                 return false;
     480                                return $this->registered[ $handle ] ?? false;
    484481
    485482                        case 'enqueued':
  • trunk/src/wp-includes/class-wp-plugin-dependencies.php

    r61006 r61470  
    201201         */
    202202        public static function get_dependencies( $plugin_file ) {
    203                 if ( isset( self::$dependencies[ $plugin_file ] ) ) {
    204                         return self::$dependencies[ $plugin_file ];
    205                 }
    206 
    207                 return array();
     203                return self::$dependencies[ $plugin_file ] ?? array();
    208204        }
    209205
     
    355351        public static function get_dependency_data( $slug ) {
    356352                $dependency_api_data = self::get_dependency_api_data();
    357 
    358                 if ( isset( $dependency_api_data[ $slug ] ) ) {
    359                         return $dependency_api_data[ $slug ];
    360                 }
    361 
    362                 return false;
     353                return $dependency_api_data[ $slug ] ?? false;
    363354        }
    364355
  • trunk/src/wp-includes/class-wp-query.php

    r61449 r61470  
    18611861         */
    18621862        public function get( $query_var, $default_value = '' ) {
    1863                 if ( isset( $this->query_vars[ $query_var ] ) ) {
    1864                         return $this->query_vars[ $query_var ];
    1865                 }
    1866 
    1867                 return $default_value;
     1863                return $this->query_vars[ $query_var ] ?? $default_value;
    18681864        }
    18691865
     
    40674063        public function get_queried_object_id() {
    40684064                $this->get_queried_object();
    4069 
    4070                 if ( isset( $this->queried_object_id ) ) {
    4071                         return $this->queried_object_id;
    4072                 }
    4073 
    4074                 return 0;
     4065                return $this->queried_object_id ?? 0;
    40754066        }
    40764067
  • trunk/src/wp-includes/class-wp-user-meta-session-tokens.php

    r60416 r61470  
    6161        protected function get_session( $verifier ) {
    6262                $sessions = $this->get_sessions();
    63 
    64                 if ( isset( $sessions[ $verifier ] ) ) {
    65                         return $sessions[ $verifier ];
    66                 }
    67 
    68                 return null;
     63                return $sessions[ $verifier ] ?? null;
    6964        }
    7065
  • trunk/src/wp-includes/class-wp-user-query.php

    r61387 r61470  
    911911         */
    912912        public function get( $query_var ) {
    913                 if ( isset( $this->query_vars[ $query_var ] ) ) {
    914                         return $this->query_vars[ $query_var ];
    915                 }
    916 
    917                 return null;
     913                return $this->query_vars[ $query_var ] ?? null;
    918914        }
    919915
  • trunk/src/wp-includes/global-styles-and-settings.php

    r61442 r61470  
    385385                )
    386386        );
    387         if ( isset( $result[0] ) ) {
    388                 return $result[0];
    389         }
    390         return '';
     387        return $result[0] ?? '';
    391388}
    392389
  • trunk/src/wp-includes/http.php

    r60652 r61470  
    267267        }
    268268
    269         if ( isset( $response['headers'][ $header ] ) ) {
    270                 return $response['headers'][ $header ];
    271         }
    272 
    273         return '';
     269        return $response['headers'][ $header ] ?? '';
    274270}
    275271
  • trunk/src/wp-includes/nav-menu.php

    r61465 r61470  
    149149function get_registered_nav_menus() {
    150150        global $_wp_registered_nav_menus;
    151         if ( isset( $_wp_registered_nav_menus ) ) {
    152                 return $_wp_registered_nav_menus;
    153         }
    154         return array();
     151        return $_wp_registered_nav_menus ?? array();
    155152}
    156153
  • trunk/src/wp-includes/option.php

    r61445 r61470  
    548548function wp_set_option_autoload( $option, $autoload ) {
    549549        $result = wp_set_option_autoload_values( array( $option => $autoload ) );
    550         if ( isset( $result[ $option ] ) ) {
    551                 return $result[ $option ];
    552         }
    553         return false;
     550        return $result[ $option ] ?? false;
    554551}
    555552
  • trunk/src/wp-includes/post.php

    r61445 r61470  
    23232323function get_all_post_type_supports( $post_type ) {
    23242324        global $_wp_post_type_features;
    2325 
    2326         if ( isset( $_wp_post_type_features[ $post_type ] ) ) {
    2327                 return $_wp_post_type_features[ $post_type ];
    2328         }
    2329 
    2330         return array();
     2325        return $_wp_post_type_features[ $post_type ] ?? array();
    23312326}
    23322327
  • trunk/src/wp-includes/theme.php

    r61463 r61470  
    30433043                case 'custom-header':
    30443044                case 'custom-background':
    3045                         if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) {
    3046                                 return $_wp_theme_features[ $feature ][0][ $args[0] ];
    3047                         }
    3048                         return false;
     3045                        return $_wp_theme_features[ $feature ][0][ $args[0] ] ?? false;
    30493046
    30503047                default:
Note: See TracChangeset for help on using the changeset viewer.