Make WordPress Core

Changeset 56986 for branches/6.4


Ignore:
Timestamp:
10/23/2023 04:02:02 PM (3 years ago)
Author:
flixos90
Message:

Multisite: Ensure that switching sites resets the current theme directory globals.

The globals introduced in [56635] to cache the current theme directories in memory were not considering switching sites in a multisite network. This changeset addresses the bug including test coverage.

Props codex-m, jeremyfelt, costdev, joemcgill.
Merges [56974] to the 6.4 branch.
Fixes #59677.
See #18298.

Location:
branches/6.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/6.4

  • branches/6.4/src/wp-includes/ms-blogs.php

    r55990 r56986  
    492492 * @global bool            $switched
    493493 * @global string          $table_prefix
     494 * @global string          $wp_template_path
     495 * @global string          $wp_stylesheet_path
    494496 * @global WP_Object_Cache $wp_object_cache
    495497 *
     
    533535
    534536        $wpdb->set_blog_id( $new_blog_id );
    535         $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    536         $GLOBALS['blog_id']      = $new_blog_id;
     537        $GLOBALS['table_prefix']       = $wpdb->get_blog_prefix();
     538        $GLOBALS['blog_id']            = $new_blog_id;
     539        $GLOBALS['wp_template_path']   = null;
     540        $GLOBALS['wp_stylesheet_path'] = null;
    537541
    538542        if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
     
    601605 * @global bool            $switched
    602606 * @global string          $table_prefix
     607 * @global string          $wp_template_path
     608 * @global string          $wp_stylesheet_path
    603609 * @global WP_Object_Cache $wp_object_cache
    604610 *
     
    626632
    627633        $wpdb->set_blog_id( $new_blog_id );
    628         $GLOBALS['blog_id']      = $new_blog_id;
    629         $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
     634        $GLOBALS['blog_id']            = $new_blog_id;
     635        $GLOBALS['table_prefix']       = $wpdb->get_blog_prefix();
     636        $GLOBALS['wp_template_path']   = null;
     637        $GLOBALS['wp_stylesheet_path'] = null;
    630638
    631639        if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
  • branches/6.4/tests/phpunit/tests/theme.php

    r56727 r56986  
    10601060
    10611061        /**
     1062         * Tests whether a switched site retrieves the correct stylesheet directory.
     1063         *
     1064         * @ticket 59677
     1065         * @group ms-required
     1066         *
     1067         * @covers ::get_stylesheet_directory
     1068         */
     1069        public function test_get_stylesheet_directory_with_switched_site() {
     1070                $blog_id = self::factory()->blog->create();
     1071
     1072                update_blog_option( $blog_id, 'stylesheet', 'switched_stylesheet' );
     1073
     1074                // Prime global storage with the current site's data.
     1075                get_stylesheet_directory();
     1076
     1077                switch_to_blog( $blog_id );
     1078                $switched_stylesheet = get_stylesheet_directory();
     1079                restore_current_blog();
     1080
     1081                $this->assertSame( WP_CONTENT_DIR . '/themes/switched_stylesheet', $switched_stylesheet );
     1082        }
     1083
     1084        /**
     1085         * Tests whether a switched site retrieves the correct template directory.
     1086         *
     1087         * @ticket 59677
     1088         * @group ms-required
     1089         *
     1090         * @covers ::get_template_directory
     1091         */
     1092        public function test_get_template_directory_with_switched_site() {
     1093                $blog_id = self::factory()->blog->create();
     1094
     1095                update_blog_option( $blog_id, 'template', 'switched_template' );
     1096
     1097                // Prime global storage with the current site's data.
     1098                get_template_directory();
     1099
     1100                switch_to_blog( $blog_id );
     1101                $switched_template = get_template_directory();
     1102                restore_current_blog();
     1103
     1104                $this->assertSame( WP_CONTENT_DIR . '/themes/switched_template', $switched_template );
     1105        }
     1106
     1107        /**
     1108         * Tests whether a restored site retrieves the correct stylesheet directory.
     1109         *
     1110         * @ticket 59677
     1111         * @group ms-required
     1112         *
     1113         * @covers ::get_stylesheet_directory
     1114         */
     1115        public function test_get_stylesheet_directory_with_restored_site() {
     1116                $blog_id = self::factory()->blog->create();
     1117
     1118                update_option( 'stylesheet', 'original_stylesheet' );
     1119                update_blog_option( $blog_id, 'stylesheet', 'switched_stylesheet' );
     1120
     1121                $stylesheet = get_stylesheet_directory();
     1122
     1123                switch_to_blog( $blog_id );
     1124
     1125                // Prime global storage with the restored site's data.
     1126                get_stylesheet_directory();
     1127                restore_current_blog();
     1128
     1129                $this->assertSame( WP_CONTENT_DIR . '/themes/original_stylesheet', $stylesheet );
     1130        }
     1131
     1132        /**
     1133         * Tests whether a restored site retrieves the correct template directory.
     1134         *
     1135         * @ticket 59677
     1136         * @group ms-required
     1137         *
     1138         * @covers ::get_template_directory
     1139         */
     1140        public function test_get_template_directory_with_restored_site() {
     1141                $blog_id = self::factory()->blog->create();
     1142
     1143                update_option( 'template', 'original_template' );
     1144                update_blog_option( $blog_id, 'template', 'switched_template' );
     1145
     1146                $template = get_template_directory();
     1147
     1148                switch_to_blog( $blog_id );
     1149
     1150                // Prime global storage with the switched site's data.
     1151                get_template_directory();
     1152                restore_current_blog();
     1153
     1154                $this->assertSame( WP_CONTENT_DIR . '/themes/original_template', $template );
     1155        }
     1156
     1157        /**
    10621158         * Helper function to ensure that a block theme is available and active.
    10631159         */
Note: See TracChangeset for help on using the changeset viewer.