Make WordPress Core


Ignore:
Timestamp:
09/23/2026 05:59:05 PM (2 weeks ago)
Author:
westonruter
Message:

Code Quality: Remove unnecessary null coalescing.

In get_current_user_id() the ?? 0 fallback is removed since wp_get_current_user() returns a WP_User, but the (int) cast is retained since the function is pluggable and the ID property may be set to a non-integer value. The deprecated id property is now also cast to an integer in WP_User::__set(), as is done in WP_User::init().

In WP_Http_Cookie::test() the fallback for the path property is removed since the constructor always initializes it to a string, and the fallback for the port property is removed since it was a no-op. The port property and the corresponding constructor $data args are now documented as nullable.

The $authordata global is now documented as WP_User|false|null since it is populated by get_userdata() and is unset outside the loop, which accounts for the null coalescing in get_the_author_meta().

The PHPStan baseline entries which no longer apply are removed.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13674.
Follow-up to r61435, r61454, r61637, r63023.

Props arshidkv12, westonruter, mukesh27.
See #65817.
Fixes #66163.

File:
1 edited

Legend:

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

    r63758 r63899  
    729729        }
    730730        $user = wp_get_current_user();
    731         return (int) ( $user->ID ?? 0 );
     731        return (int) $user->ID;
    732732}
    733733
Note: See TracChangeset for help on using the changeset viewer.