Skip to content

Instantly share code, notes, and snippets.

@UmeshSingla
Created July 18, 2013 13:22
Show Gist options
  • Save UmeshSingla/6029248 to your computer and use it in GitHub Desktop.
Save UmeshSingla/6029248 to your computer and use it in GitHub Desktop.
Media Uploader Wordpress
jQuery(document).ready(function(){
var _rtp_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
jQuery('.rtp-media-uploader').click(function () {
var button = jQuery(this),
textbox_id = jQuery(this).attr('data-id');
_rtp_media = true;
wp.media.editor.send.attachment = function (props, attachment) {
if ( _rtp_media && ( attachment.mime === 'application/pdf' ) ) {
jQuery( '#'+ textbox_id ).val( attachment.id );
button.next().show();
} else {
alert('Please select a valid PDF file');
return false;
}
}
wp.media.editor.open(button);
return false;
});
jQuery('.add_media').on('click', function(){
_rtp_media = false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment