[wp-trac] [WordPress Trac] #48098: ReferenceError: jQuery is not defined even if it is enqueued ('wp_display_script_once' needed)

WordPress Trac noreply at wordpress.org
Wed Oct 16 10:22:08 UTC 2019


#48098: ReferenceError: jQuery is not defined even if it is enqueued
('wp_display_script_once' needed)
-------------------------------------+-------------------------
 Reporter:  KestutisIT               |       Owner:  (none)
     Type:  defect (bug)             |      Status:  reopened
 Priority:  normal                   |   Milestone:
Component:  Script Loader            |     Version:  5.2.3
 Severity:  normal                   |  Resolution:
 Keywords:  2nd-opinion needs-patch  |     Focuses:  javascript
-------------------------------------+-------------------------
Changes (by KestutisIT):

 * status:  closed => reopened
 * resolution:  wontfix =>


Comment:

 Replying to [comment:5 peterwilsoncc]:
 > @KestutisIT
 >
 > The existing function is
 https://developer.wordpress.org/reference/functions/wp_print_scripts/
 >
 > However, the recommended approach is to use code similar to the example
 provided above.

 Thanks for the information.
 So to be clear (as the documentation of that function is TRAGIC there -
 meaning no documentation at all) - does it will render that specific the
 script immediately. And if other plugin calls it once again - it will not
 render that script file for the second time.
 Also - why it is called 'wp_print_scripts', as I want to print out only
 specific scripts related to the plugin.
 And finally, if I have 'x.js' registed on AssetLoader.php with:

 {{{
 wp_register_script('x', array('jquery'));
 }}}

 When I call:

 {{{
 wp_print_scripts('x');
 }}}

 Will it render two scripts immediately:
 jquery.min.js
 and
 x.js

 I'm reopening this ticket as your answer is not clear as well as I do get
 the point why 'wp_print_scripts' are plural, but 'wp_enqueue_script' is
 singular, meaning:
 Is the 'wp_print_scripts' is equal to described appoarch of
 'wp_display_script_once' or not.

 Or it prints all the scripts that I do not want to print as well
 (including the one's that are enqueued by other plugins and which has to
 be printed on those plugin's template scopes).

 And the last thing - who decided that that this is not recomended? The
 'Clean code' book, as well as all the books about MVC, including the
 legendary:


 N. Rozanski, E. Woods - Software Systems Architecture - Working With
 Stakeholders Using Viewpoints and Perspectives (2nd Edition)

 Says differently what you said and they says that the mentioned path I
 wrote is the best practice. As well as the whole fact that WordPress is
 not based on 'BLOCKS' where it can be anything and it's part should stay
 in it's part only (expect the actually 'header' and 'meta' things required
 by some plugins).

 Feel free to close this ticket if it is does what I described. Otherwise
 there is no solution what I described.

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


More information about the wp-trac mailing list