From d83f786d3c6ca2fe7f5d72241d3ff9b697e1a200 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 5 Mar 2018 22:13:36 +0000 Subject: [PATCH] Themes: Ensure the theme roots cache is cleared when registering a theme directory. Props soulseekah, johnbillion Fixes #43228 git-svn-id: https://develop.svn.wordpress.org/trunk@42788 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/theme.php | 2 ++ tests/phpunit/tests/theme/themeDir.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index ecbedec482..662df894b3 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -413,6 +413,8 @@ function register_theme_directory( $directory ) { $wp_theme_directories[] = $untrailed; } + wp_clean_themes_cache(); + return true; } diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index 2cab375b1a..4e915aeb40 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -293,4 +293,24 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { rmdir( WP_CONTENT_DIR . '/themes/foo' ); rmdir( WP_CONTENT_DIR . '/themes/foo-themes' ); } + + /** + * @ticket 43228 + */ + function test_theme_dir_caches() { + @mkdir( WP_CONTENT_DIR . '/themes/foo' ); + @mkdir( WP_CONTENT_DIR . '/themes/foo/bar' ); + + $old_roots = get_theme_roots(); + + register_theme_directory( WP_CONTENT_DIR . '/themes/foo' ); + + $new_roots = get_theme_roots(); + + rmdir( WP_CONTENT_DIR . '/themes/foo/bar' ); + rmdir( WP_CONTENT_DIR . '/themes/foo' ); + + $this->assertNotEquals( $new_roots, $old_roots ); + $this->assertArrayHasKey( 'foo', $new_roots ); + } }