Make WordPress Core

09/20/2023 05:25:26 PM (8 months ago)

Themes: Deprecate usage of TEMPLATEPATH and STYLESHEETPATH constants.

While generally the functions get_template_directory() and get_stylesheet_directory() were long recommended to use to get the parent or child theme directory, the TEMPLATEPATH and STYLESHEETPATH constants were still used in a few places in core, most importantly in template related logic.

The remaining usage was problematic as it prevented testability of certain key components of WordPress core.

This changeset replaces all remaining usage with the corresponding functions and effectively marks these constants as deprecated. It also adds test coverage accordingly and even unlocks some existing, previously commented out test coverage to work as expected.

Performance of the new approach has been benchmarked and shows no notable differences. Yet, given that the current theme directories are not expected to change within a regular WordPress page load, the get_template_directory() and get_stylesheet_directory() functions were amended with in-memory caching of the result, unless one of the defining values is being filtered.

Props thekt12, spacedmonkey, mukesh27, aaroncampbell, scribu, lloydbudd, cais, chipbennett, toscho, omarabid, CrazyJaco, DrewAPicture, obenland, wonderboymusic, nacin, helen, dd32, chriscct7, SergeyBiryukov, swissspidy, joemcgill, flixos90.
Fixes #18298.

1 edited


  • trunk/src/wp-includes/comment-template.php

    r56549 r56635  
    13821382 *
    13831383 * The `$file` path is passed through a filter hook called {@see 'comments_template'},
    1384  * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
     1384 * which includes the template directory and $file combined. Tries the $filtered path
    13851385 * first and if it fails it will require the default comment template from the
    13861386 * default theme. If either does not exist, then the WordPress process will be
    16011601    }
    1603     $theme_template = STYLESHEETPATH . $file;
     1603    $stylesheet_path = get_stylesheet_directory();
     1604    $template_path   = get_template_directory();
     1606    $theme_template = $stylesheet_path . $file;
    16051608    /**
    16141617    if ( file_exists( $include ) ) {
    16151618        require $include;
    1616     } elseif ( file_exists( TEMPLATEPATH . $file ) ) {
    1617         require TEMPLATEPATH . $file;
     1619    } elseif ( file_exists( $template_path . $file ) ) {
     1620        require $template_path . $file;
    16181621    } else { // Backward compat code will be removed in a future release.
    16191622        require ABSPATH . WPINC . '/theme-compat/comments.php';
Note: See TracChangeset for help on using the changeset viewer.