-
-
Save hemant-tivlabs/bff9d5943e5987324f363d64e6f5ad6f to your computer and use it in GitHub Desktop.
WordPress 3.5 media uploader in easier steps. If using other than edit post screen, don't forget to use wp_enqueue_media(); in your functions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
var _custom_media = true, | |
_orig_send_attachment = wp.media.editor.send.attachment; | |
$('.stag-metabox-table .button').click(function(e) { | |
var send_attachment_bkp = wp.media.editor.send.attachment; | |
var button = $(this); | |
var id = button.attr('id').replace('_button', ''); | |
_custom_media = true; | |
wp.media.editor.send.attachment = function(props, attachment){ | |
if ( _custom_media ) { | |
$("#"+id).val(attachment.url); | |
} else { | |
return _orig_send_attachment.apply( this, [props, attachment] ); | |
}; | |
} | |
wp.media.editor.open(); | |
return false; | |
}); | |
$('.add_media').on('click', function(){ | |
_custom_media = false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changing
wp.media.editor.open(button);
to
wp.media.editor.open();
helped me get rid of a
document.getElementById(...) is null
error.