2013-01-06 38 views
1

我有一個新的WordPress 3.5中的媒體上傳器小問題。我創建了自己的插件上傳圖片。我正在使用此代碼JS:顯示媒體上傳自己的插件WordPress的3.5

<script type="text/javascript"> 
    var file_frame; 

    jQuery('.button-secondary').live('click', function(event){ 

     event.preventDefault(); 

     if (file_frame) { 
      file_frame.open(); 
      return; 
     } 

     file_frame = wp.media.frames.file_frame = wp.media(
      { 
       title: 'Select File', 
       button: { 
        text: jQuery(this).data('uploader_button_text') 
       }, 
       multiple: false 
      } 
     ); 

     file_frame.on('select', function() { 
      attachment = file_frame.state().get('selection').first().toJSON(); 
      jQuery('#IMGsrc').val(attachment.url); 
     }); 

     file_frame.open(); 
    }); 
</script> 

代碼工作正常,但不幸的是窗體看起來不完整。當我選擇任何圖片時,右側沒有顯示「附件顯示設置」。我不知道爲什麼。我嘗試添加媒體選項:

displaySettings: true, 
displayUserSettings: true 

但它也行不通。

+0

你有沒有想過這個?我試圖做同樣的事情,所有的研究都顯示了同樣的事情,但沒有人解釋任何關於顯示附件設置選項的信息......在此先感謝。 – Bowenac

+0

也許你可以在這裏找到解決方案http://stackoverflow.com/questions/21540951/custom-wp-media-with-arguments-support – elhaj

回答

0

頁面中是否有源代碼中的<script type="text/html" id="tmpl-attachment-details">...模板?如果不是,則需要調用wp_print_media_templates()從wp-includes/media-template.php中編寫樣式。

0

這是我使用的代碼。資料來源:http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/它似乎工作得很好,但左邊的邊欄已丟失。 (故意的,但我不希望它)。

<?php wp_enqueue_media(); ?> 

<script> 

function showAddPhotos() { 

// Uploading files 
var file_frame; 

// event.preventDefault(); 

// If the media frame already exists, reopen it. 
if (file_frame) { 
    file_frame.open(); 
    return; 
} 

// Create the media frame. 
file_frame = wp.media.frames.file_frame = wp.media({ 
    title: jQuery(this).data('uploader_title'), 
    button: { 
    text: jQuery(this).data('uploader_button_text'), 
    }, 
    multiple: false // Set to true to allow multiple files to be selected 
}); 

// When an image is selected, run a callback. 
file_frame.on('select', function() { 
    // We set multiple to false so only get one image from the uploader 
    attachment = file_frame.state().get('selection').first().toJSON(); 

    // Do something with attachment.id and/or attachment.url here 
}); 

// Finally, open the modal 
file_frame.open(); 

} 
</script> 
相關問題