[英]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.