[wp-trac] [WordPress Trac] #58664: Eliminate manual construction of script tags in WP_Scripts

WordPress Trac noreply at wordpress.org
Tue Sep 5 19:58:45 UTC 2023


#58664: Eliminate manual construction of script tags in WP_Scripts
-------------------------------------------------+-------------------------
 Reporter:  westonruter                          |       Owner:
                                                 |  westonruter
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  6.4
Component:  Script Loader                        |     Version:  6.3
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests 2nd-        |     Focuses:  javascript
  opinion                                        |
-------------------------------------------------+-------------------------
Changes (by azaozz):

 * keywords:  has-patch has-unit-tests => has-patch has-unit-tests 2nd-
               opinion


Comment:

 Replying to [comment:15 westonruter]:
 > For a discussion about the use of output buffering to ensure IDE
 intelligence for inline script tags with `wp_print_inline_script_tag()`
 extended to support passing a closure, see
 [https://wordpress.slack.com/archives/C5UNMSU4R/p1693591315595499 thread
 in #core-js]. For example:
 >
 > {{{#!php
 > <?php
 > wp_print_inline_script_tag(
 >       static function () {
 >               ?>
 >               <script>
 >                       var foo = 'bar';
 >                       /* JS code goes here */
 >               </script>
 >               <?php
 >       }
 > );
 > }}}

 Using a lambda function there looks a bit like a "weird hack" :)

 Seems `wp_print_inline_script_tag()` is not particularly suitable for this
 kind of usage. Wouldn't it be better to try to improve it instead of
 wrapping all "normal" scripts in WP in that PHP code?

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


More information about the wp-trac mailing list