From 8fe92ac1371faed0e963b5c258c9cdf1d0455682 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 7 Jun 2023 20:08:00 +0000 Subject: [PATCH] Load: Avoid loading a theme's `functions.php` when `! wp_using_themes()`. Updates `wp_get_active_and_valid_themes()` to return early when `wp_using_themes()` returns `false`. This prevents a theme's `functions.php` from being loaded erroneously when the site isn't using themes. Also adds `define( 'WP_USE_THEMES', true );` to the test suite bootstrap. Some tests randomly break without it because they were dependent on the previous buggy behavior. Props bpayton, costdev, danielbachhuber, hellofromtonya, sergeybiryukov, spacedmonkey. Fixes #57928. git-svn-id: https://develop.svn.wordpress.org/trunk@55890 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/load.php | 4 +++ tests/phpunit/includes/bootstrap.php | 1 + .../tests/load/wpGetActiveAndValidThemes.php | 30 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tests/phpunit/tests/load/wpGetActiveAndValidThemes.php diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 02bf0299bf..9780519856 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -948,6 +948,10 @@ function wp_get_active_and_valid_themes() { return $themes; } + if ( ! wp_using_themes() ) { + return $themes; + } + if ( TEMPLATEPATH !== STYLESHEETPATH ) { $themes[] = STYLESHEETPATH; } diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 1113a87eea..7e183c995d 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -252,6 +252,7 @@ $phpmailer = new MockPHPMailer( true ); if ( ! defined( 'WP_DEFAULT_THEME' ) ) { define( 'WP_DEFAULT_THEME', 'default' ); } +define( 'WP_USE_THEMES', true ); $wp_theme_directories = array(); if ( file_exists( DIR_TESTDATA . '/themedir1' ) ) { diff --git a/tests/phpunit/tests/load/wpGetActiveAndValidThemes.php b/tests/phpunit/tests/load/wpGetActiveAndValidThemes.php new file mode 100644 index 0000000000..f6519486f8 --- /dev/null +++ b/tests/phpunit/tests/load/wpGetActiveAndValidThemes.php @@ -0,0 +1,30 @@ +assertEquals( + array( + TEMPLATEPATH, + ), + wp_get_active_and_valid_themes() + ); + + // Disabling 'wp_using_themes' should return an empty array. + add_filter( 'wp_using_themes', '__return_false' ); + $this->assertEquals( + array(), + wp_get_active_and_valid_themes() + ); + } +}