Make WordPress Core

Opened 11 years ago

Last modified 11 years ago

#22252 closed defect (bug)

register_theme_directory() usage can break the current theme — at Version 2

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by:
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.5
Component: Themes Keywords: has-patch
Focuses: Cc:

Description (last modified by johnjamesjacoby)

Problem:

It's possible for the active theme and it's roots to become out of sync when performing a specific set of actions, resulting in the site white-screening because of the active theme directory being incorrect.

Hard to explain, so I've included more information below.


Steps to reproduce:

  1. Activate BuddyPress.
  2. Activate bp-default theme.
  3. Deactivate BuddyPress.
  4. Visit Appearance > Themes.
  5. Check DB: stylesheet and template are changed to 'twentytwelve'.
  6. Check DB: stylesheet_root and template_root still point to '/plugins/buddypress/bp-themes/'.
  7. Reactivate BuddyPress.
  8. Visit Appearance > Themes.
  9. twentytwelve reports back as broken

Stack:

  • wp-admin/themes.php:line 107 calls validate_current_theme()
  • wp-includes/theme.php:719 calls switch_theme()
  • wp-includes/theme.php 682 counts $wp_theme_directories, and skips the roots.
  • This results in the _root options pointing to '/plugins/buddypress/bp-themes', and the current stylesheet and template being set as 'twentytwelve'.
  • If you re-activate BuddyPress, $wp_theme_directories will now be greater than 1, and the _root options will not get updated.

Possible fixes:

  • Remove count( $wp_theme_directories ) check from switch_theme(). This forces the theme root to be accurate every time the theme switches, regardless of how many directories are ever registered. In my opinion, this is the most sensible option. (Patch attached)
  • Improve search_theme_directories() to update 'stylesheet_root' and 'template_root' when 'theme_roots' transient doesn't match up. This works because we're already looping through the $cached_roots to make sure each theme is valid. The problem here is we're depending on the expiration of the transient, and doing additional logic each time that happens. (No patch attached)

Change History (3)

@johnjamesjacoby
11 years ago

Remove $wp_theme_directories check from switch_theme()

#1 @johnjamesjacoby
11 years ago

  • Description modified (diff)

#2 @johnjamesjacoby
11 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.