我正在尝试在选择图像时重新排序媒体框中的链接。我想将“用作特色图片”移到“插入帖子”按钮上方。
我还想重命名“用作特色图像”文本?我通过编辑媒体做到了这一点。wp admin/INCLUDES/media中的php文件。php,但我不想每次升级都编辑这个。
是否可以在不必重写整个函数的情况下对元素重新排序?
提前谢谢。
编辑:
基本上,我想把文本移到按钮上方,也许还会像上面其他的一样在左侧添加标签。我还想重命名文本“use as featured image”。
编辑
感谢goto10帮助我做到这一点,下面的代码“起作用”,因为它更改了特征图像的文本和位置。虽然我无法获取附件ID,但它不会保存图像。。。它通过手动键入附件ID来工作。
function custom_attachment_fields_to_edit($form_fields, $post) {
$form_fields[\'buttons\'] = array(
\'label\' => \'Banner Image\',
\'value\' => \'\',
\'input\' => \'html\'
);
$thumbnail = \'\';
$calling_post_id = 0;
if (isset($_GET[\'post_id\']))
$calling_post_id = absint($_GET[\'post_id\']);
elseif (isset($_POST) && count($_POST))
$calling_post_id = $post->post_parent;
$attachment_id = ???
$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
$form_fields[\'buttons\'][\'html\'] = $thumbnail = "<a class=\'\' id=\'wp-post-thumbnail-" . $attachment_id . "\' href=\'#\' onclick=\'WPSetAsThumbnail(\\"$attachment_id\\", \\"$ajax_nonce\\");return false;\'>Set as Banner Image</a>";
return $form_fields;
}
add_filter(\'attachment_fields_to_edit\', \'custom_attachment_fields_to_edit\', 11, 2);
尝试获取附件ID:$args = array(\'post_type\' => \'attachment\', \'post_parent\' => $_GET[\'post_id\'] );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
$attachment_id = $attachment->ID;
}
}
$attachment_id = get_post_meta($_GET[\'post_id\'], \'_wp_attachment_image_id\', true);
$attachment_id = get_post_meta($_GET[\'post_id\'], \'_wp_attachment_url\', true );
还尝试更换$_GET[\'post_id\']
具有$calling_post_id
关于如何获取附件ID有什么建议吗?我试着从media.php
没有任何运气。