[wp-meta] [Making WordPress.org] #5200: Update wp_register_script documentation to recommend registration on init instead of wp_enqueue_scripts

Making WordPress.org noreply at wordpress.org
Tue May 5 18:10:02 UTC 2020


#5200: Update wp_register_script documentation to recommend registration on init
instead of wp_enqueue_scripts
-------------------------+--------------------
 Reporter:  jhned        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  low          |  Milestone:
Component:  Codex        |   Keywords:
-------------------------+--------------------
 I disagree with
 [[https://developer.wordpress.org/reference/functions/wp_register_script/#notes|this
 part]] of the documentation for `wp_register_script`:

   The function should be called using the wp_enqueue_scripts action hook
 if you want to call it on the front-end of the site. To call it on the
 administration screens, use the admin_enqueue_scripts action hook. For the
 login screen, use the login_enqueue_scripts action hook. Calling it
 outside of an action hook can often lead to unexpected results and should
 be avoided.

 First off, according to `_wp_scripts_maybe_doing_it_wrong`, `init` is also
 an acceptable hook for registering scripts. The benefit we get from
 registering scripts on `init` is that plugins can get a comprehensive list
 of the registered scripts and styles in the WordPress Admin by accessing
 the "registered" property of the `$wp_scripts` and `$wp_styles` globals.
 If we're going to register scripts and styles, we should be able to pull a
 full list of the registered scripts and styles. The recommended usage is
 only for code efficiency, and has no other useful aspect to it.

-- 
Ticket URL: <https://meta.trac.wordpress.org/ticket/5200>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list