Can I use the wp media uploader for my own plugin?

You can use wp_enqueue_media() in your admin_enqueue_scripts hook.

In a javascript file hook it into a button and use insert event to capture the selected image’s details

$('.media-button').click(function() {
    var media_uploader = wp.media({
            frame: "post",
            text : "Add image",
            state: "insert",
            multiple: false
        });


    media_uploader.on("insert", function(){
            var json = media_uploader.state().get("selection").first().toJSON();
            var image_name = json.filename;
            var image_url = json.url;
            var image_caption = json.caption;
            var image_title = json.title;
        });
    });

Leave a Comment