[英]NHP Theme Options Framework using Wordpress 3.5 Media Manager
誰能幫助我為基於“上載”類型的NHP主題選項框架創建新的字段類型,以便它可以使用Wordpress從3.5開始使用的新“媒體管理器”,而不是“媒體上載器”。 這對於與滑塊一起使用非常有用。
也許這篇文章會有所幫助。
您很幸運,我需要同樣的功能。 通過查看代碼並應用與舊媒體管理器相同的替代技術,我設法做到了。
實際上,我在這里已經編寫了有關它的教程。
這是JavaScript代碼:
(function($){
var doc = {
ready: function(){
// initialize only if our button is in the page
if($('#btn_browse_files').length > 0){
slider.init();
}
}
},
slider = {
// the following 2 objects would be our backup containers
// as we will be replacing the default media handlers
media_send_attachment: null,
media_close_window: null,
init: function(){
// bind the button's click the browse_clicked handler
$('#btn_browse_files').click(slider.browse_clicked);
},
browse_clicked: function(event){
// cancel the event so we won't be navigated to href="#"
event.preventDefault();
// backup editor objects first
slider.media_send_attachment = wp.media.editor.send.attachment;
slider.media_close_window = wp.media.editor.remove;
// override the objects with our own
wp.media.editor.send.attachment = slider.media_accept;
wp.media.editor.remove = slider.media_close;
// open up the media manager window
wp.media.editor.open();
},
media_accept: function(props, attachment){
// this function is called when the media manager sends in media info
// when the user clicks the "Insert into Post" button
// this may be called multiple times (one for each selected file)
// you might be interested in the following:
// alert(attachment.id); // this stands for the id of the media attachment passed
// alert(attachment.url); // this is the url of the media attachment passed
// for now let's log it the console
// not you can do anything Javascript-ly possible here
console.log(props);
console.log(attachment);
},
media_close: function(id){
// this function is called when the media manager wants to close
// (either close button or after sending the selected items)
// restore editor objects from backup
wp.media.editor.send.attachment = slider.media_send_attachment;
wp.media.editor.remove = slider.media_close_window;
// nullify the backup objects to free up some memory
slider.media_send_attachment= null;
slider.media_close_window= null;
// trigger the actual remove
wp.media.editor.remove(id);
}
};
$(document).ready(doc.ready);
})(jQuery);
fyi ... http://reduxframework.com/是NHP的分支,並添加了3.5介質加載程序,還修復了NHP的其他區域。
我剛切換到到目前為止還不錯。
在我們的vafpress主題框架 github代碼片段中查看用法:
在代碼中,還存在此變量( vp_wp.use_new_media_upload
),您需要通過wp_localize_script
將其“暴露”到您的JS代碼中,該變量用於說明您運行的Wordpress是否在3.5以下。在3.5以下,則不應使用新的媒體管理器,而應使用通過厚框media-upload.php iframe使用的舊方法。
NHP剛剛與Redux Framework合並,並且Redux 3.0已發布。 它可以作為Wordpress插件運行,也可以嵌入主題中。 您確實應該嘗試新版本。
http://wordpress.org/plugins/redux-framework/
它具有對Wordpress Media 3.5的完全支持,然后提供了一些支持。 它不僅存儲媒體URL,還存儲ID和完整尺寸。
認真地檢查一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.