I'm studying theme development and am working on some code for a media uploader that can be used to add a picture. The file frame is opening (and I've called wp_enqueue_media();
for that to be the case), but nothing happens after the picture is selected.
I think I'm missing something simple and, frankly, I'm going crazy looking for it. Could anyone help me out?
jQuery(document).ready(function($){
var mediaUploader;
$('#upload-button').on('click', function(e){
e.preventDefault();
if(mediaUploader){
mediaUploader.open();
return;
}
mediaUploader = wp.media.frames.file_frame = wp.media({
title: 'Choose a profile picture',
button: {
text: 'Choose Picture'
},
multiple: false
});
//This alert fires.
alert("First message.");
$(mediaUploader).on('select', function(){
//This alert does not fire.
alert("Second message.");
});
mediaUploader.open();
});
});