[wp-trac] [WordPress Trac] #40221: switch_theme action + Live Preview = confusion

WordPress Trac noreply at wordpress.org
Wed Mar 13 04:04:10 UTC 2019


#40221: switch_theme action + Live Preview = confusion
--------------------------+------------------------------
 Reporter:  alexvorn2     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Themes        |     Version:  4.7.3
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+------------------------------
Changes (by joyously):

 * keywords:   => needs-patch


Comment:

 The `switch_theme` action is for when the theme is switched, and is
 supposed to run in the context of the old theme. It is passed the new and
 the old theme object.
 Searching for it in the WP 5.1 code, I found these:
 wp-includes\class-wp-customize-manager.php(2840): `switch_theme(
 $this->get_stylesheet() );`
 wp-includes\class-wp-customize-manager.php(3463): `if ( did_action(
 'switch_theme' ) ) {`
 wp-includes\theme.php(713): `function switch_theme( $stylesheet ) {`
 wp-includes\theme.php(792): `do_action( 'switch_theme', $new_name,
 $new_theme, $old_theme );`
 wp-includes\theme.php(835): `switch_theme( WP_DEFAULT_THEME );`
 wp-includes\theme.php(853): `switch_theme( $default->get_stylesheet() );`
 wp-admin\themes.php(33): `switch_theme( $theme->get_stylesheet() );`
 wp-admin\includes\class-theme-upgrader.php(577): `switch_theme(
 $stylesheet );`

 The code appears as if it is always called in the context of the old
 theme, but in the case of Live Preview it is the theme being previewed
 (new theme) and not the theme on the front end (old theme), since that is
 what is already loaded for the preview. The action's parameters are
 correct for the old and new Theme objects, however.

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


More information about the wp-trac mailing list