[wp-hackers] wp_enqueue_script() and URLs with 2+ parameters
Glenn Ansley
glenn at glennansley.com
Fri Feb 27 19:03:18 GMT 2009
Hi Mike,
I've done this before, but I don't have the code anymore because the
project was scratched (i'm an idiot for deleting code)
Maybe I can point you in the right direction though...
* There is a function in wp-includes/formatting.php called clean_url
* To make a long story short, wp_enqueue_script runs your src through
that before spitting it out.
* Luckily, there is a filter on the return and the original url is
preserved at the top of the clean_url() function.
* First, you will have to hook into that filter (remember to ask for
more than the 1 default accepted arg: <?php add_filter($tag,
$function_to_add, $priority = 10, $accepted_args = 1); ?>)
* Second, you will have to determine if it's filtering you're src (do
strpos() or something)
* If you get a match, return the original rather than the clean url.
Something like that... let me know if you have trouble.
Glenn Ansley
WordPress Plugin Development
http://fullthrottledevelopment.com
On Fri, Feb 27, 2009 at 1:36 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> 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/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list