Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing a custom plugin and i would like to add the "Add Media" button.

I just need to upload media, not to retrieve any content/data from the uploaded file.

How can I add this button?

Thanks

share|improve this question

1 Answer 1

If you want to add a add media button to your admin panels:

You need to use wp_enqueue_media();

    add_action ( 'admin_enqueue_scripts', function () {
        if (is_admin ())
            wp_enqueue_media ();
    } );

Then use this js:

    if ($('.set_custom_images').length > 0) {
    if ( typeof wp !== 'undefined' && wp.media && wp.media.editor) {
        $('.wrap').on('click', '.set_custom_images', function(e) {
            e.preventDefault();
            var button = $(this);
            var id = button.prev();
            wp.media.editor.send.attachment = function(props, attachment) {
                id.val(attachment.id);
            };
            wp.media.editor.open(button);
            return false;
        });
    }
};

Use this html:

        <p>
            <input type="number" value="" class="regular-text process_custom_images" id="process_custom_images" name="" max="" min="1" step="1">
            <button class="set_custom_images button">Set Image ID</button>
        </p>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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