我正在为Wordpress编写一个插件,我想知道如何在媒体上传器中添加一个额外的按钮,上面写着“添加到相册”。我似乎找不到其他开发人员是如何做到这一点的信息。谢谢:)
向媒体上载程序添加按钮
3 个回复
最合适的回答,由SO网友:Gerben Van Dijk 整理而成
我设法这样做:
将JS添加到媒体上载程序:
function mediabutton(){
wp_register_script( \'mediabutton\', \'\'.WP_PLUGIN_URL.\'/magic-gallery/js/mediabutton.js\', null, null);
wp_enqueue_script( \'mediabutton\');
}
add_action(\'admin_print_scripts-media-upload-popup\',\'mediabutton\'); // Adding insert button
然后使用这个JS:jQuery(document).ready(function() {
jQuery(\'<a href="#" id="insert_gallery" class="button">Return to gallery</a>\').insertAfter(\'.ml-submit\');
jQuery(\'#insert_gallery\').live(\'click\',function() {
self.parent.tb_remove(); // This closes the thickbox
});
});
然后我像这样迷上了tb\\U close:tb_remove = function () {
// Your code here
alert(\'closing thickbox\');
// Original tb_remove code
jQuery("#TB_imageOff").unbind("click");
jQuery("#TB_closeWindowButton").unbind("click");
jQuery("#TB_window").fadeOut("fast",function(){jQuery(\'#TB_window,#TB_overlay,#TB_HideSelect\').trigger("tb_unload").unbind().remove();});
jQuery("#TB_load").remove();
if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
jQuery("body","html").css({height: "auto", width: "auto"});
jQuery("html").css("overflow","");
}
jQuery(document).unbind(\'.thickbox\');
return false;
}
SO网友:Bainternet
当我需要做类似的事情时,我使用admin_print_scripts-media-upload-popup
hookto添加我自己的js/Jquery代码来插入一个按钮,并用ajax处理它的click事件。
类似这样:
add_action(\'admin_print_scripts-media-upload-popup\',\'add_my_media_button\');
function add_my_media_button(){
?>
<script>
jQuery(document).ready(function() {
//loop over all attachments
jQuery(".savesend").each(function(i,v){
if (jQuery(this).next().attr(\'id\') != ""){
//get attachment id
var att_id = jQuery(this).next().attr(\'id\');
att_id = att_id.replace("send[", "");
att_id = att_id.replace("]", "");
//insert button
jQuery(this).append(\'<a href="#" class="button add_to_album" rel="\'+ att_id +\'" id="add_to_album[\'+att_id+\']" name="add_to_album[\'+att_id+\']">add to album</a>\');
}
});
//add handler for click
jQuery(".add_to_album").live("click", function(){
//do your thing here
alert("add to album click");
)};
)};
</script>
<?php
}
SO网友:krembo99
或者,您可以添加一个新选项卡,包含您想要的任何内容。
<?php
function my_media_menu($tabs) {
$newtab = array(\'tabname\' => __(\'TextInMenu\', \'yourname\'));
return array_merge($tabs, $newtab);
}
add_filter(\'media_upload_tabs\', \'my_media_menu\');
?>
结束