Make WordPress Core

Changeset 63490


Ignore:
Timestamp:
09/05/2026 05:56:32 AM (6 weeks ago)
Author:
westonruter
Message:

Role/Capability: Ensure wp_roles() returns WP_Roles.

Previously wp_roles() only checked whether the $wp_roles global was set before returning it, so any code that overwrote that global with another value caused the function to hand back something which is not a WP_Roles object. Checking instanceof instead guarantees the return type, matching the approach already used by wp_scripts() and wp_styles().

Developed in ​https://github.com/WordPress/wordpress-develop/pull/8315.
Follow-up to r32541.

Props marian1.
See #62562.
Fixes #62959.

File:
1 edited

Legend:

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

    r62895 r63490  
    10791079 * @return WP_Roles WP_Roles global instance if not already instantiated.
    10801080 */
    1081 function wp_roles() {
     1081function wp_roles(): WP_Roles {
    10821082        global $wp_roles;
    10831083
    1084         if ( ! isset( $wp_roles ) ) {
     1084        if ( ! ( $wp_roles instanceof WP_Roles ) ) {
    10851085                $wp_roles = new WP_Roles();
    10861086        }
Note: See TracChangeset for help on using the changeset viewer.