Skip to content

Commit 63e679c

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@61404 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3d9fde3 commit 63e679c

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/wp-includes/class-wp-roles.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,7 @@ public function remove_cap( $role, $cap ) {
268268
* @return WP_Role|null WP_Role object if found, null if the role does not exist.
269269
*/
270270
public function get_role( $role ) {
271-
if ( isset( $this->role_objects[ $role ] ) ) {
272-
return $this->role_objects[ $role ];
273-
} else {
274-
return null;
275-
}
271+
return $this->role_objects[ $role ] ?? null;
276272
}
277273

278274
/**

0 commit comments

Comments
 (0)