Opened 18 months ago
Closed 15 months ago
#19244 closed defect (bug) (fixed)
get_theme() function incorrectly assuming $themes is always an array
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.4 |
| Component: | Themes | Version: | 3.2.1 |
| Severity: | normal | Keywords: | needs-patch |
| Cc: |
Description
On line 499 of the current /wp-includes/theme.php file, within the get_theme() function, the array_key_exists() function is being run on the $themes variable, which may not always be an array. If it's not an array, the get_theme() function will throw a PHP warning (which, depending on the user's PHP settings, could also throw additional errors about the headers not being able to be set because of previous output).
The $themes variable is populated from the get_themes() function, which may return an array, or may return boolean false (if search_theme_directories() returns false to the get_themes() function).
I would propose that either get_themes() be modified to always return an array, or that get_theme() be modified to check the data type of the $themes variable before attempting to use the array_key_exists() function. I've attached a patch with the latter suggestion implemented. Thanks.
Attachments (2)
Change History (8)
SergeyBiryukov — 18 months ago
comment:2
SergeyBiryukov — 18 months ago
19244.patch adds more checks and fixes a comment typo in get_theme_roots().
- Keywords needs-patch added; has-patch removed
- Milestone changed from Awaiting Review to Future Release
- Version changed from 3.3 to 3.2.1

Simple fix, but note that core never uses get_theme(). Looks like get_themes() has been able to return a boolean for a few years now. Feels odd, but that's how it (currently) is. But it also looks like a number of locations in core might break if get_themes() returned false. We seem to be inconsistent in casting.