S
S
Serufim2016-08-08 19:58:52
CMS
Serufim, 2016-08-08 19:58:52

How to make wp image upload field in admin panel on plugin settings page?

I am writing a plugin for wp and I have such a problem, it is necessary to make a field for uploading an image, or selecting it from the list of a media file, and as a result a link to this image should come. I have been looking for something similar for a long time, but most of the examples are only suitable for wp themes, but I need it to work from the admin page in the plugin settings. Thanks in advance for any help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-08-08
@Serufim

$('#add-image').click(function(e) {
        e.preventDefault();
        var image = wp.media({ 
            title: 'Upload Image',
            multiple: false
        }).open()
        .on('select', function(e){
            var uploaded_image = image.state().get('selection').first();
            console.log(uploaded_image);
            var image_url = uploaded_image.toJSON().url;
        });
    });

add the #add-image button
on click, get the standard media library window

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question