add_filter( 'attachment_fields_to_edit', 'attachment_fields_to_edit', null, 2 );
add_filter( 'attachment_fields_to_save', 'attachment_fields_to_save', null, 2 );
function attachment_fields_to_edit( $form_fields, $post ) {
$form_fields['my_attachment_field'] = array(
'label' => 'My Label',
'input' => 'text',
'value' => get_post_meta( $post->ID, '_my_attachment_field', true )
);
return $form_fields;
}
function attachment_fields_to_save( $post, $attachment ) {
if ( ! empty( $attachment['my_attachment_field'] ) )
update_post_meta( $post['ID'], '_my_attachment_field', $attachment['my_attachment_field'] );
else
delete_post_meta( $post['ID'], '_my_attachment_field' );
return $post;
}