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/default-constants.php

    r56548 r56635  
    408408     *
    409409     * @since 1.5.0
     410     * @deprecated 6.4.0 Use get_template_directory() instead.
     411     * @see get_template_directory()
    410412     */
    411413    define( 'TEMPLATEPATH', get_template_directory() );
    415417     *
    416418     * @since 2.1.0
     419     * @deprecated 6.4.0 Use get_stylesheet_directory() instead.
     420     * @see get_stylesheet_directory()
    417421     */
    418422    define( 'STYLESHEETPATH', get_stylesheet_directory() );
Note: See TracChangeset for help on using the changeset viewer.