From 8e09fb821a7f8db68761c7c9050a5b707e3f1e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20W=C3=BCnsch?= Date: Fri, 9 Jan 2026 15:28:37 +0100 Subject: [PATCH 1/3] Coding Standards: replace if isset() return with null coalescing. --- src/wp-admin/includes/class-wp-list-table.php | 6 +----- src/wp-admin/includes/class-wp-screen.php | 5 +---- src/wp-includes/class-wp-block-styles-registry.php | 5 +---- src/wp-includes/class-wp-comment.php | 6 +----- src/wp-includes/class-wp-dependencies.php | 5 +---- src/wp-includes/class-wp-plugin-dependencies.php | 12 ++---------- src/wp-includes/class-wp-query.php | 12 ++---------- .../class-wp-user-meta-session-tokens.php | 6 +----- src/wp-includes/class-wp-user-query.php | 6 +----- src/wp-includes/global-styles-and-settings.php | 5 +---- src/wp-includes/http.php | 6 +----- src/wp-includes/nav-menu.php | 5 +---- src/wp-includes/option.php | 5 +---- src/wp-includes/post.php | 6 +----- src/wp-includes/theme.php | 5 +---- 15 files changed, 17 insertions(+), 78 deletions(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 12432e0140b1f..7b84a641f5831 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -345,11 +345,7 @@ public function get_pagination_arg( $key ) { return $this->get_pagenum(); } - if ( isset( $this->_pagination_args[ $key ] ) ) { - return $this->_pagination_args[ $key ]; - } - - return 0; + return $this->_pagination_args[ $key ] ?? 0; } /** diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php index 62b29d51bdb4e..6bb8681cc612d 100644 --- a/src/wp-admin/includes/class-wp-screen.php +++ b/src/wp-admin/includes/class-wp-screen.php @@ -554,10 +554,7 @@ public function get_option( $option, $key = false ) { return null; } if ( $key ) { - if ( isset( $this->_options[ $option ][ $key ] ) ) { - return $this->_options[ $option ][ $key ]; - } - return null; + return $this->_options[ $option ][ $key ] ?? null; } return $this->_options[ $option ]; } diff --git a/src/wp-includes/class-wp-block-styles-registry.php b/src/wp-includes/class-wp-block-styles-registry.php index 60c799898580a..9efdb30157235 100644 --- a/src/wp-includes/class-wp-block-styles-registry.php +++ b/src/wp-includes/class-wp-block-styles-registry.php @@ -170,10 +170,7 @@ public function get_all_registered() { * @return array[] Array whose keys are block style names and whose values are block style properties. */ public function get_registered_styles_for_block( $block_name ) { - if ( isset( $this->registered_block_styles[ $block_name ] ) ) { - return $this->registered_block_styles[ $block_name ]; - } - return array(); + return $this->registered_block_styles[ $block_name ] ?? array(); } /** diff --git a/src/wp-includes/class-wp-comment.php b/src/wp-includes/class-wp-comment.php index b42523da375f7..db5ebcd2cf770 100644 --- a/src/wp-includes/class-wp-comment.php +++ b/src/wp-includes/class-wp-comment.php @@ -323,11 +323,7 @@ public function add_child( WP_Comment $child ) { * @return WP_Comment|false Returns the comment object if found, otherwise false. */ public function get_child( $child_id ) { - if ( isset( $this->children[ $child_id ] ) ) { - return $this->children[ $child_id ]; - } - - return false; + return $this->children[ $child_id ] ?? false; } /** diff --git a/src/wp-includes/class-wp-dependencies.php b/src/wp-includes/class-wp-dependencies.php index c3dc40bc88141..a3182c8697d50 100644 --- a/src/wp-includes/class-wp-dependencies.php +++ b/src/wp-includes/class-wp-dependencies.php @@ -477,10 +477,7 @@ public function query( $handle, $status = 'registered' ) { switch ( $status ) { case 'registered': case 'scripts': // Back compat. - if ( isset( $this->registered[ $handle ] ) ) { - return $this->registered[ $handle ]; - } - return false; + return $this->registered[ $handle ] ?? false; case 'enqueued': case 'queue': // Back compat. diff --git a/src/wp-includes/class-wp-plugin-dependencies.php b/src/wp-includes/class-wp-plugin-dependencies.php index e4dc4b0f40c0c..26b83f0006a36 100644 --- a/src/wp-includes/class-wp-plugin-dependencies.php +++ b/src/wp-includes/class-wp-plugin-dependencies.php @@ -200,11 +200,7 @@ public static function get_dependents( $slug ) { * @return array An array of dependency plugin slugs. */ public static function get_dependencies( $plugin_file ) { - if ( isset( self::$dependencies[ $plugin_file ] ) ) { - return self::$dependencies[ $plugin_file ]; - } - - return array(); + return self::$dependencies[ $plugin_file ] ?? array(); } /** @@ -355,11 +351,7 @@ public static function get_dependency_filepath( $slug ) { public static function get_dependency_data( $slug ) { $dependency_api_data = self::get_dependency_api_data(); - if ( isset( $dependency_api_data[ $slug ] ) ) { - return $dependency_api_data[ $slug ]; - } - - return false; + return $dependency_api_data[ $slug ] ?? false; } /** diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index ad2dda78271a8..1e08b57b3a391 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -1860,11 +1860,7 @@ public function set_404() { * @return mixed Contents of the query variable. */ public function get( $query_var, $default_value = '' ) { - if ( isset( $this->query_vars[ $query_var ] ) ) { - return $this->query_vars[ $query_var ]; - } - - return $default_value; + return $this->query_vars[ $query_var ] ?? $default_value; } /** @@ -4067,11 +4063,7 @@ public function get_queried_object() { public function get_queried_object_id() { $this->get_queried_object(); - if ( isset( $this->queried_object_id ) ) { - return $this->queried_object_id; - } - - return 0; + return $this->queried_object_id ?? 0; } /** diff --git a/src/wp-includes/class-wp-user-meta-session-tokens.php b/src/wp-includes/class-wp-user-meta-session-tokens.php index ecbb23d4e871c..92bdda69c4804 100644 --- a/src/wp-includes/class-wp-user-meta-session-tokens.php +++ b/src/wp-includes/class-wp-user-meta-session-tokens.php @@ -61,11 +61,7 @@ protected function prepare_session( $session ) { protected function get_session( $verifier ) { $sessions = $this->get_sessions(); - if ( isset( $sessions[ $verifier ] ) ) { - return $sessions[ $verifier ]; - } - - return null; + return $sessions[ $verifier ] ?? null; } /** diff --git a/src/wp-includes/class-wp-user-query.php b/src/wp-includes/class-wp-user-query.php index d704dc70340bc..3815023924489 100644 --- a/src/wp-includes/class-wp-user-query.php +++ b/src/wp-includes/class-wp-user-query.php @@ -910,11 +910,7 @@ public function query() { * @return mixed */ public function get( $query_var ) { - if ( isset( $this->query_vars[ $query_var ] ) ) { - return $this->query_vars[ $query_var ]; - } - - return null; + return $this->query_vars[ $query_var ] ?? null; } /** diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index 9027856763a25..938648ad47fa2 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -384,10 +384,7 @@ static function ( $item ) { } ) ); - if ( isset( $result[0] ) ) { - return $result[0]; - } - return ''; + return $result[0] ?? ''; } /** diff --git a/src/wp-includes/http.php b/src/wp-includes/http.php index b343bb69f572b..643efc0a16930 100644 --- a/src/wp-includes/http.php +++ b/src/wp-includes/http.php @@ -266,11 +266,7 @@ function wp_remote_retrieve_header( $response, $header ) { return ''; } - if ( isset( $response['headers'][ $header ] ) ) { - return $response['headers'][ $header ]; - } - - return ''; + return $response['headers'][ $header ] ?? ''; } /** diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 83a67cfe2a800..4971250ae16bd 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -148,10 +148,7 @@ function register_nav_menu( $location, $description ) { */ function get_registered_nav_menus() { global $_wp_registered_nav_menus; - if ( isset( $_wp_registered_nav_menus ) ) { - return $_wp_registered_nav_menus; - } - return array(); + return $_wp_registered_nav_menus ?? array(); } /** diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index ec6ddd9372e4e..7979c119a986f 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -547,10 +547,7 @@ function wp_set_options_autoload( array $options, $autoload ) { */ function wp_set_option_autoload( $option, $autoload ) { $result = wp_set_option_autoload_values( array( $option => $autoload ) ); - if ( isset( $result[ $option ] ) ) { - return $result[ $option ]; - } - return false; + return $result[ $option ] ?? false; } /** diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index ae9900a704f11..8bdf1a6d60cdd 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -2323,11 +2323,7 @@ function remove_post_type_support( $post_type, $feature ) { function get_all_post_type_supports( $post_type ) { global $_wp_post_type_features; - if ( isset( $_wp_post_type_features[ $post_type ] ) ) { - return $_wp_post_type_features[ $post_type ]; - } - - return array(); + return $_wp_post_type_features[ $post_type ] ?? array(); } /** diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 49779728414c7..9aaeba088a7c0 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -3047,10 +3047,7 @@ function get_theme_support( $feature, ...$args ) { case 'custom-logo': case 'custom-header': case 'custom-background': - if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) { - return $_wp_theme_features[ $feature ][0][ $args[0] ]; - } - return false; + return $_wp_theme_features[ $feature ][0][ $args[0] ] ?? false; default: return $_wp_theme_features[ $feature ]; From 4b26e492a5e0dc9d38d481adeaee1bb629957376 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 10 Jan 2026 15:14:15 -0800 Subject: [PATCH 2/3] Remove extraneous line breaks --- src/wp-admin/includes/class-wp-list-table.php | 1 - src/wp-includes/class-wp-plugin-dependencies.php | 1 - src/wp-includes/class-wp-query.php | 1 - src/wp-includes/class-wp-user-meta-session-tokens.php | 1 - src/wp-includes/post.php | 1 - 5 files changed, 5 deletions(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 7b84a641f5831..45849eb595f9c 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -344,7 +344,6 @@ public function get_pagination_arg( $key ) { if ( 'page' === $key ) { return $this->get_pagenum(); } - return $this->_pagination_args[ $key ] ?? 0; } diff --git a/src/wp-includes/class-wp-plugin-dependencies.php b/src/wp-includes/class-wp-plugin-dependencies.php index 26b83f0006a36..67110a8fd2374 100644 --- a/src/wp-includes/class-wp-plugin-dependencies.php +++ b/src/wp-includes/class-wp-plugin-dependencies.php @@ -350,7 +350,6 @@ public static function get_dependency_filepath( $slug ) { */ public static function get_dependency_data( $slug ) { $dependency_api_data = self::get_dependency_api_data(); - return $dependency_api_data[ $slug ] ?? false; } diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 1e08b57b3a391..8edcf80b54400 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -4062,7 +4062,6 @@ public function get_queried_object() { */ public function get_queried_object_id() { $this->get_queried_object(); - return $this->queried_object_id ?? 0; } diff --git a/src/wp-includes/class-wp-user-meta-session-tokens.php b/src/wp-includes/class-wp-user-meta-session-tokens.php index 92bdda69c4804..0a3961803ad1a 100644 --- a/src/wp-includes/class-wp-user-meta-session-tokens.php +++ b/src/wp-includes/class-wp-user-meta-session-tokens.php @@ -60,7 +60,6 @@ protected function prepare_session( $session ) { */ protected function get_session( $verifier ) { $sessions = $this->get_sessions(); - return $sessions[ $verifier ] ?? null; } diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 8bdf1a6d60cdd..e8f37ecc34f31 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -2322,7 +2322,6 @@ function remove_post_type_support( $post_type, $feature ) { */ function get_all_post_type_supports( $post_type ) { global $_wp_post_type_features; - return $_wp_post_type_features[ $post_type ] ?? array(); } From de042b59f67db0d6014be62bbe83070962ce8ad1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 10 Jan 2026 15:24:56 -0800 Subject: [PATCH 3/3] Use null coalescing in additional locations --- src/wp-admin/includes/file.php | 12 ++---------- src/wp-admin/includes/plugin.php | 27 ++++----------------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index a3e5742d00283..610125b252ec0 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -1097,11 +1097,7 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) { * $_POST['action'] must be set and its value must equal $overrides['action'] * or this: */ - $action = 'wp_handle_upload'; - if ( isset( $overrides['action'] ) ) { - $action = $overrides['action']; - } - + $action = $overrides['action'] ?? 'wp_handle_upload'; return _wp_handle_upload( $file, $overrides, $time, $action ); } @@ -1128,11 +1124,7 @@ function wp_handle_sideload( &$file, $overrides = false, $time = null ) { * $_POST['action'] must be set and its value must equal $overrides['action'] * or this: */ - $action = 'wp_handle_sideload'; - if ( isset( $overrides['action'] ) ) { - $action = $overrides['action']; - } - + $action = $overrides['action'] ?? 'wp_handle_sideload'; return _wp_handle_upload( $file, $overrides, $time, $action ); } diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index a9ca5553ad74b..460874ca52181 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/wp-admin/includes/plugin.php @@ -1971,44 +1971,25 @@ function get_admin_page_parent( $parent_page = '' ) { $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; if ( ! empty( $parent_page ) && 'admin.php' !== $parent_page ) { - if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) { - $parent_page = $_wp_real_parent_file[ $parent_page ]; - } - - return $parent_page; + return $_wp_real_parent_file[ $parent_page ] ?? $parent_page; } if ( 'admin.php' === $pagenow && isset( $plugin_page ) ) { foreach ( (array) $menu as $parent_menu ) { if ( $parent_menu[2] === $plugin_page ) { $parent_file = $plugin_page; - - if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { - $parent_file = $_wp_real_parent_file[ $parent_file ]; - } - - return $parent_file; + return $_wp_real_parent_file[ $parent_file ] ?? $parent_file; } } if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { $parent_file = $plugin_page; - - if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { - $parent_file = $_wp_real_parent_file[ $parent_file ]; - } - - return $parent_file; + return $_wp_real_parent_file[ $parent_file ] ?? $parent_file; } } if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) { $parent_file = $pagenow; - - if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { - $parent_file = $_wp_real_parent_file[ $parent_file ]; - } - - return $parent_file; + return $_wp_real_parent_file[ $parent_file ] ?? $parent_file; } foreach ( array_keys( (array) $submenu ) as $parent_page ) {