Opened 13 years ago
Closed 13 years ago
#19244 closed defect (bug) (fixed)
get_theme() function incorrectly assuming $themes is always an array
Reported by: | cgrymala | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | 3.2.1 |
Component: | Themes | Keywords: | needs-patch |
Focuses: | 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.
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.