[wp-hackers] wp_enqueue_script() and URLs with 2+ parameters

Mike Schinkel mikeschinkel at newclarity.net
Fri Feb 27 18:36:30 GMT 2009


Hi all: 


I'm running into a quandry and am wondering if you have suggestions. 

I have a PHP file that accepts URL parameters to generate different Javascript depending on which page is calling it and I need to make sure that for each of the different generated JS there is a unique URL for reasons of HTTP caching. 

To start my PHP file sets the HTTP content type using: 


header('Content-Type:text/javascript'); 


In(directly with)in my functions.php file in my theme I'm using wp_enqueue_script() something like this: 


wp_enqueue_script('my-custom-js',"$template_url/ js/ my-custom-js .js.php?p1=A&p2=B&p3=C",array('jquery'),'1.0'); 


The problem is that WordPress sends the first URL that follows to the browser instead of the second URL which is what I need: 


http://example.com/wp-content/themes/my-theme/js/my-custom-js.js.php?p1=A&p2=B&p3=C 

http://example.com/wp-content/themes/my-theme/js/my-custom-js.js.php?p1=A&p2=B&p3=C 


My question is: "Is this really by design, or an oversight in the design?" 

I've tried to figure out how to solve this via a hook but the code is very complex and nested and I can't figure out how to hook it easily enough given my deadline today. 

I'm to the point of just moving that javascript reference into header.php and ignoring wp_enqueue_script() for this custom JS file (and that might be the best practice anyway), but it seems there is still a problem if and when a plugin needed to use a URL with multiple parameters and specify it using wp_enqueue_script(). 

So in summary my questions are: 


1.) Is this encoding of the ampersand in the URL from "&" to "#038;" by design, or is it a bug we can fix in core? 
2.) No matter the answer to #1, is there a hook that would allow a plugin to bypass this encoding? 


Thanks in advance. 

-Mike Schinkel 
http://mikeschinkel.com/ 


More information about the wp-hackers mailing list