Opened 19 months ago
Closed 10 days ago
#62959 closed enhancement (fixed)
Ensure wp_roles() returns an instance of WP_Roles
| Reported by: | marian1 | Owned by: | westonruter |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Role/Capability | Version: | |
| Severity: | minor | Keywords: | has-patch |
| Cc: | Focuses: |
Description
Currently, wp_roles() only checks whether the global variable $wp_roles is set before returning it. As global variables can be overridden, it should verify that $wp_roles is indeed a WP_Roles object to ensure that wp_roles() consistently returns a WP_Roles instance.
Refer to wp_scripts() and wp_styles() for the correct approach.
See #62562 for another example where the type of a global variable is not properly checked.
Change History (3)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The original implementation of
wp_roles()only checked whether the global variable$wp_roleswas set (isset) before returning it. This could lead to issues if$wp_roleswas set to a non-WP_Rolesvalue, resulting in potential errors or unexpected behaviour.The fix introduces an additional check to ensure that
$wp_rolesis an instance ofWP_Roles. If it is not, a newWP_Rolesobject is instantiated, ensuring thatwp_roles()always returns a validWP_Rolesinstance.Trac ticket: https://core.trac.wordpress.org/ticket/62959