[wp-trac] [WordPress Trac] #26113: Create a WordPress-specific, dependable reference to the WP-bundled jQuery object.

WordPress Trac noreply at wordpress.org
Tue Nov 19 16:46:12 UTC 2013


#26113: Create a WordPress-specific, dependable reference to the WP-bundled jQuery
object.
--------------------------+-----------------------------
 Reporter:  markjaquith   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 When enqueueing jQuery for use on the front end of a site in a plugin or
 theme, a common concern is that the theme or another plugin has injected
 its own version of jQuery (probably an older version). This causes no end
 of support headaches for me as a plugin author.

 I've recently taken drastic measures in one of my plugins:

 I'm hooking in to `wp_enqueue_scripts` at -9999 and starting a buffer,
 then collecting it at `wp_head` 9999. I'm looking for the WP-included
 jQuery script tag, and then inserting this immediately after it:

 `<script>jQueryWP = jQuery;</script>`

 Then in my JS, I do:

 {{{
 ;(function (w) {
     var jQ = w.jQueryWP || w.jQuery;
     // my jQuery code here, using jQ
 })(window);
 }}}

 I think that having a dependable reference to WP's jQuery object would be
 quite useful. One way to solve it would be to just add the line to our
 copy of jQuery. But that will cause issues with people who use well-
 behaved CDN plugins to swap out WP's jQuery for a Google-hosted copy of
 jQuery (note: THE SAME VERSION). So maybe a better way to do it would be
 to create a way to append inline JS code immediately after the inclusion
 of a particular script handle. We could then do what I'm doing in my
 plugin, but without the nasty PHP output buffers.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26113>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list