Code Modernization: Replace isset() with null coalescing in WP_Roles::get_role().

Since PHP 7.0 introduced the [https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op 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.

Follow-up to [2703], [61403].

Props dilipbheda, mukesh27, spacedmonkey, SergeyBiryukov.
Fixes #63216. See #58874.
Built from https://develop.svn.wordpress.org/trunk@61404


git-svn-id: http://core.svn.wordpress.org/trunk@60716 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2025-12-23 21:20:31 +00:00
parent e1e3fc707b
commit 3429087f6c
2 changed files with 2 additions and 6 deletions

View File

@@ -268,11 +268,7 @@ class WP_Roles {
* @return WP_Role|null WP_Role object if found, null if the role does not exist.
*/
public function get_role( $role ) {
if ( isset( $this->role_objects[ $role ] ) ) {
return $this->role_objects[ $role ];
} else {
return null;
}
return $this->role_objects[ $role ] ?? null;
}
/**

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-alpha-61403';
$wp_version = '7.0-alpha-61404';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.