I’m trying to re-order the links in the media box when selecting an image. I want to move “Use as featured image” above the insert into post button.
I also want to rename the “Use as featured image” text? I have done this by editing the media.php file in wp-admin/incudes/media.php but I don’t want to edit this everytime I upgrade.
Is it possible to re-order the elements without having to re-write the whole function?
Thanks in advance.
EDIT:
Basically I want to move the text above the button and maybe add a label on the left too like the others above. I also want to rename the text “use as featured image”.
EDIT
Thanks to goto10 for helping me get this far, the code below “works” as it changes the text and location of the featured image. Although as I cannot get the attachment ID, it will not save the image…it works by manually typing in the attachment 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);
Tried these to get attachment 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 );
Also tried replacing $_GET['post_id']
with $calling_post_id
Any suggestions on how to get the attachment ID? I tried copying most of the code from media.php
without any luck.