Opened 9 months ago
Last modified 9 months ago
#62959 new enhancement
Ensure wp_roles() returns an instance of WP_Roles
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | minor | Version: | |
| Component: | Role/Capability | Keywords: | has-patch |
| Focuses: | Cc: |
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 (1)
This ticket was mentioned in PR #8315 on WordPress/wordpress-develop by @marian1.
9 months ago
#1
- Keywords has-patch added
Note: See
TracTickets for help on using
tickets.
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