Title: Plugin breaks default &quot;Add Media&quot; functionality.
Last modified: August 21, 2016

---

# Plugin breaks default "Add Media" functionality.

 *  Resolved [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/)
 * Hi again,
 * It seems like the plugin breaks the functionality to add media (images) via the
   default “Add Media” button above the post content edit field.
 * I’m able to select the image file in the overlay but when I click “insert” the
   post content is not updated and I get the following console output:
 * `ReferenceError: exhibition_image_id is not defined`
 * in scripts.min.js:2 (wp-content/plugins/exhibition/assets/js/scripts.min.js)
 * The issue remains when I disable the plugin for that post type.
    The issue resolves
   when I disable the plugin completely.
 * Upon encountering this I updated the plugin to the latest version but that did
   not fix the issue.
 * I will be looking into this and see if I can find more info.
 * [https://wordpress.org/plugins/exhibition/](https://wordpress.org/plugins/exhibition/)

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/page/2/?output_format=md)

 *  Plugin Author [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * (@mwtsn)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740318)
 * Hi there,
 * Could you tell me if you have upgraded to the latest version?
 * I patched this bug last night.
 * Matt 🙂
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740324)
 * Yes, I did update. I am using version 1.1.3 of the plugin.
 * [This ](http://pastie.org/8966777)is the script that is on my server.
 * It seems you are overriding `window.send_to_editor()` and basically replacing
   the default image upload functionality
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740329)
 * I just reinstalled the plugin and the issue persists, scripts.js seems to have
   the same contents, too.
 *  Plugin Author [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * (@mwtsn)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740339)
 * Thanks,
 * Looks like my patch didn’t upload properly :-/
 * I will get this fixed, but I’m afraid it will not be until this afternoon.
 * Sorry about this 🙁
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740341)
 * No problem!
 * If you still have a few seconds to spare then you could outline how the patch
   works and I can hack something together myself in the meantime.
 * The problem doesn’t look too complicated, I just dont have the time myself right
   now to go through all of the plugin and half of wordpress to figure out how it
   works. (Also, why do the same work twice.)
 * Anyway I thank you for your quick replies, I’m actually impressed.
 *  Plugin Author [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * (@mwtsn)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740344)
 * Hi there,
 * The patch should be replacing the scripts.min.js with the following:
 *     ```
       jQuery('.exhibition-image-upload').live( "click", function( e ) {
   
       	var id = jQuery(this).attr('id')
       	var id_split = id.split("-");
       	exhibition_image_id = id_split[1];
       	exhibition_src = jQuery(this).find('img').attr('src');
   
       	jQuery(this).removeClass('exhibition-image-upload').addClass('exhibition-image-remove');
       	jQuery(this).val('Remove Image');
   
       	tb_show( '', ' media-upload.php?type=image&TB_iframe=true' );
   
       	e.preventDefault();
       	return false;
       });
   
       jQuery('.exhibition-image-remove').live( 'click', function( e ) {
   
       	jQuery(this).remove();
   
       	e.preventDefault();
       	return false;
       });
   
       window.send_to_editor = function( html ) {
   
       	var parent 			= jQuery( '#exhibition_image-' + exhibition_image_id ).parent();
       	var image_url 		= jQuery( 'img', html ).attr('src');
       	var image_id 		= jQuery( 'img', html ).attr('class');
   
       	if( !image_url )
       	{
       		image_url = jQuery( html ).attr('src');
       	}
   
       	if( !image_id )
       	{
       		image_id = jQuery( html ).attr('class');
       	}
   
       	var image_output 	= '';
       	image_id 			= image_id.replace(/[^0-9]/g,'');
   
       	jQuery.post( ajaxurl, {
       		action: 'exhibition_gallery',
       		'image_id': image_id,
       	},
       	function(response) {
       		image_output = response.substring(0, response.length - 1);
   
       		jQuery( '#exhibition_image-' + exhibition_image_id ).val( image_url ).find('img').attr( 'src', image_url ).replaceWith( image_output );
       		jQuery( '#exhibition_image-' + exhibition_image_id ).val( image_url ).find('input').val( image_id );
       		jQuery( '#exhibition_image-' + exhibition_image_id ).append('<img class="exhibition-image-remove-hover" src="'+exhibition_src.replace( '/add.png', '/remove.png' )+'" alt="Remove image" />');
   
       		parent.append('<button id="exhibition_image-' + ( parseInt( exhibition_image_id ) + 1 ) + '" class="exhibition-image-upload" value="Add Image" type="submit"><img src="'+exhibition_src+'" height="150" width="150" alt=""/><input type="hidden" name="exhibition_image-' + ( parseInt( exhibition_image_id ) + 1 ) + '" value=""/></button>');
   
       		tb_remove();
   
       	});
       };
       ```
   
 * The key fix in this is the following block:
 *     ```
       if( !image_url )
       {
       	image_url = jQuery( html ).attr('src');
       }
   
       if( !image_id )
       {
       	image_id = jQuery( html ).attr('class');
       }
       ```
   
 * Basically the `html` variable that is passed into the `window.send_to_editor`
   function is an image tag, but sometimes WordPress puts it in a wrapper (which
   is what my original broken plugin checks for).
 * These two ifs, check to see if the variables have been set, and if they haven’t
   assumes that the `html` variable is not in a wrapper, and must be the `img` tag
   itself.
 * This was in the patch, but it looks like the minified version dosn’t contain 
   the fix :-/
 * Give this a go, and if it dosnt work, will you dump out the contents of the `
   html` variable, as you may have a case that I am not taking into consideration.
 * Cheers 🙂
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740350)
 * Weird fix you have there – That wasnt even the issue 😉
 * It is the variable `exhibition_image_id` which is defined in the $().live() event
   and is left undefined when the default uploader is used and therefore breaks 
   the script.
 * I think we just need to only override window.send_to_editor() when we actually
   use the gallery uploader.
 * PS: I was not even looking at the minified versions.
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740352)
 * Either way, just for the sake of completeness here are the outputs of the `html`
   variable.
 * Using default uploader to add to post:
 * `<a href="http://www.redacted.de/wp-content/uploads/2014/03/karte.jpg"><img src
   ="http://www.redacted.de/wp-content/uploads/2014/03/karte.jpg" alt="Karte" width
   ="630" height="472" class="alignleft size-full wp-image-541" /></a>`
 * Adding to gallery:
    `<a href="http://www.redacted.de/konzept/erlebnisorientierte-
   musikerziehung/karte/" rel="attachment wp-att-541"><img src="http://www.redacted.
   de/wp-content/uploads/2014/03/karte.jpg" alt="" width="630" height="472" class
   ="alignleft size-full wp-image-541" /></a>`
 *  Plugin Author [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * (@mwtsn)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740353)
 * Ahhh! You are right!
 * Back to the drawing board. I’m afraid I won’t get chance to patch this until 
   later today, but I’ll get to it.
 *  Plugin Author [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * (@mwtsn)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740354)
 * Actually, I’m going to try and fix it now, so if I do, I’ll post the fix here,
   and patch it later.
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740358)
 * Haha, did I wake your developer’s pride? 😀
 * I would look into this myself but unfortunately I have a million other todos 
   on this site that need to be taken care of by tonight too.
 *  Plugin Author [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * (@mwtsn)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740360)
 * Hi again,
 * Right, I think I have a fix in place.
 * Try putting this in your min.scripts.js file:
 *     ```
       jQuery('.exhibition-image-upload').live( "click", function( e ) {
   
       	send_to_editor_temp = window.send_to_editor;
   
       	var id = jQuery(this).attr('id')
       	var id_split = id.split("-");
   
       	exhibition_image_id = id_split[1];
       	exhibition_src = jQuery(this).find('img').attr('src');
   
       	jQuery(this).removeClass('exhibition-image-upload').addClass('exhibition-image-remove');
       	jQuery(this).val('Remove Image');
   
       	tb_show( '', ' media-upload.php?type=image&TB_iframe=true' );
   
       	window.send_to_editor = function( html ) {
   
       		var parent 			= jQuery( '#exhibition_image-' + exhibition_image_id ).parent();
       		var image_url 		= jQuery( 'img', html ).attr('src');
       		var image_id 		= jQuery( 'img', html ).attr('class');
   
       		if( !image_url )
       		{
       			image_url = jQuery( html ).attr('src');
       		}
   
       		if( !image_id )
       		{
       			image_id = jQuery( html ).attr('class');
       		}
   
       		var image_output 	= '';
       		image_id 			= image_id.replace(/[^0-9]/g,'');
   
       		jQuery.post( ajaxurl, {
       			action: 'exhibition_gallery',
       			'image_id': image_id,
       		},
       		function(response) {
       			image_output = response.substring(0, response.length - 1);
   
       			jQuery( '#exhibition_image-' + exhibition_image_id ).val( image_url ).find('img').attr( 'src', image_url ).replaceWith( image_output );
       			jQuery( '#exhibition_image-' + exhibition_image_id ).val( image_url ).find('input').val( image_id );
       			jQuery( '#exhibition_image-' + exhibition_image_id ).append('<img class="exhibition-image-remove-hover" src="'+exhibition_src.replace( '/add.png', '/remove.png' )+'" alt="Remove image" />');
   
       			parent.append('<button id="exhibition_image-' + ( parseInt( exhibition_image_id ) + 1 ) + '" class="exhibition-image-upload" value="Add Image" type="submit"><img src="'+exhibition_src+'" height="150" width="150" alt=""/><input type="hidden" name="exhibition_image-' + ( parseInt( exhibition_image_id ) + 1 ) + '" value=""/></button>');
   
       			tb_remove();
       		});
       		window.send_to_editor = send_to_editor_temp;
       	};
   
       	e.preventDefault();
       	return false;
       });
   
       jQuery('.exhibition-image-remove').live( 'click', function( e ) {
   
       	jQuery(this).remove();
   
       	e.preventDefault();
       	return false;
       });
       ```
   
 * Now when you click the button `window.send_to_editor()` is stored in a temporary
   variable, and then reassigned when the whole thing is over.
 * It seems to work for me, but if you have any more trouble let me know and I’ll
   jump on it.
 * I will put this in an official fix tonight after I’ve done some more testing.
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740379)
 * This works for me so far!
 * Thank you very much.
 *  Plugin Author [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * (@mwtsn)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740382)
 * Fantastic 🙂
 * I will push the patch later tonight and close the thread 🙂
 * Thanks for all your help in getting this working.
 *  Thread Starter [thelastcookie](https://wordpress.org/support/users/thelastcookie/)
 * (@thelastcookie)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/#post-4740400)
 * My pleasure!
 * Keep up the good work.

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/page/2/?output_format=md)

The topic ‘Plugin breaks default "Add Media" functionality.’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/exhibition_da6e8b.svg)
 * [Exhibition](https://wordpress.org/plugins/exhibition/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/exhibition/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/exhibition/)
 * [Active Topics](https://wordpress.org/support/plugin/exhibition/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/exhibition/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/exhibition/reviews/)

## Tags

 * [add media](https://wordpress.org/support/topic-tag/add-media/)
 * [images](https://wordpress.org/support/topic-tag/images/)
 * [media](https://wordpress.org/support/topic-tag/media/)

 * 16 replies
 * 2 participants
 * Last reply from: [Matt Watson](https://wordpress.org/support/users/mwtsn/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/plugin-breaks-default-add-media-functionality/page/2/#post-4740444)
 * Status: resolved