Make WordPress Core

Changeset 61404


Ignore:
Timestamp:
12/23/2025 09:18:57 PM (8 weeks ago)
Author:
SergeyBiryukov
Message:

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

Since PHP 7.0 introduced the 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-roles.php

    r61354 r61404  
    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
Note: See TracChangeset for help on using the changeset viewer.