[wp-trac] [WordPress Trac] #14853: wp_add_inline_script()

WordPress Trac noreply at wordpress.org
Sun Feb 21 20:37:45 UTC 2016


#14853: wp_add_inline_script()
--------------------------------------+-------------------------
 Reporter:  mattwiebe                 |       Owner:  swissspidy
     Type:  enhancement               |      Status:  accepted
 Priority:  normal                    |   Milestone:  4.5
Component:  Script Loader             |     Version:  3.1
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-------------------------

Comment (by ocean90):

 Replying to [comment:40 swissspidy]:
 > Inline scripts are properly inserted after and before the handle (but
 after l10n scripts). If a script has a conditional comment, it's not
 concatenated just as before, with the inline scripts printed in the right
 order.

 That raises a question:

 Let's say we move `jQuery.noConflict();` out of jquery.js and instead
 we're adding it via `wp_add_inline_script()`:
 {{{#!php
 <?php
 add_action( 'admin_init', function() {
         wp_add_inline_script( 'jquery-core', 'jQuery.noConflict();' );
 });
 }}}

 Current output '''without''' concat:
 {{{#!htm
 <script type='text/javascript' src='http://develop.wp.dev/wp-
 includes/js/jquery/jquery.js?ver=1.12.0'></script>
 <script type='text/javascript'>
 jQuery.noConflict();
 </script>
 <script type='text/javascript' src='http://develop.wp.dev/wp-
 includes/js/jquery/jquery-migrate.js?ver=1.3.0'></script>
 }}}


 Current output '''with''' concat:
 {{{#!htm
 <script type='text/javascript' src='http://build.wp.dev/wp-admin/load-
 scripts.php?c=1&load%5B%5D=jquery-core,jquery-
 migrate,hoverIntent,…,thickbox&ver=4.5-alpha-20160221.211639'></script>
 <script type='text/javascript'>
 jQuery.noConflict();
 </script>
 }}}

 Is this the expected output in case of concatenation? Or shouldn't it be
 instead:

 {{{#!htm
 <script type='text/javascript' src='http://develop.wp.dev/wp-
 includes/js/jquery/jquery.js?ver=1.12.0'></script>
 <script type='text/javascript'>
 jQuery.noConflict();
 </script>
 <script type='text/javascript' src='http://build.wp.dev/wp-admin/load-
 scripts.php?c=1&load%5B%5D=jquery-
 migrate,hoverIntent,…,thickbox&ver=4.5-alpha-20160221.211639'></script>
 }}}

 This only affects wp-admin and it seems like the current output works
 anyway, but I think it's worth do mention it here.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/14853#comment:41>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list