There is a Bug when selecting attachments
-
there is a bug when selecting attachments, when there a file doesn’t have a thumbnail it will trigger an error I added a code to the plugin on my site to fix it, you can change the script by this one
function kgm_add_attachment() { var mediaframes = wp.media.frames.items = wp.media({ 'multiple': true }); mediaframes.on('select', function() { var attachment = mediaframes.state().get('selection').toJSON(); for(var i = 0; i < mediaframes.state().get('selection').length; i++) { var currentIDS = jQuery('#attachment_ids').val(); if (currentIDS == '') { currentIDS = currentIDS+attachment[i].id } else { currentIDS = currentIDS+','+attachment[i].id } if ( (typeof attachment[i].sizes !== undefined ) && ( typeof attachment[i].sizes !== 'undefined' ) ) { if ( attachment[i].sizes.thumbnail !== undefined ) url_image=attachment[i].sizes.thumbnail.url; else if (attachment[i].sizes.medium !== undefined ) url_image=attachment[i].sizes.medium.url; else url_image=attachment[i].sizes.full.url; } var file_image = (typeof attachment[i].sizes !== undefined ) && ( typeof attachment[i].sizes !== 'undefined' ) ? '<img src="'+url_image+'" style="max-width:150px;" /></br>' : ''; jQuery('#attachment_ids').val(currentIDS); jQuery('.details').append('<li data-id="'+attachment[i].id+'">'+file_image+'+attachment[i].title+' <b>['+attachment[i].mime+']</b><div class="remove dashicons dashicons-dismiss" onClick="kgm_remove_attachment(this)"></div></li>'); } }); mediaframes.open(); } function kgm_remove_attachment(id) { var old = jQuery(id).parent(); old.remove(); var currentIDS = ''; jQuery('.details li').each(function(){ if (currentIDS == '') { currentIDS = currentIDS+jQuery(this).data('id'); } else { currentIDS = currentIDS+','+jQuery(this).data('id') } }); jQuery('#attachment_ids').val(currentIDS); }
I hope this helps
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘There is a Bug when selecting attachments’ is closed to new replies.