Make WordPress Core

Opened 5 years ago

Last modified 3 days ago

#14849 assigned enhancement

Rewrite rules should be flushed when you switch themes

Reported by: jorbin Owned by: jorbin
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.0
Component: Permalinks Keywords: needs-patch
Focuses: Cc:


@nacin said so at WCMA, so here's a patch to do it.

Attachments (1)

theme.php.15608.diff (380 bytes) - added by jorbin 5 years ago.

Download all attachments as: .zip

Change History (19)

@jorbin5 years ago

comment:1 @greenshady5 years ago

Why should rewrite rules be flushed when switching themes?

comment:2 follow-up: @filosofo5 years ago

I suppose in case a theme is using custom post types. But it seems that, like plugins, themes that need flushed rules should handle it themselves.

comment:3 in reply to: ↑ 2 @nacin5 years ago

Replying to filosofo:

But it seems that, like plugins, themes that need flushed rules should handle it themselves.

Unfortunately, there's no activation hook for them to do so. (For example P2 uses an option to store whether rules have been flushed.) I suggested this in response to a question for how to handle things that add rewrite rules...

I don't think this patch will work, though, because the new theme isn't included on that pageload so the old rules will still be regenerated. Sounds to me that to do an activation hook for themes, we need to add an autoloaded option to keep track.

comment:4 @greenshady5 years ago

Adding an activation hook sounds like the best solution for this. We have switch_theme, which works on deactivation. Themes that add custom post types and taxonomies should be flushing the rewrite rules themselves.

comment:5 @hakre5 years ago

+1 for theme activation hook.

comment:6 @dd325 years ago

  • Keywords needs-patch added; has-patch removed

resetting keywords since the attached patch will not work as intended.

comment:7 @jane5 years ago

  • Version set to 3.0

If anyone would like to get this in for 3.1, there are a few days left to submit patches for enhancements before freeze.

comment:8 @johnpbloch5 years ago

  • Cc johnpbloch added

comment:9 @nacin5 years ago

  • Milestone changed from 3.1 to Future Release

This is done in 3.0 on wp-admin/themes.php. We should do this better, in conjunction with a real theme activation hook, in the future.

Version 0, edited 5 years ago by nacin (next)

comment:10 @nacin5 years ago

FYI, the jank was removed in 3.1. [17241]. Need to do this properly in 3.2.

comment:11 @WraithKenny4 years ago

  • Cc Ken@… added

comment:12 @scribu3 years ago

Related: #7795

comment:13 @chriscct710 months ago

Can't themes who want to do this simply hook into after_switch_theme and do this?

comment:14 @slackbot3 days ago

This ticket was mentioned in Slack in #core by jorbin. View the logs.

comment:15 @jorbin3 days ago

  • Milestone changed from Future Release to 3.3
  • Resolution set to fixed
  • Status changed from new to closed

r18655 in 3.3 introduced after_switch_theme which can be used for this. Core shouldn't encourage themes to include there own custom rewrite rules.

Also, bad on me for such a bad description.

comment:16 @jorbin3 days ago

  • Milestone changed from 3.3 to 4.4

I didn't consider the use case of needing to get rid of old rewrites from the last theme. Dion pointed it out. Let's fix this in 4.4

comment:17 @chriscct73 days ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:18 @chriscct73 days ago

  • Owner set to jorbin
  • Status changed from reopened to assigned
Note: See TracTickets for help on using tickets.