[wp-trac] [WordPress Trac] #33835: action switch_theme, after_switch_theme should not be trigged when switch_theme for child site.

WordPress Trac noreply at wordpress.org
Mon Sep 14 20:11:46 UTC 2015


#33835: action switch_theme, after_switch_theme should not be trigged when
switch_theme for child site.
--------------------------------+------------------------------
 Reporter:  nguyenvanduocit     |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Networks and Sites  |     Version:  4.3
 Severity:  normal              |  Resolution:
 Keywords:  reporter-feedback   |     Focuses:  multisite
--------------------------------+------------------------------
Changes (by jeremyfelt):

 * keywords:   => reporter-feedback


Comment:

 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?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33835#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list