Media upload not working on theme option in WordPress 3.8.1

I have this jQuery code in my plugin to display a media box preferably to upload an image or to pick an image from the media gallery:

(function($){
jQuery(document).ready(function() {

$('#upload_image_button').click(function(e) {

    e.preventDefault();

    //If the uploader object has already been created, reopen the dialog
    if (custom_uploader) {
        custom_uploader.open();
        return;
    }

    //Extend the wp.media object
    custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Choose Image',
        button: {
            text: 'Choose Image'
        },
        multiple: false
    });

    //When a file is selected, grab the URL and set it as the text field's value
    custom_uploader.on('select', function() {
        attachment = custom_uploader.state().get('selection').first().toJSON();
        $('#upload_image').val(attachment.url);
    });

    //Open the uploader dialog
    custom_uploader.open();

});

});
})(jQuery);

and thee are the following elements in my plugin option that binds with that jQuery code:

Read More
<input class="nput" id="upload_image" type="text" name="the_box[authorpic]" value="<?php echo $options['authorpic']; ?>" />&nbsp;<input class="button-primary" id="upload_image_button" type="button" value="Pick From Gallery" />

but now it doesn’t work, I mean nothing happens when I click or press the button now as it should display the media box just like before (I’m using now WordPress 3.8.1) and I’m sure I load up the jQuery scripts (I tested it).

What could cause this not to work any more? Any ideas, recommendations and suggestions will be greatly appreciated. Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. Try removing (function($){ from the beginning and })(jQuery); from the end. And change jQuery(document).ready(function() to jQuery(document).ready(function($)