WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#22495 closed defect (bug) (fixed)

Localize media-popup.js?

Reported by: bradyvercher Owned by: koopersmith
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords:
Focuses: Cc:

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)

#1 @ocean90
8 years ago

  • Cc koopersmith added
  • Milestone changed from Awaiting Review to 3.5

#2 follow-up: @SergeyBiryukov
8 years 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

#3 in reply to: ↑ 2 @koopersmith
8 years 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.

#4 @SergeyBiryukov
8 years 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

#5 @nacin
8 years ago

  • Owner set to koopersmith
  • Status changed from new to assigned

#6 @koopersmith
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 22694:

Media: Prevent undefined errors when media scripts are enqueued outside of wp_enqueue_media(). fixes #22495, see #21390.

Note: See TracTickets for help on using tickets.