From 021b07a1619729ab62feef55f562a6361b0e64ea Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 19 Jul 2014 23:07:15 +0000 Subject: [PATCH] Call `untrailingslashit()` when adding a theme directory in `register_theme_directory()`. This prevents double-slashing in generated URLs. Don't add a directory if it is already present. Adds unit tests. Props obenland, wonderboymusic. Fixes #28662. Built from https://develop.svn.wordpress.org/trunk@29249 git-svn-id: http://core.svn.wordpress.org/trunk@29033 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/theme.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index f21075a116..0562c832aa 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -370,11 +370,19 @@ function register_theme_directory( $directory ) { // Try prepending as the theme directory could be relative to the content directory $directory = WP_CONTENT_DIR . '/' . $directory; // If this directory does not exist, return and do not register - if ( ! file_exists( $directory ) ) + if ( ! file_exists( $directory ) ) { return false; + } } - $wp_theme_directories[] = $directory; + if ( ! is_array( $wp_theme_directories ) ) { + $wp_theme_directories = array(); + } + + $untrailed = untrailingslashit( $directory ); + if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories ) ) { + $wp_theme_directories[] = $untrailed; + } return true; }