Make WordPress Core


Ignore:
Timestamp:
02/21/2024 07:24:12 PM (3 months ago)
Author:
joemcgill
Message:

Themes: Use original template paths when switching blogs.

This fixes a bug introduced by [57129] and [56635] in which deprecating the previous TEMPLATEPATH and STYLESHEETPATH constants in favor of get_template_directory() and get_stylesheet_directory() functions caused the active theme template path to change when using switch_to_blog().

This introduces a new function, wp_set_template_globals(), which is called during the bootstrap process to store the template paths to new globals values $wp_template_path and $wp_stylesheet_path. This restores behavior to how things worked prior to [56635] but retains the ability for template values to be reset for better testability.

Related #18298, #60025.

Props joemcgill, flixos90, mukesh27, swissspidy, manfcarlo, metropolis_john, jeremyfelt.
Fixes #60290.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r57644 r57685  
    11611161 * @since 5.2.0
    11621162 *
     1163 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
     1164 * @global string $wp_template_path   Path to current theme's template directory.
     1165 *
    11631166 * @param string $theme    Single theme to resume.
    11641167 * @param string $redirect Optional. URL to redirect to. Default empty string.
     
    11671170 */
    11681171function resume_theme( $theme, $redirect = '' ) {
     1172    global $wp_stylesheet_path, $wp_template_path;
     1173
    11691174    list( $extension ) = explode( '/', $theme );
    11701175
     
    11741179     */
    11751180    if ( ! empty( $redirect ) ) {
    1176         $stylesheet_path = get_stylesheet_directory();
    1177         $template_path   = get_template_directory();
    1178 
    11791181        $functions_path = '';
    1180         if ( str_contains( $stylesheet_path, $extension ) ) {
    1181             $functions_path = $stylesheet_path . '/functions.php';
    1182         } elseif ( str_contains( $template_path, $extension ) ) {
    1183             $functions_path = $template_path . '/functions.php';
     1182        if ( str_contains( $wp_stylesheet_path, $extension ) ) {
     1183            $functions_path = $wp_stylesheet_path . '/functions.php';
     1184        } elseif ( str_contains( $wp_template_path, $extension ) ) {
     1185            $functions_path = $wp_template_path . '/functions.php';
    11841186        }
    11851187
Note: See TracChangeset for help on using the changeset viewer.