我想在“图库设置”中添加一个选项(将图库插入帖子时)。
我曾经找到一些关于如何做到这一点的代码,但不幸的是,我再也找不到了。我甚至记不起它是不是一个钩子,但我想它是一些黑客的东西;-)
Thx公司
我想在“图库设置”中添加一个选项(将图库插入帖子时)。
我曾经找到一些关于如何做到这一点的代码,但不幸的是,我再也找不到了。我甚至记不起它是不是一个钩子,但我想它是一些黑客的东西;-)
Thx公司
感谢Niall Campbell提供的multiple galleries插件提示,也感谢这个问题How to Add a Custom Colum on Thickbox Media Gallery Tab? (我从哪里弄到的钩子admin_head-media-upload-popup
从),我能够完成任务。
我添加了一个选项来添加style
属性设置为库短代码。
以下是完整的代码:
add_action( \'admin_head-media-upload-popup\', \'wpse_53803_script_enqueuer\' );
function wpse_53803_script_enqueuer()
{
if( $_GET[\'tab\'] == \'gallery\' )
{
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
// append the table row
$(\'#gallery-settings table#basic tbody\').append(\'<tr><th scope="row" class="label"><label><span class="alignleft">Style:</span></label></th><td class="field"><select id="style" name="style"><option value="standard">Standard</option><option value="slideshow">Slideshow</option></select></td></tr>\');
// set our vars
var $style = \'\', $is_update = false;
// Select parent editor, read existing gallery data
w = wpgallery.getWin();
editor = w.tinymce.EditorManager.activeEditor;
if (editor !== null) {
gal = editor.selection.getNode();
if (editor.dom.hasClass(gal, \'wpGallery\')) {
$style = editor.dom.getAttrib(gal, \'title\').match(/style=[\'"]([^\'"]+)[\'"]/i);
var $is_update = true;
if ($style != null) {
$style = $style[1];
$(\'table#basic #style\').find(\'option[value="\' + $style + \'"]\').attr(\'selected\',\'selected\');
}
} else {
$(\'#insert-gallery\').show();
$(\'#update-gallery\').hide();
}
}
// remove standard onmousedown action
$(\'#insert-gallery\').attr(\'onmousedown\', \'\');
// Insert or update the actual shortcode
$(\'#update-gallery, #insert-gallery, #save-all\').mousedown(function() {
var $styleAdd = \'\';
if (editor !== null)
var orig_gallery = editor.dom.decode(editor.dom.getAttrib(gal, \'title\'));
else
var orig_gallery = \'\';
// Check which which style is selected
if($(\'table#basic #style\').val() != \'standard\') {
$styleAdd = \' style="slideshow"\';
}
if ($(this).attr(\'id\') == \'insert-gallery\') {
w.send_to_editor(\'[gallery\' + wpgallery.getSettings() + $styleAdd + \']\');
}
// Update existing shortcode
if ($is_update) {
if ($styleAdd != \'\' && orig_gallery.indexOf(\' style=\') == -1)
editor.dom.setAttrib(gal, \'title\', orig_gallery + $styleAdd);
else if (orig_gallery.indexOf(\' style=\') != -1)
editor.dom.setAttrib(gal, \'title\', orig_gallery.replace(\' style="slideshow"\', $styleAdd));
else
editor.dom.setAttrib(gal, \'title\', orig_gallery.replace(\' style="slideshow"\', \'\'));
}
});
});
</script>
<?php
}
}
它添加了style="slideshow"
如果选择了幻灯片样式,否则不会添加任何内容。如果更新库,它会识别设置的样式,以便选择正确的选项。非常感谢。
hmmm检查一下Mutriple Galleries插件的代码,由于media\\u upload\\u gallery\\u表单功能(在wp admin/includes中)没有wordpress挂钩,它使用了javascript解决方法。然后,它将修改后的库短代码输出到编辑器(带有一些额外属性)。
如果要添加gallery快捷码未包含的其他属性,则需要为其编写自己的函数,但有很多信息可供使用,因此我将不深入讨论。
在WordPress中,是否有任何受支持的“脚本插件”、类和/或WordPress函数允许插件将其自身数据从数据库导出/导入到txt/json文件?一种帮助处理插件中备份功能数据的方法。最初的代码是我在本地主机上工作的,但不是在我上线时,因为各种原因。最初发布时,正如奥利在回答中指出的那样,“你不能上传AJAX文件。它们不受支持,但你可以伪造它。”How can I upload files asynchronously with jQuery?. 从那以后,又增加了一些答案。使用表单和ajax函数时,大