[wp-hackers] Missing safety check in WP3.6

Luke Bryan lukebryan at sharefaith.com
Fri May 17 18:56:32 UTC 2013


Greetings,

I have been testing WP3.6 and have run into a problem. It seems a
safety check has been removed since wp3.5. In
wp-includes/js/media-editor.js, the add function used to simply return
the wp.media object of the object, if it existed already:

WP3.5:
add: function( id, options ) {
			var workflow = this.get( id );

			if ( workflow )
				return workflow;

			workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
				frame:    'post',
				state:    'insert',
				title:    wp.media.view.l10n.addMedia,
				multiple: true
			} ) );

			workflow.on( 'insert', function( selection ) { ...

WP3.6:
add: function( id, options ) {
			var workflow = this.get( id );

			workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
				frame:    'post',
				state:    'insert',
				title:    wp.media.view.l10n.addMedia,
				multiple: true
			} ) );

			workflow.on( 'insert', function( selection ) { ...

You used to be able to create the editor's add-media window and make
modifications to it, using
var dialog = wp.media.editor.add('content');
dialog.on('open', dosomething...
dialog.on(event, dosomethingelse...

This would work in 3.5, since all code calling "add" would get the
same object, creating it if it did not yet exist.
In 3.6, the same method seems to cause double-creation of the object,
which makes plupload fail when user tries to upload a file.
When that happens, it causes exception where $index is undefined, in
this section of media-views.js:
info: function() {
			var queue = this.queue,
				index = 0, active;

			if ( ! queue.length )
				return;

			active = this.queue.find( function( attachment, i ) {
				index = i;
				return attachment.get('uploading');
			});

			this.$index.text( index + 1 );

Is this a bug in 3.6, or does code that interacts with the uploader
need to be rewritten, to check existence with get() before calling
add(), and wait for the initial add() call on admin pages, somehow? I
couldn't find any documentation on this issue.

Other than that, wp3.6 seems pretty stable, looking forward to release
day Monday.

Best regards,
Luke


More information about the wp-hackers mailing list