WordPress.org

Make WordPress Core

Ticket #30797: 30797.diff

File 30797.diff, 2.3 KB (added by DrewAPicture, 4 years ago)

Alternate approach

  • src/wp-includes/theme.php

     
    209209}
    210210
    211211/**
    212  * Retrieve URI of current theme stylesheet.
     212 * Retrieves the URI of the current theme stylesheet.
    213213 *
    214  * The stylesheet file name is 'style.css' which is appended to {@link
    215  * get_stylesheet_directory_uri() stylesheet directory URI} path.
     214 * If `$type` is 'child' (default), 'style.css' is appended to the get_stylesheet_directory_uri()
     215 * path. If 'parent', it is appended to get_template_directory_uri(). If the parent theme doesn't
     216 * exist, it falls back to the current theme (the same as if the default 'child' value were chosen).
    216217 *
    217218 * @since 1.5.0
     219 * @since 4.4.0 Introduced the optional `$type` parameter.
    218220 *
    219  * @return string
     221 * @param string $type Optional. Type of stylesheet to retrieve. Accepts 'child' or 'parent'.
     222 *                     Default 'child'.
     223 * @return string If `$type` is 'parent' and a parent theme exists, the parent theme stylesheet URI.
     224 *                In all other cases, the current theme stylesheet URI will be returned.
    220225 */
    221 function get_stylesheet_uri() {
     226function get_stylesheet_uri( $type = 'child' ) {
    222227        $stylesheet_dir_uri = get_stylesheet_directory_uri();
     228
     229        // Normalize on two choices for the benefit of the 'stylesheet_uri' filter.
     230        if ( ! in_array( $type, array( 'child', 'parent' ) ) ) {
     231                $type = 'child';
     232        }
     233
     234        if ( 'parent' === $type ) {
     235                $stylesheet_dir_uri = get_template_directory_uri();
     236        }
     237
    223238        $stylesheet_uri = $stylesheet_dir_uri . '/style.css';
     239
    224240        /**
    225241         * Filter the URI of the current theme stylesheet.
    226242         *
    227243         * @since 1.5.0
     244         * @since 4.4.0 Added the `$type` parameter.
    228245         *
    229246         * @param string $stylesheet_uri     Stylesheet URI for the current theme/child theme.
    230247         * @param string $stylesheet_dir_uri Stylesheet directory URI for the current theme/child theme.
     248         * @param string $type               Type of stylesheet URI being retrieved. Can be either 'child'
     249         *                                   or 'parent'. Default 'child'.
    231250         */
    232         return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri );
     251        return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri, $type );
    233252}
    234253
    235254/**