[wp-trac] [WordPress Trac] #24724: _wpMediaViewsL10n not correctly enqueued in wp_enqueue_media()

WordPress Trac noreply at wordpress.org
Tue Sep 2 01:01:03 UTC 2014


#24724: _wpMediaViewsL10n not correctly enqueued in wp_enqueue_media()
--------------------------+-----------------------------
 Reporter:  Fab1en        |       Owner:  wonderboymusic
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  4.0
Component:  Media         |     Version:  3.5.2
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+-----------------------------
Changes (by nacin):

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


Comment:

 [28840] is the incorrect fix here.

 wp_localize_script() should only be called on an already registered handle
 and only once translations are loaded. This `return false` has existed
 since the initial commit of the entire script loader ([7970]), so this
 smells like it is a developer error. Changing it now will allow plugin
 developers to start using this function earlier than intended and it will
 be near impossible to walk this back once it is released.

 The issue is core is using its API incorrectly. wp_localize_script()
 should only be called on an already registered handle, but in core's case,
 we register our handles just-in-time. So we only instantiate WP_Scripts
 when we need it and our scripts are only registered when some code tries
 to enqueue something. Basically, we shouldn't be calling
 wp_localize_script( 'media-views' ) before any guarantee that anything —
 including 'media-views' — is enqueued.

 Simply enqueuing media-editor before localizing media-views fixes
 everything without opening up wp_localize_script() up to abuse.

 Again, as long as you are using it against an already registered handle,
 then this is only an issue when attaching something to a core script that
 hasn't yet been JIT registered, which is only something core should be
 doing. We can and should work around it.

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


More information about the wp-trac mailing list