Opened 6 months ago
Closed 6 months ago
#22495 closed defect (bug) (fixed)
Localize media-popup.js?
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Media | Version: | 3.5 |
| Severity: | normal | Keywords: | |
| Cc: | koopersmith |
Description
Some plugins that enqueue media-upload.js in the dashboard are throwing a javascript error in the beta: ReferenceError: _wpMediaViewsL10n is not defined.
This can be reproduced by implementing the following code and visiting any dashboard page that doesn't include the media upload functionality by default:
add_action( 'admin_enqueue_scripts', 'media_upload_js_test' );
function media_upload_js_test() {
wp_enqueue_script( 'media-upload' );
}
Change History (6)
comment:2
follow-up:
↓ 3
SergeyBiryukov — 6 months ago
Seems that the right way to include the media upload functionality on a page is to call wp_enqueue_media() instead of enqueueing the scripts directly:
http://core.trac.wordpress.org/browser/trunk/wp-includes/media.php?rev=22647#L1299
comment:3
in reply to:
↑ 2
koopersmith — 6 months ago
Replying to SergeyBiryukov:
Seems that the right way to include the media upload functionality on a page is to call wp_enqueue_media() instead of enqueueing the scripts directly.
You're correct. We should add some graceful fallbacks for the l10n variable to make sure things don't break when media-upload.js is enqueued as a dependency, though.
comment:4
SergeyBiryukov — 6 months ago
The example from the description actually produces two errors:
Timestamp: 19.11.2012 4:31:28 Error: ReferenceError: _wpMediaViewsL10n is not defined Source File: http://trunk.wordpress/wp-includes/js/media-views.js?ver=3.5-beta3-22645 Line: 9 Timestamp: 19.11.2012 4:31:28 Error: TypeError: wp.media.view.settings is undefined Source File: http://trunk.wordpress/wp-admin/js/media-upload.js?ver=3.5-beta3-22645 Line: 218
comment:6
koopersmith — 6 months ago
- Resolution set to fixed
- Status changed from assigned to closed
In 22694:

Also reported in the forum: http://wordpress.org/support/topic/35-beta-3-load-scripts-error-when-enqueuing-media-upload?replies=1