6

I'd like to use the media uploader within my own plugin and I was wondering if this was possible?

Essentially I'd like the same functionality as found in media-new.php so I can have the same interface to add new files within my plugin as WordPress does.

Apologies for the lack of detail but I'm not sure how else to ask this question.

enter image description here

1 Answer 1

6

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;
        });
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.