From 903b9af181b8f557a2575a9b03b05b325335bffb Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Sun, 30 Aug 2015 21:44:38 +0000 Subject: [PATCH] Themes: Get the correct theme when template and stylesheet were both passed as arguments. Fixes a bug where `$new_theme` got set before the second argument was appropriately handled, causing the `current_theme` option to later always be updated to the parent theme's name. Introduced in [21131]. Props obenland, wonderboymusic. Fixes #32635. git-svn-id: https://develop.svn.wordpress.org/trunk@33815 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/theme.php | 10 ++++------ tests/phpunit/tests/theme.php | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index a9f0e6ed8d..07b0f6a208 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -690,16 +690,14 @@ function switch_theme( $stylesheet ) { $nav_menu_locations = get_theme_mod( 'nav_menu_locations' ); - $old_theme = wp_get_theme(); - $new_theme = wp_get_theme( $stylesheet ); - if ( func_num_args() > 1 ) { - $template = $stylesheet; $stylesheet = func_get_arg( 1 ); - } else { - $template = $new_theme->get_template(); } + $old_theme = wp_get_theme(); + $new_theme = wp_get_theme( $stylesheet ); + $template = $new_theme->get_template(); + update_option( 'template', $template ); update_option( 'stylesheet', $stylesheet ); diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index 972c964fa6..3c9b649ef8 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -85,6 +85,11 @@ class Tests_Theme extends WP_UnitTestCase { $themes = get_themes(); // Generic tests that should hold true for any theme foreach ( $themes as $k => $theme ) { + // Don't run these checks for custom themes. + if ( empty( $theme['Author'] ) || false === strpos( $theme['Author'], 'WordPress' ) ) { + continue; + } + $this->assertEquals( $theme['Name'], $k ); $this->assertNotEmpty( $theme['Title'] );