WordPress 3.5 custom media upload for your theme options

后端 未结 5 866
一个人的身影
一个人的身影 2020-12-04 05:08

WordPress 3.5 has been released recently, I used the WordPress Media Upload system via thickbox and window.send_to_editor for some options in my WordPress theme

5条回答
  •  时光说笑
    2020-12-04 05:39

    I modified this code a bit more to make it usable for multiple fields at once:

    HTML:

    
    
    
    
    
    Upload
    

    jQuery:

    jQuery(document).ready(function($){
    
    $('.custom_media_upload').click(function() {
    
            var send_attachment_bkp = wp.media.editor.send.attachment;
            var button = $(this);
    
            wp.media.editor.send.attachment = function(props, attachment) {
    
                $(button).prev().prev().attr('src', attachment.url);
                $(button).prev().val(attachment.url);
    
                wp.media.editor.send.attachment = send_attachment_bkp;
            }
    
            wp.media.editor.open(button);
    
            return false;       
        });
    
    });
    

提交回复
热议问题