summaryrefslogtreecommitdiffstats
path: root/wp-includes/template.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--wp-includes/template.php38
1 files changed, 29 insertions, 9 deletions
diff --git a/wp-includes/template.php b/wp-includes/template.php
index 989d630..401df4d 100644
--- a/wp-includes/template.php
+++ b/wp-includes/template.php
@@ -654,8 +654,6 @@ function get_singular_template() {
*
* @see get_query_template()
*
- * @global array $posts
- *
* @return string Full path to attachment template file.
*/
function get_attachment_template() {
@@ -682,6 +680,21 @@ function get_attachment_template() {
}
/**
+ * Set up the globals used for template loading.
+ *
+ * @since 6.5.0
+ *
+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
+ */
+function wp_set_template_globals() {
+ global $wp_stylesheet_path, $wp_template_path;
+
+ $wp_stylesheet_path = get_stylesheet_directory();
+ $wp_template_path = get_template_directory();
+}
+
+/**
* Retrieves the name of the highest priority template file that exists.
*
* Searches in the stylesheet directory before the template directory and
@@ -691,6 +704,9 @@ function get_attachment_template() {
* @since 2.7.0
* @since 5.5.0 The `$args` parameter was added.
*
+ * @global string $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string $wp_template_path Path to current theme's template directory.
+ *
* @param string|array $template_names Template file(s) to search for, in order.
* @param bool $load If true the template file will be loaded if it is found.
* @param bool $load_once Whether to require_once or require. Has no effect if `$load` is false.
@@ -700,20 +716,24 @@ function get_attachment_template() {
* @return string The template filename if one is located.
*/
function locate_template( $template_names, $load = false, $load_once = true, $args = array() ) {
- $stylesheet_path = get_stylesheet_directory();
- $template_path = get_template_directory();
- $is_child_theme = $stylesheet_path !== $template_path;
+ global $wp_stylesheet_path, $wp_template_path;
+
+ if ( ! isset( $wp_stylesheet_path ) || ! isset( $wp_template_path ) ) {
+ wp_set_template_globals();
+ }
+
+ $is_child_theme = is_child_theme();
$located = '';
foreach ( (array) $template_names as $template_name ) {
if ( ! $template_name ) {
continue;
}
- if ( file_exists( $stylesheet_path . '/' . $template_name ) ) {
- $located = $stylesheet_path . '/' . $template_name;
+ if ( file_exists( $wp_stylesheet_path . '/' . $template_name ) ) {
+ $located = $wp_stylesheet_path . '/' . $template_name;
break;
- } elseif ( $is_child_theme && file_exists( $template_path . '/' . $template_name ) ) {
- $located = $template_path . '/' . $template_name;
+ } elseif ( $is_child_theme && file_exists( $wp_template_path . '/' . $template_name ) ) {
+ $located = $wp_template_path . '/' . $template_name;
break;
} elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
$located = ABSPATH . WPINC . '/theme-compat/' . $template_name;