Tag: wordpress 3.5

WordPress的3.5自定义媒体上传为您的主题选项

WordPress的3.5最近已经发布,我通过thickbox和window.send_to_editor WordPress媒体上传系统在我的WordPress主题(背景,标志等)的一些选项。 但正如你所知,Wordpress已经集成了一个新的媒体pipe理器,我想用这个新function上传图片/文件作为自定义字段。 所以我花了早上find一个方法来获得希望的结果。 我发现与这个解决scheme,这可能对你们中的一些人有用。 感谢您向我提供关于代码的意见或任何改进意见! HTML示例: <a href="#" class="custom_media_upload">Upload</a> <img class="custom_media_image" src="" /> <input class="custom_media_url" type="text" name="attachment_url" value=""> <input class="custom_media_id" type="text" name="attachment_id" value=""> jQuery代码: $('.custom_media_upload').click(function() { var send_attachment_bkp = wp.media.editor.send.attachment; wp.media.editor.send.attachment = function(props, attachment) { $('.custom_media_image').attr('src', attachment.url); $('.custom_media_url').val(attachment.url); $('.custom_media_id').val(attachment.id); wp.media.editor.send.attachment = send_attachment_bkp; } wp.media.editor.open(); return false; }); 如果您想查看attachmentvariables中包含的每个设置,您可以执行console.log(attachment)或alert(attachment) 。