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

WordPress Trac noreply at wordpress.org
Wed Jul 10 23:04:25 UTC 2013


#24724: _wpMediaViewsL10n not correctly enqueued in wp_enqueue_media()
--------------------------+-----------------------------
 Reporter:  Fab1en        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  3.5.2
 Severity:  trivial       |   Keywords:
--------------------------+-----------------------------
 I use `wp_enqueue_media()` to use the new Media Library on the front end
 side and I found a very weird case where `_wpMediaViewsL10n` is not
 correctly declared in javascript before media-views script enqueue.

 In the `wp_enqueue_media` function, `wp_localize_script( 'media-views',
 '_wpMediaViewsL10n', $strings );` is called before `wp_enqueue_script(
 'media-editor' );` (which is dependent on `media-views` script), so there
 is a risk that `_wpMediaViewsL10n` is not taken into account if `media-
 views` script has not been enqueued before.

 If `wp_enqueue_media()` is called on the front-end with the admin-bar
 deactivated, you will have a js error saying `Cannot read property 'id' of
 undefined` when trying to read `wp.media.view.settings.post.id`.

 This issue can be solved by placing the `wp_localize_script` call just
 after `wp_enqueue_script( 'media-editor' )`.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24724>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list