Make WordPress Core


Ignore:
Timestamp:
02/21/2024 07:24:12 PM (10 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-includes/comment-template.php

    r57648 r57685  
    13911391 * @since 1.5.0
    13921392 *
    1393  * @global WP_Query   $wp_query         WordPress Query object.
    1394  * @global WP_Post    $post             Global post object.
    1395  * @global wpdb       $wpdb             WordPress database abstraction object.
     1393 * @global WP_Query   $wp_query           WordPress Query object.
     1394 * @global WP_Post    $post               Global post object.
     1395 * @global wpdb       $wpdb               WordPress database abstraction object.
    13961396 * @global int        $id
    1397  * @global WP_Comment $comment          Global comment object.
     1397 * @global WP_Comment $comment            Global comment object.
    13981398 * @global string     $user_login
    13991399 * @global string     $user_identity
    14001400 * @global bool       $overridden_cpage
    14011401 * @global bool       $withcomments
     1402 * @global string     $wp_stylesheet_path Path to current theme's stylesheet directory.
     1403 * @global string     $wp_template_path   Path to current theme's template directory.
    14021404 *
    14031405 * @param string $file              Optional. The file to load. Default '/comments.php'.
     
    14061408 */
    14071409function comments_template( $file = '/comments.php', $separate_comments = false ) {
    1408     global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
     1410    global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage, $wp_stylesheet_path, $wp_template_path;
    14091411
    14101412    if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
     
    16011603    }
    16021604
    1603     $stylesheet_path = get_stylesheet_directory();
    1604     $template_path   = get_template_directory();
    1605 
    1606     $theme_template = $stylesheet_path . $file;
     1605    $theme_template = trailingslashit( $wp_stylesheet_path ) . $file;
    16071606
    16081607    /**
     
    16171616    if ( file_exists( $include ) ) {
    16181617        require $include;
    1619     } elseif ( file_exists( $template_path . $file ) ) {
    1620         require $template_path . $file;
     1618    } elseif ( file_exists( trailingslashit( $wp_template_path ) . $file ) ) {
     1619        require trailingslashit( $wp_template_path ) . $file;
    16211620    } else { // Backward compat code will be removed in a future release.
    16221621        require ABSPATH . WPINC . '/theme-compat/comments.php';
Note: See TracChangeset for help on using the changeset viewer.