Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#33835 closed defect (bug) (invalid)

action switch_theme, after_switch_theme should not be trigged when switch_theme for child site.

Reported by: nguyenvanduocit's profile nguyenvanduocit Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Networks and Sites Keywords: reporter-feedback
Focuses: multisite Cc:

Description

If you hook to after_switch_theme ( on network's theme ) for initialize some default values, then your switch theme for child site by this line :

switch_to_blog( $child_site_Id );
switch_theme( $new_theme_name );
restore_current_blog();

The hook after_switch_theme will be trigger on network's theme.
I think it is incorrect.

Change History (2)

#1 @jeremyfelt
9 years ago

  • Keywords reporter-feedback added

Hi @nguyenvanduocit, thanks for the report. I'm not able to reproduce the described issue.

I did the following in a multisite setup where the same theme was activated for 2 sites.

In mu-plugins/index.php, I added a hook to switch the site and then switch that site's theme:

add_action( 'after_setup_theme', 'test_33835', 999 );
function test_33835() {
	switch_to_blog( 2 );
	switch_theme( 'theme-two' );
	restore_current_blog();
}

In theme-one, the theme that was activated on all sites, including the network, I added:

add_action( 'after_switch_theme', 'theme_one_after_switch_theme' );
function theme_one_after_switch_theme() {
	die( 'Theme Two' );
}

And in theme-two, the theme I was switching to:

add_action( 'after_switch_theme', 'theme_two_after_switch_theme' );
function theme_two_after_switch_theme() {
	die( 'Theme Two' );
}

I loaded foo.bar/wp-admin/network/sites.php to trigger the initial mu-plugins action and then *removed* the action from mu-plugins/index.php so that it would not trigger on the next page view.

I then loaded the front page of site 2, which now had theme-two activated and was shown "Theme-Two".

If I redo the experiment with Theme Two as a child of Theme One, and used echo instead of die, I see that both the child theme and the parent theme will fire as expected.

Are you getting different results than this? If so, can you describe steps to reproduce?

#2 @jeremyfelt
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I'm going to close this out. Please re-open with steps to reproduce if necessary.

Note: See TracTickets for help on using tickets.