roots / sage

WordPress starter theme with Laravel Blade components and templates, Tailwind CSS, and a modern development workflow
https://roots.io/sage/
MIT License
12.76k stars 3.06k forks source link

Rewrite killing other plugins #293

Closed zslabs closed 12 years ago

zslabs commented 12 years ago

Hi, The new re-write for script URLs for example seems to be killing some plugins - for example, the output looks like:

<script src="/base//base/wp-content/plugins/jquery-colorbox/js/jquery.colorbox-min.js"></script>

Also - why wouldn't this be hooking into the proper re-write to not only be relative, but also use the /plugins URL as it did in other versions? /base is the root of the site -- in a sub-directory and /base is also the name of the theme folder

Also, when adding in new scripts the standard WP way, this doesn't work properly:

function roots_custom_scripts() {
  wp_register_script('roots_script_less', THEME_PATH . '/js/less.min.js', false, null, false);
  wp_enqueue_script('roots_script_less');
}

add_action('wp_print_scripts', 'roots_custom_scripts');

It spits out <script type='text/javascript' src='/basewp-content/themes/base/js/less.min.js'></script> which is missing a / and also is not rewritten. If we are trying to take the approach of not touching the core roots files, then what's the best way to add JS files? Maybe a quick WIKI addition would help, but something seems a bit off with the plugin rewrite for JS files in general unless I'm missing something. Thanks.

retlehs commented 12 years ago

ew, this is a bug. (pinging @swalkinshaw)

CodeDecent commented 12 years ago

A horrible bug!

WP HEAD:

/plugins/ubermenu/styles/basic.css /plugins/ubermenu/styles/skins/blackwhite2.css?ver=2.0.1.0 //wp-content/plugins/ubermenu/js/hoverIntent.js <--- 404 /http://maps.googleapis.com/maps/api/js?sensor=false <--- 404 //wp-content/plugins/ubermenu/js/ubermenu.min.js" <---- 404 /js/plugins.js /js/script.js

waitxd commented 12 years ago

quick and dirty fix for absolute-url by wp_enqueue_script: at inc/roots-scripts.php 27 row

replace $src = WP_BASE . leadingslashit($wp_scripts->registered[$handle]->src); $src = apply_filters('script_loader_src', $src);

on $src = apply_filters('script_loader_src', $wp_scripts->registered[$handle]->src);

CodeDecent commented 12 years ago

Thanks!

loganlape commented 12 years ago

Quick and dirty fix from @waitxd seems to only solve half the problem for me. WP install in /new2 directory.

Before fix:

/new2//new2/wp-content/plugins/the-events-calendar/resources/events.js /new2/new2/plugins/wp-orbit-slider/js/jquery.orbit-1.3.0.min.js?ver=3.3.1

After:

/new2/plugins/the-events-calendar/resources/events.js /new2/new2/plugins/wp-orbit-slider/js/jquery.orbit-1.3.0.min.js?ver=3.3.1

Same for css files loaded by plugins .

lawrencetaur commented 12 years ago

Any fix yet?

the quick fix mentioned above doesn't work for me.

here's a screenshot: http://dl.dropbox.com/u/9124270/For%20Public/rootsbug.jpg

thats what i get when: install wordpress > install roots theme > visit the site.

stuwaddy commented 12 years ago

Is there any news on this?, can the re-write be turned off as it's pretty much impossible to work with this issue?

swalkinshaw commented 12 years ago

I'll be working on it soon. However, you can easily turn anything off by commenting out the action(s).

stuwaddy commented 12 years ago

Thanks, could you let me know which action(s) to comment out?

swalkinshaw commented 12 years ago

https://github.com/retlehs/roots/blob/master/functions.php#L17

This would skip the whole script processing stuff Roots does.

retlehs commented 12 years ago

can you see if this is still an issue after 7f9077cfebd3a479eb63f79078a3e2dbfcff5f7d?

stuwaddy commented 12 years ago

Sorry, no the issue is still there. Wordpress is in the directory /wp2 and the scripts are duplicating the wp2 folder in the path.

" script type='text/javascript' src='/wp2/wp2/plugins/events-manager/includes/js/events-manager.js?ver=3.3.1 script type='text/javascript' src='/wp2/wp2/js/plugins.js script type='text/javascript' src='/wp2/wp2/js/script.js' "

iagdotme commented 12 years ago

I think I am getting the same issue:

<script src="/wp-includes/js/admin-bar.js"></script>
<script src="//wp-content/plugins/wp-views/embedded/res/js/wpv-pagination-embedded.js"></script>
<script src="/http://maps.google.com/maps?file=api&v=2&hl=en&key=!removed!&sensor=false"></script>
<script src="//wp-content/plugins/wp-geo/js/tooltip.js"></script>
<script src="//wp-content/plugins/wp-geo/js/wp-geo.js"></script>
<script src="/js/plugins.js"></script>
<script src="/js/script.js"></script>

On another note, is there a way Roots can clean/rewrite the links to css/js files from other plugins? I hate the way plugins can just call a js file like here:

<script src="//wp-content/plugins/wp-geo/js/tooltip.js"></script>
stuwaddy commented 12 years ago

Problem appears to be with root relative URLs for everything in roots-cleanup.

It's adding either an extra "/" or, if wordpress is installed in a sub-folder, it is duplicating the folder name in the path.

Removing the roots_root_relative_url function prevents the issue.

Geroblee commented 12 years ago

I haven't tried this with any other plugins installed but to fix this issue for my local testing I took:

wp_register_script('roots_plugins', template_directory_uri() . '/js/plugins.js', false, null, false);
wp_register_script('roots_script', template_directory_uri() . '/js/script.js', false, null, false);
wp_enqueue_script('roots_plugins');
wp_enqueue_script('roots_script');

and replaced it with:

wp_register_script('roots_plugins', '/js/plugins.js', false, null, false);
wp_register_script('roots_script', '/js/script.js', false, null, false);
wp_enqueue_script('roots_plugins');
wp_enqueue_script('roots_script');

I am sure there is some issue that I am not realizing will happen by doing this but it does make the plugins.js and script.js load properly for me via localhost testing.

EDIT: I realized the problem will be that it's doing it to other plugins as well.

lawrencetaur commented 12 years ago

Seems fixed.

The 404's i used to get for the css files have been fixed. plugins.js and script.js had the duplicate directory that @stuwaddy pointed out.

the fix @Geroblee pointed out has fixed the issue.

jaapwalhout commented 12 years ago

It isn't fixed for me: http://fes.walhout.net/

Any other solutions? I tryed the fix of @Geroblee

lawrencetaur commented 12 years ago

Your issue is very similar to issue #330 which i filed yesterday. The rest seems fixed.

smth commented 12 years ago

@Geroblee fix works on my local version, but not the live one. Could it be due to being a network installation? Or that it is a sub-domain?

sdsanders commented 12 years ago

I am having the same problem. Fresh install of the latest version of Roots installed into a subfolder. It is duplicating the directory when attempting to reference plugins.js and script.js. The fix from @Geroblee works.

stuwaddy commented 12 years ago

Can anyone confirm that the @Geroblee fix works with other plugins? Removing the roots_root_relative_url function was the only fix that worked for me.

intelligence commented 12 years ago

^ Nope, it will only fix for this plugin.js and script.js

intelligence commented 12 years ago

Removing roots_root_relative_url function does not quite help either.

Gives me urls like: script type='text/javascript' src='/http://aufdeutsch.co.uk/wp-content/plugins/describe-it/js/script.js?ver=3.3.1'> Notice the prepended "/"

leepeterson commented 12 years ago

@Geroblee's fix took care of my issue. In my case, I moved from subdomain to subdirectory.

swalkinshaw commented 12 years ago

Sorry for the delay guys. I should have a proper fix in place for this tonight.

CodeDecent commented 12 years ago

Nice :D

swalkinshaw commented 12 years ago

@Geroblee had the right idea. The call to get_template_directory_uri() just wasn't needed with the rewrites. But they are needed for WPMU or child theme installs (since rewrites don't happen).

smth commented 12 years ago

Still doesn't seem to work with sub-domain.

christophgockel commented 12 years ago

I'm afraid, this doesn't fix anything for me either. It even breaks more than before.

The stylesheet elements (<link>) are handled correctyl for me, but all JavaScript entries (<script>) are broken. My WP installation is placed in a subdirectory and I'm using roots with a child-theme. My header looks like this:

With the unmodified Roots:

<script type='text/javascript' src='/wordpress/wordpress/wp-content/themes/roots/js/plugins.js'></script>
<script type='text/javascript' src='/wordpress/wordpress/wp-content/themes/roots/js/script.js'></script>
<script type='text/javascript' src='/wordpress/wordpress/wp-content/plugins/meteor-slides/js/jquery.cycle.all.min.js?ver=3.3.1'></script>
<script type='text/javascript' src='/wordpress/wordpress/wp-content/plugins/meteor-slides/js/jquery.metadata.v2.js?ver=3.3.1'></script>

With swalkinshaw's latest commit (7a471be):

<script type='text/javascript' src='/wordpress/js/plugins.js'></script>
<script type='text/javascript' src='/wordpress/js/script.js'></script>
<script type='text/javascript' src='/wordpress/wordpress/wp-content/plugins/meteor-slides/js/jquery.cycle.all.min.js?ver=3.3.1'></script>
<script type='text/javascript' src='/wordpress/wordpress/wp-content/plugins/meteor-slides/js/jquery.metadata.v2.js?ver=3.3.1'></script>

My only solution right now is to disable all the "cleanup" with removing the "roots_root_relative_url" filter.

edit: fixed the code formatting.

swalkinshaw commented 12 years ago

Thanks for the reports. It's hard to test all possible install types, but I'll look into these.

deegs commented 12 years ago

Chiming in here as well for what it's worth. commit ( 7a471be04926532ffe8d8a6687d23fff2f6c604a ) worked on a fresh install but as soon as I reinstated a few plugins it would mess up their calls to a .css or .js file.

deegs commented 12 years ago

Also can chime in and say that the fix at ( 00066ee0dd49e9f0acc0be412adcced129d7899d ) works in my situation. :)

smth commented 12 years ago

Are we still assuming this is the cause of issue #319?

NickTomlin commented 12 years ago

It's broken for me on a localhost install, 404's for everything : ( my CSS paths are : /directoryname/css/bootstrap.css mod_rewrite is enabled.

sdsanders commented 12 years ago

I can confirm that I am still having issues as well. I have a fresh install of Wordpress in both a subdomain and a subfolder. My paths for Wordpress plugin CSS and JS files are coming up as /wordpressinstall/wordpressinstall/plugins/....

The paths for everything Roots related, including CSS and JS, are working just fine.

NickTomlin commented 12 years ago

Just curious SDsanders, what local platform are you developing on? (WAMP/XAMP/MAMP/LAMP? ) I use WAMP and XAMP (when I'm on windows) and XAMP works fine but WAMP is broken.

sdsanders commented 12 years ago

I just tried it out on your standard LAMP install. It's the server that we use to show sites to clients before we launch them. development.mysite.com/clientname/, where the problem is the paths are /clientname/clientname/plugins/ rather than just /clientname/plugins/

leepfrog commented 12 years ago

+1 issue, tried commits listed here without success

hixen commented 12 years ago

Hello, can't get my Contact Form 7 plugin to work, i'll keep getting 404's all the time.

<link href="/develop/develop/wp-content/plugins/contact-form-7/styles.css?ver=3.1.1" rel="stylesheet"> <script src="/develop/develop/wp-content/plugins/contact-form-7/jquery.form.js"></script> <script src="/develop/develop/wp-content/plugins/contact-form-7/scripts.js"></script>

Using Multisite with sub directory. Tried the different fixes in this thread, but couldn't get anyone to work. And since my programing skills are very limited and just started playing around with the roots-scripts.php, and on line 27 I removed the WP_BASE, and no longer did I get the double /develop/develop syndrome as people where getting. (No I don't actually know what I did, or if I did break anything else)

So now my script links look like this: <script src="/develop/wp-content/plugins/contact-form-7/jquery.form.js"></script> <script src="/develop/wp-content/plugins/contact-form-7/scripts.js"></script>

But my <link> is still broken with /develop/develop/

So anyone, I don't know if i'm helping anyone, I just thought since it seems there is no fix for this, I just wanted to share my experiance, maybe leads to something, or it's another useless post.

Keep up the good work guys, i just love this theme for so many reasons.

lluisgerard commented 12 years ago

I have the same issue with free "Meteor Slides" plugin. I'm just saying it because you can play with it if you are trying to fix this issue :)

I installed my website inside "/wp" directory, to develop it, to eventually move it to root "/". But it duplicates "/wp": <link rel="stylesheet" href="/wp/wp/plugins/meteor-slides/css/meteor-slides.css?ver=1.0"> <script type='text/javascript' src='/wp/wp/plugins/meteor-slides/js/jquery.cycle.all.min.js?ver=3.3.1'></script> <script type='text/javascript' src='/wp/wp/plugins/meteor-slides/js/jquery.metadata.v2.js?ver=3.3.1'></script>

Even playing with roots-scripts.php I can't change it. I do change the main style.css app.css... but not the meteor slides related js and css.

In the meantime I'm just adding these urls directly on header.php, not very elegant solution but it works for development :)

Love this theme guys! thanks!! :)

thathurtabit commented 12 years ago

I'm hoping this is the right place to post this, but I'm having issues with loading @font-face through my Bootstrap.css file... it simply gives a 404 for the fonts, despite being there.

Does not work (relative path): http://localhost/mysite/fonts/Poly-Regular-webfont.svg (404)

Does work (absolute path): http://localhost/mysite/wp-content/themes/mytheme/fonts/Poly-Regular-webfont.eot

BTW I'm running site on XAMPP Windows.

UPDATE: Sorry! This was corrected here: https://github.com/retlehs/roots/issues/88

thathurtabit commented 12 years ago

Still no fix on this issue then? Arg!

retlehs commented 12 years ago

@swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw @swalkinshaw

hey bro. HEY. fix this.

leepfrog commented 12 years ago

it's free software. be kind to the people who wrote it and gave it away.

(i'm sure he would gladly accept a pull request for the fix).

thathurtabit commented 12 years ago

I'm really liking the theme as it provides loads of useful-ness, shame this issue means I can't really use it.

retlehs commented 12 years ago

not really - you can comment out the rewrites & root relative cleanup stuff pretty easily.

sdsanders commented 12 years ago

I've just been using older versions of inc/roots-actions.php and inc/roots-cleanup.php until someone smarter than me fixes this issue. Probably not the best solution, but it works for me.

retlehs commented 12 years ago

also: you will have no issues with the rewrites and URL cleanup if you use roots in a base directory - no subdir, no subfolder

thathurtabit commented 12 years ago

Thanks @retlehs - could you let me know specifically which bits to comment out? I just tried commenting out the roots_root_relative_url section in roots-cleanup.php but that caused a gazillion errors.

retlehs commented 12 years ago

sure, but i'm extremely busy with dayjob work and other projects. if you'd like for me to do your troubleshooting for you, you can email me at ben@benword.com and we can discuss my consultancy rates. ;)

otherwise, maybe someone else can help you out in the meantime - but right now i'm jammin' out some other work and can't spend time helping you out.

hopefully this issue will be resolved soon anyway. (maybe someone can bribe @swalkinshaw (maybe someone else can submit a fix))