From ead3f2f435fe05eb96124b970ed64df55259140c Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 8 Mar 2012 18:18:10 +0000 Subject: [PATCH] Pass WP_Theme->get_theme_root_uri() to get_theme_root_uri(), thereby always triggering the theme_root_uri filter. see #20103. git-svn-id: http://svn.automattic.com/wordpress/trunk@20162 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme.php | 21 ++++++++++++++++----- wp-includes/theme.php | 12 +++++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index a72421037..606975c85 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -112,6 +112,14 @@ final class WP_Theme implements ArrayAccess { */ private $parent; + /** + * URL to the theme root, usually an absolute URL to wp-content/themes + * + * @access private + * var string + */ + private $theme_root_uri; + /** * Flag for whether the theme's textdomain is loaded. * @@ -789,7 +797,11 @@ final class WP_Theme implements ArrayAccess { /** * Returns the URL to the directory of the theme root. * - * This is typically the absolute path to wp-content/themes. + * This is typically the absolute URL to wp-content/themes. This forms the basis + * for all other URLs returned by WP_Theme, so we pass it to the public function + * get_theme_root_uri() and allow it to run the theme_root_uri filter. + * + * @uses get_theme_root_uri() * * @since 3.4.0 * @access public @@ -797,10 +809,9 @@ final class WP_Theme implements ArrayAccess { * @return string Theme root URI. */ public function get_theme_root_uri() { - if ( 0 === strpos( WP_CONTENT_DIR, $this->theme_root ) ) - return str_replace( WP_CONTENT_DIR, content_url(), $this->theme_root ); - // Give up, send it off to the filter. - return get_theme_root_uri( $this->stylesheet ); + if ( ! isset( $this->theme_root_uri ) ) + $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); + return $this->theme_root_uri; } /** diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 35374747a..8044101e8 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -525,13 +525,19 @@ function get_theme_root( $stylesheet_or_template = false ) { * * @since 1.5.0 * - * @param string $stylesheet_or_template The stylesheet or template name of the theme + * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme. + * Default is to leverage the main theme root. + * @param string $theme_root Optional. The theme root for which calculations will be based, preventing + * the need for a get_raw_theme_root() call. * @return string Themes URI. */ -function get_theme_root_uri( $stylesheet_or_template = false ) { +function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) { global $wp_theme_directories; - if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) { + if ( $stylesheet_or_template && ! $theme_root ) + $theme_root = get_raw_theme_root( $stylesheet_or_template ); + + if ( $stylesheet_or_template && $theme_root ) { if ( in_array( $theme_root, (array) $wp_theme_directories ) ) { // Absolute path. Make an educated guess. YMMV -- but note the filter below. if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) )