Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#19682 closed feature request (worksforme)

Add hook before_switch_theme to the switch_theme function

Reported by: griffinjt Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.3
Component: Themes Keywords: has-patch needs-testing
Focuses: Cc:


There should be another hook in the switch_theme function that occurs before the previous theme is switched but during the switch theme process. The current switch_theme action hook occurs after the new theme has been activated, which takes away the ability to reference data from the previous theme. The are many use-cases that would warrant such a hook, but one in particular is a theme deactivating plugins specific to that theme (as there would be no use for them once the them has been switched). You can always reference the page and $_GET action, but a hook would be easier to work with in my opinion.

I've suggested the name before_switch_theme, but it could be something else. Just as long as it occurs during the switch theme process but before the current theme is replaced.

Attachments (1)

before_switch_theme.diff (481 bytes) - added by griffinjt 6 years ago.

Download all attachments as: .zip

Change History (5)

#1 @dd32
6 years ago

The switch_theme action is fired whilst the current theme is still active, so in reality, the switch_theme action is a deactivation hook for a theme.

The only downside is that at the time of firing, the template/stylesheet options will now refer to the new theme, however the old themes files will be loaded.

You can use get_option('theme_switched') in the action to retrieve the previous theme details, perhaps we should be passing those details to the switch_theme action itself.

#2 @griffinjt
6 years ago

You are correct. I was wrong. I was able to reference what I needed.

+1 for your idea, though. Then you could specify priority if you wanted to do something before the files were switched.

#3 @dd32
6 years ago

Then you could specify priority if you wanted to do something before the files were switched.

It'd still execute after the theme options have been altered, but at least you'd have easy access to the details.

#4 @SergeyBiryukov
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.