感谢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"
如果选择了幻灯片样式,否则不会添加任何内容。如果更新库,它会识别设置的样式,以便选择正确的选项。
非常感谢。