From 0d74dbcb9b1ce6cab1ed36dc8ecdeee626ba5ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20W=C3=BCnsch?= Date: Mon, 20 Jul 2026 09:19:57 +0200 Subject: [PATCH] Code Quality: Use the null coalescing operator for isset() return checks. Replace `if ( isset( $x ) ) { return $x; } else { return $default; }` patterns with the null coalescing operator (`??`). --- src/wp-includes/capabilities.php | 6 +----- .../customize/class-wp-customize-selective-refresh.php | 6 +----- src/wp-includes/functions.php | 6 +----- src/wp-includes/http.php | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php index 028e61ec414a8..645ab5588ee5e 100644 --- a/src/wp-includes/capabilities.php +++ b/src/wp-includes/capabilities.php @@ -1163,11 +1163,7 @@ function remove_role( $role ) { function get_super_admins() { global $super_admins; - if ( isset( $super_admins ) ) { - return $super_admins; - } else { - return get_site_option( 'site_admins', array( 'admin' ) ); - } + return $super_admins ?? get_site_option( 'site_admins', array( 'admin' ) ); } /** diff --git a/src/wp-includes/customize/class-wp-customize-selective-refresh.php b/src/wp-includes/customize/class-wp-customize-selective-refresh.php index f51b1e6dc7627..3077d09dcf75e 100644 --- a/src/wp-includes/customize/class-wp-customize-selective-refresh.php +++ b/src/wp-includes/customize/class-wp-customize-selective-refresh.php @@ -120,11 +120,7 @@ public function add_partial( $id, $args = array() ) { * @return WP_Customize_Partial|null The partial, if set. Otherwise null. */ public function get_partial( $id ) { - if ( isset( $this->partials[ $id ] ) ) { - return $this->partials[ $id ]; - } else { - return null; - } + return $this->partials[ $id ] ?? null; } /** diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 6afe9fad0c7ff..30b5a4aae337e 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -1445,11 +1445,7 @@ function get_status_header_desc( $code ) { ); } - if ( isset( $wp_header_to_desc[ $code ] ) ) { - return $wp_header_to_desc[ $code ]; - } else { - return ''; - } + return $wp_header_to_desc[ $code ] ?? ''; } /** diff --git a/src/wp-includes/http.php b/src/wp-includes/http.php index 8280f424934dd..19aec80581a44 100644 --- a/src/wp-includes/http.php +++ b/src/wp-includes/http.php @@ -855,9 +855,5 @@ function _wp_translate_php_url_constant_to_key( $constant ) { PHP_URL_FRAGMENT => 'fragment', ); - if ( isset( $translation[ $constant ] ) ) { - return $translation[ $constant ]; - } else { - return false; - } + return $translation[ $constant ] ?? false; }