Skip to:
Content

bbPress.org

Ticket #3048: 3048.01.patch

File 3048.01.patch, 3.1 KB (added by r-a-y, 8 years ago)
  • src/includes/core/template-functions.php

     
    158158
    159159        // Enqueue if located
    160160        if ( ! empty( $located ) ) {
     161                // Calculate canonical plugins directory.
     162                // Why doesn't WP have a plugins_dir() function?
     163                $plugins_dir = realpath( bbpress()->plugin_dir . '../' );
    161164
    162                 $content_dir = constant( 'WP_CONTENT_DIR' );
    163 
    164                 // IIS (Windows) here
    165                 // Replace back slashes with forward slash
    166                 if ( strpos( $located, '\\' ) !== false ) {
    167                         $located     = str_replace( '\\', '/', $located     );
    168                         $content_dir = str_replace( '\\', '/', $content_dir );
     165                // Hello bbPress developer!
     166                if ( false !== strpos( wp_normalize_path( bbpress()->file ), '/src/' ) || false !== strpos( wp_normalize_path( bbpress()->file ), '/build/' ) ) {
     167                        $plugins_dir = realpath( $plugins_dir . '/../' );
    169168                }
    170169
     170                // Be nice to Windows devs.
     171                $located        = wp_normalize_path( $located );
     172                $plugins_dir    = wp_normalize_path( $plugins_dir );
     173                $stylesheet_dir = wp_normalize_path( get_stylesheet_directory() );
     174                $template_dir   = wp_normalize_path( get_template_directory() );
     175
    171176                // Make path to file relative to site URL
    172                 $located = str_replace( $content_dir, content_url(), $located );
     177                $located = str_replace( $plugins_dir,    plugin_dir_url( '' ), $located );
     178                $located = str_replace( $stylesheet_dir, get_stylesheet_directory_uri(), $located );
     179                $located = str_replace( $template_dir,   get_template_directory_uri(), $located );
    173180
    174181                // Enqueue the style
    175182                wp_enqueue_style( $handle, $located, $deps, $ver, $media );
     
    226233
    227234        // Enqueue if located
    228235        if ( ! empty( $located ) ) {
     236                // Calculate canonical plugins directory.
     237                // Why doesn't WP have a plugins_dir() function?
     238                $plugins_dir = realpath( bbpress()->plugin_dir . '../' );
    229239
    230                 $content_dir = constant( 'WP_CONTENT_DIR' );
    231 
    232                 // IIS (Windows) here
    233                 // Replace back slashes with forward slash
    234                 if ( strpos( $located, '\\' ) !== false ) {
    235                         $located     = str_replace( '\\', '/', $located     );
    236                         $content_dir = str_replace( '\\', '/', $content_dir );
     240                // Hello bbPress developer!
     241                if ( false !== strpos( wp_normalize_path( bbpress()->file ), '/src/' ) || false !== strpos( wp_normalize_path( bbpress()->file ), '/build/' ) ) {
     242                        $plugins_dir = realpath( $plugins_dir . '/../' );
    237243                }
    238244
     245                // Be nice to Windows devs.
     246                $located        = wp_normalize_path( $located );
     247                $plugins_dir    = wp_normalize_path( $plugins_dir );
     248                $stylesheet_dir = wp_normalize_path( get_stylesheet_directory() );
     249                $template_dir   = wp_normalize_path( get_template_directory() );
     250
    239251                // Make path to file relative to site URL
    240                 $located = str_replace( $content_dir, content_url(), $located );
     252                $located = str_replace( $plugins_dir,    plugin_dir_url( '' ), $located );
     253                $located = str_replace( $stylesheet_dir, get_stylesheet_directory_uri(), $located );
     254                $located = str_replace( $template_dir,   get_template_directory_uri(), $located );
    241255
    242256                // Enqueue the style
    243257                wp_enqueue_script( $handle, $located, $deps, $ver, $in_footer );