WordPress.org

Make WordPress Core

Ticket #20103: 20103.4.diff

File 20103.4.diff, 2.9 KB (added by nacin, 6 years ago)
  • wp-includes/class-wp-theme.php

     
    113113        private $parent;
    114114
    115115        /**
     116         * URL to the theme root, usually an absolute URL to wp-content/themes
     117         *
     118         * @access private
     119         * var string
     120         */
     121        private $theme_root_uri;
     122
     123        /**
    116124         * Flag for whether the theme's textdomain is loaded.
    117125         *
    118126         * @access private
     
    789797        /**
    790798         * Returns the URL to the directory of the theme root.
    791799         *
    792          * This is typically the absolute path to wp-content/themes.
     800         * This is typically the absolute URL to wp-content/themes. This forms the basis
     801         * for all other URLs returned by WP_Theme, so we pass it to the public function
     802         * get_theme_root_uri() and allow it to run the theme_root_uri filter.
    793803         *
     804         * @uses get_theme_root_uri()
     805         *
    794806         * @since 3.4.0
    795807         * @access public
    796808         *
    797809         * @return string Theme root URI.
    798810         */
    799811        public function get_theme_root_uri() {
    800                 if ( 0 === strpos( WP_CONTENT_DIR, $this->theme_root ) )
    801                         return str_replace( WP_CONTENT_DIR, content_url(), $this->theme_root );
    802                 // Give up, send it off to the filter.
    803                 return get_theme_root_uri( $this->stylesheet );
     812                if ( ! isset( $this->theme_root_uri ) )
     813                        $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root );
     814                return $this->theme_root_uri;
    804815        }
    805816
    806817        /**
  • wp-includes/theme.php

     
    525525 *
    526526 * @since 1.5.0
    527527 *
    528  * @param string $stylesheet_or_template The stylesheet or template name of the theme
     528 * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
     529 *      Default is to leverage the main theme root.
     530 * @param string $theme_root Optional. The theme root for which calculations can be based, preventing
     531 *      the need for a get_raw_theme_root() call.
    529532 * @return string Themes URI.
    530533 */
    531 function get_theme_root_uri( $stylesheet_or_template = false ) {
     534function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) {
    532535        global $wp_theme_directories;
    533536
    534         if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) {
     537        if ( count( $wp_theme_directories ) <= 1 )
     538                return apply_filters( 'theme_root_uri', content_url( 'themes' ), get_option('siteurl'), $stylesheet_or_template );
     539
     540        if ( $stylesheet_or_template && ! $theme_root )
     541                $theme_root = get_raw_theme_root( $stylesheet_or_template );
     542
     543        if ( $stylesheet_or_template && $theme_root ) {
    535544                if ( in_array( $theme_root, (array) $wp_theme_directories ) ) {
    536545                        // Absolute path. Make an educated guess. YMMV -- but note the filter below.
    537546                        if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) )