[wp-trac] [WordPress Trac] #22896: Prevent plugins from overriding jQuery in the admin

WordPress Trac noreply at wordpress.org
Fri Jan 25 02:46:35 UTC 2013


#22896: Prevent plugins from overriding jQuery in the admin
------------------------------------+------------------
 Reporter:  nacin                   |       Owner:
     Type:  enhancement             |      Status:  new
 Priority:  normal                  |   Milestone:  3.6
Component:  External Libraries      |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  dev-feedback has-patch  |
------------------------------------+------------------

Comment (by auniquename):

 Replying to [comment:37 azaozz]:
 >
 > I may be mis-reading something but as Sergey pointed out above
 >
 > {{{
 > var mypluginjq = jQuery.noConflict();
 > }}}
 >
 > won't do it. You need
 >
 > {{{
 > var mypluginjq = jQuery.noConflict(true);
 > }}}
 >
 > so both `jQuery` and `$` are returned to the original values. See
 http://api.jquery.com/jQuery.noConflict/#example-4

 `*****`

 OK, I see now, thank you all for your patience and helpfulness. I know
 this is not really the place for such assistance and this is somewhat a
 tangent to the original topic of this ticket (though not entirely).

 So what I want to do in my myplugin-libs.js file is:

 {{{

 /* included minified jQuery */

 var mypluginjq = jQuery.noConflict(true);

 (function($){

 /* included minified jQuery UI */
 /* included minified Iris */

 }(mypluginjq));

 }}}

 ...and in my myplugin.js
 {{{

 mypluginjq(document).ready(function($) {

     /* Finally, my plugin jQuery stuff */

 });
 }}}

 No ugly hacks needed! Sweet. This makes the demonstration I was working on
 redundant, though it would still illustrate where the standard approach
 will go wrong...

 So the question remains, what about plugin authors who have not thought it
 through like this and simply use the WordPress bundled jQuery as
 recommended in the codex? Their plugins will break in a relatively short
 time. I still think an AMD style solution of some kind is required in the
 long run. In any case, I'd say some additions to
 http://codex.wordpress.org/Function_Reference/wp_enqueue_script are in
 order. If not there, then some more appropriate and prominent location.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22896#comment:38>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list