WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 2 years ago

#10570 closed enhancement (duplicate)

Flush/Init the $wp_rewrite on theme change.

Reported by: frumph Owned by: westi
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Themes Keywords: reporter-feedback
Focuses: Cc:

Description

With some premium themes adding personal rewrite rules for the theme itself I would like to have it so that if there's a theme change the rewrite rules get reset so those rules in the themes do not bleed into other themes after changing themes.

This will also allow people to check out more themes that have the ability to be more custom towards how it works with the rewrite_rules with custom pages and get_query_var's without messing with their system for the theme they eventually choose.

Change History (7)

comment:1 dd325 years ago

  • Keywords dev-feedback 2nd-opinion added
  • Milestone changed from Unassigned to Future Release
  • Version set to 2.8

Theme authors may hook the 'switch_themes' action to catch when the theme is being deactivated.

add_action('switch_themes', array(&$GLOBALS['wp_rewrite'], 'flush_rules') );

would work for theme authors(who should be taking care of it IMO), or in core..

comment:2 westi5 years ago

  • Keywords reporter-feedback added; dev-feedback 2nd-opinion removed
  • Priority changed from high to normal

That sounds reasonable.

It is hard to have a definitive opinion without seeing what and how the themes are doing stuff.

We really need some example code here - just something simple which demonstrates how and what these themes are doing so we can understand the issue and use-case fully.

comment:3 westi5 years ago

  • Owner set to westi
  • Status changed from new to accepted

comment:4 frumph5 years ago

Just an example off the top of my head, this is no way reflects what the real code is.. but I was working on having for author pages have it change the name author/ to users/ or members/ so that I can create member pages from the author template. Now mind you this works, however switching themes it keeps the /user/ portion of the rewrite while the rest reverts back after switching themes. (bad idea for someone who just wants to check out the theme) So I end up $wp_rewrite->init(); it back after switching themes in whatever theme i'm working on.

So I was thinking, how does this effect generate_rewrite_rules and all of those others, apparently they too stay. So having an init(); or flush_rules(); on switching themes doesn't sound like a bad idea. Premium templete themes that have special rewrite rules associated with them will no longer bleed into other themes used.

if ($some_run_once_var) {
   add_action('init','cp_rewrite_author_to_user',5);
}

function cp_rewrite_author_to_user() {
	global $wp_rewrite;
	$wp_rewrite->author_base = 'user';
	$wp_rewrite->flush_rules();
}

comment:5 follow-up: pbearne3 years ago

  • Cc pbearne added

Hi Guys

I have been keeping an eye on the IIS rewrite rules (We provided the hard-coded rules that in the current code) for a while and it would be very nice to get it sorted.

But that would be easy as it will need a lot of code and testing

there is fork in code between lamp and wimp in the lamp fork their is code to allow plug-in / themes and the WP-core to generate premalinks rule by rule. The Wimp fork writes a hard-coded blog of code with switch between MS and stand alone.

I would love to see the code that generates the rules for lamp to be extended to translate the requested rule into an wimp rule so it can be add rule by rule.

It is a bit of a hack the way it is now.

I have a nice wimp MS setup to help with testing.

comment:6 in reply to: ↑ 5 westi3 years ago

Replying to pbearne:

Hi Guys

I have been keeping an eye on the IIS rewrite rules (We provided the hard-coded rules that in the current code) for a while and it would be very nice to get it sorted.

But that would be easy as it will need a lot of code and testing

there is fork in code between lamp and wimp in the lamp fork their is code to allow plug-in / themes and the WP-core to generate premalinks rule by rule. The Wimp fork writes a hard-coded blog of code with switch between MS and stand alone.

I would love to see the code that generates the rules for lamp to be extended to translate the requested rule into an wimp rule so it can be add rule by rule.

It is a bit of a hack the way it is now.

I have a nice wimp MS setup to help with testing.

That sounds great and warrants a separate ticket.

If you can come up with a translation engine for htaccess rules over to IIS that would be magic :-)

comment:7 johnbillion2 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from accepted to closed

Dupe of #14849 (which was opened after this but has more up to date discussion).

Note: See TracTickets for help on using tickets.