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

WordPress Trac noreply at wordpress.org
Sat Jan 16 13:08:08 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 needs-refresh needs-unit-  |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by swissspidy):

 > * `print_inline_script()` returns always a boolean, but if
 `$this->do_concat` is true the expected return value is the script because
 of `$this->print_code .= $this->print_inline_script( $handle, 'before',
 false );`. `print_inline_style()` does it right in this case.
 > * When using `wp_add_inline_script( 'common', 'console.log("before");',
 'before' );` the script is printed after the localized data, but in concat
 mode it's printed before. It should be always after the localized data
 IMO.

 Yeah, that makes sense. Will update the patch.

 > * We don't have ID attributes for all the other script handling methods,
 is there a use case why `add_inline_script()` should add one? (Note: In
 concat mode the ID gets ignored.)

 I copied it from `add_inline_style`, but I agree that it's not really
 useful except that you know the handle it was added for. Doesn't hurt when
 it's absent.

 > * Beside `jQuery.noConflict();` are there any other places where core
 could benefit of the new methods? Maybe `wp_color_scheme_settings()`? (For
 back-compat reasons I don't think we can remove the `noConflict()` line
 for a while.)

 I haven't found any other place where JavaScript is printed inline besides
 these two. It's mainly for developers I think.

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


More information about the wp-trac mailing list