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
This commit is contained in:
nacin 2012-03-08 18:18:10 +00:00
parent c5d5d2f13f
commit ead3f2f435
2 changed files with 25 additions and 8 deletions

View File

@ -112,6 +112,14 @@ final class WP_Theme implements ArrayAccess {
*/ */
private $parent; 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. * 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. * 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 * @since 3.4.0
* @access public * @access public
@ -797,10 +809,9 @@ final class WP_Theme implements ArrayAccess {
* @return string Theme root URI. * @return string Theme root URI.
*/ */
public function get_theme_root_uri() { public function get_theme_root_uri() {
if ( 0 === strpos( WP_CONTENT_DIR, $this->theme_root ) ) if ( ! isset( $this->theme_root_uri ) )
return str_replace( WP_CONTENT_DIR, content_url(), $this->theme_root ); $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root );
// Give up, send it off to the filter. return $this->theme_root_uri;
return get_theme_root_uri( $this->stylesheet );
} }
/** /**

View File

@ -525,13 +525,19 @@ function get_theme_root( $stylesheet_or_template = false ) {
* *
* @since 1.5.0 * @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. * @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; 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 ) ) { if ( in_array( $theme_root, (array) $wp_theme_directories ) ) {
// Absolute path. Make an educated guess. YMMV -- but note the filter below. // Absolute path. Make an educated guess. YMMV -- but note the filter below.
if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) )