Jose,试试看你是不是在想这样的事。。
EDIT: 对核心代码进行了一点测试和复制,以将其归档,但我认为我在下面添加的新示例应该与您描述的一样,删除按钮“插入帖子”等等。。。,但保留删除链接。我留下了我提供的原始示例,因为它可能对某些人有用
新示例
删除按钮,但保留删除链接
function myAttachmentFields($form_fields, $post) {
// Can now see $post becaue the filter accepts two args, as defined in the add_fitler
if ( substr( $post->post_mime_type, 0, 5 ) == \'image\' ) {
$form_fields[\'image_alt\'][\'value\'] = \'\';
$form_fields[\'image_alt\'][\'input\'] = \'hidden\';
$form_fields[\'post_excerpt\'][\'value\'] = \'\';
$form_fields[\'post_excerpt\'][\'input\'] = \'hidden\';
$form_fields[\'post_content\'][\'value\'] = \'\';
$form_fields[\'post_content\'][\'input\'] = \'hidden\';
$form_fields[\'url\'][\'value\'] = \'\';
$form_fields[\'url\'][\'input\'] = \'hidden\';
$form_fields[\'align\'][\'value\'] = \'aligncenter\';
$form_fields[\'align\'][\'input\'] = \'hidden\';
$form_fields[\'image-size\'][\'value\'] = \'thumbnail\';
$form_fields[\'image-size\'][\'input\'] = \'hidden\';
$form_fields[\'image-caption\'][\'value\'] = \'caption\';
$form_fields[\'image-caption\'][\'input\'] = \'hidden\';
$form_fields[\'buttons\'] = array(
\'label\' => \'\',
\'value\' => \'\',
\'input\' => \'html\'
);
$filename = basename( $post->guid );
$attachment_id = $post->ID;
if ( current_user_can( \'delete_post\', $attachment_id ) ) {
if ( !EMPTY_TRASH_DAYS ) {
$form_fields[\'buttons\'][\'html\'] = "<a href=\'" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", \'delete-attachment_\' . $attachment_id ) . "\' id=\'del[$attachment_id]\' class=\'delete\'>" . __( \'Delete Permanently\' ) . \'</a>\';
} elseif ( !MEDIA_TRASH ) {
$form_fields[\'buttons\'][\'html\'] = "<a href=\'#\' class=\'del-link\' onclick=\\"document.getElementById(\'del_attachment_$attachment_id\').style.display=\'block\';return false;\\">" . __( \'Delete\' ) . "</a>
<div id=\'del_attachment_$attachment_id\' class=\'del-attachment\' style=\'display:none;\'>" . sprintf( __( \'You are about to delete <strong>%s</strong>.\' ), $filename ) . "
<a href=\'" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", \'delete-attachment_\' . $attachment_id ) . "\' id=\'del[$attachment_id]\' class=\'button\'>" . __( \'Continue\' ) . "</a>
<a href=\'#\' class=\'button\' onclick=\\"this.parentNode.style.display=\'none\';return false;\\">" . __( \'Cancel\' ) . "</a>
</div>";
} else {
$form_fields[\'buttons\'][\'html\'] = "<a href=\'" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", \'trash-attachment_\' . $attachment_id ) . "\' id=\'del[$attachment_id]\' class=\'delete\'>" . __( \'Move to Trash\' ) . "</a><a href=\'" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", \'untrash-attachment_\' . $attachment_id ) . "\' id=\'undo[$attachment_id]\' class=\'undo hidden\'>" . __( \'Undo\' ) . "</a>";
}
}
else {
$form_fields[\'buttons\'][\'html\'] = \'\';
}
}
return $form_fields;
}
// Hook on after priority 10, because WordPress adds a couple of filters to the same hook - added accepted args(2)
add_filter(\'attachment_fields_to_edit\', \'myAttachmentFields\', 11, 2 );
如何删除所有按钮的原始示例,但提供了插入到post按钮的示例。
function myAttachmentFields($form_fields, $post) {
if ( substr( $post->post_mime_type, 0, 5 ) == \'image\' ) {
// .. $form_fields code here(per above example), trimmed for illustration ..
$form_fields[\'buttons\'] = array(
\'label\' => \'\', // Put a label in?
\'value\' => \'\', // Doesn\'t need one
\'html\' => "<input type=\'submit\' class=\'button\' name=\'send[$post->ID]\' value=\'" . esc_attr__( \'Insert into Post\' ) . "\' />",
\'input\' => \'html\'
);
}
return $form_fields;
}
// Hook on after priority 10, because WordPress adds a couple of filters to the same hook
add_filter(\'attachment_fields_to_edit\', \'myAttachmentFields\', 15, 2 );
将过滤器设置为优先级15,这样在WordPress挂接了自己的过滤器后,它就会挂接上(因为它以默认优先级10添加过滤器)。
不确定您是否需要插入按钮,只想给出一个用单个插入按钮替换原始按钮的示例。。
希望这有帮助。。