使用Wordpress 3.5媒体管理器的NHP主题选项框架

时间:2012-12-17 09:25:39

标签: wordpress frameworks media

任何人都可以帮我为“NHP主题选项框架”创建一个基于“上传”类型的新字段类型,这样它就可以使用Wordpress自3.5以后使用的新“媒体管理器”而不是媒体上传器。这对滑块使用非常有用。

也许this post会有所帮助。

4 个答案:

答案 0 :(得分:1)

你很幸运我需要同样的功能。我设法通过查看代码并应用与旧媒体管理器相同的覆盖技术来实现。

事实上我已经写了一篇关于它的教程here

这是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);

答案 1 :(得分:0)

fyi ... http://reduxframework.com/是NHP的一个分支,增加了3.5个媒体加载器,并修复了NHP的其他区域。

我刚刚切换到目前为止并不差。

答案 2 :(得分:0)

请参阅我们的vafpress theme framework github代码段中的用法:

media manager with WP < 3.5 fallback

在代码中,还有这个变量(vp_wp.use_new_media_upload),您需要通过wp_localize_script“公开”到您的JS代码中,该变量需要说明您是否是Wordpress运行是否低于3.5,如果它低于3.5,那么它不应该使用新的媒体管理器,并使用thickbox media-upload.php iframe的旧方法。

答案 3 :(得分:0)

NHP刚刚与Redux Framework合并,Redux 3.0已经发布。它可以作为Wordpress插件或嵌入在主题中运行。你应该试试新版本。

http://wordpress.org/plugins/redux-framework/

它拥有完整的Wordpress媒体3.5支持,然后一些。它不仅存储媒体URL,还存储ID和全尺寸。

说真的,看一下。