I’m using the code below to add a custom text field in WP 3.5 Attachment Window (from this question # Expanding new Media Uploader in WordPress 3.5) …
add_filter( 'attachment_fields_to_edit', 'xf_attachment_fields', 10, 2 );
function xf_attachment_fields( $fields, $post ) {
$meta = get_post_meta($post->ID, 'meta_link', true);
$fields['meta_link'] = array(
'label' => 'More Media Management',
'input' => 'text',
'value' => $meta,
// 'html' => '<div class="meta_link"><input type="text" /></div>',
'show_in_edit' => true,
);
return $fields;
}
add_filter( 'attachment_fields_to_save', 'xa_update_attachment_meta', 4);
function xa_update_attachment_meta($attachment){
global $post;
update_post_meta($post->ID, 'meta_link', $attachment['attachments'][$post->ID]['meta_link']);
return $attachment;
}
add_action('wp_ajax_save-attachment-compat', 'xa_media_xtra_fields', 0, 1);
function xa_media_xtra_fields() {
$post_id = $_POST['id'];
$meta = $_POST['attachments'][$post_id ]['meta_link'];
update_post_meta($post_id , 'meta_link', $meta);
clean_post_cache($post_id);
}
This code adds the field there and I can also save and afterwards retrieve value for any of my attachment. But the issue is this code does NOT saves value of any attachment by using AJAX.
Mean, if for any attachment image I define any value in this custom field, then selecting another image will remove my defined value for that image apparently. However, if I update the post and check again that field the saved value is there.
I wanted to be able to add author information to my attachments and merged this code: http://www.billerickson.net/wordpress-add-custom-fields-media-gallery/ with the one you refer to. I Got it to work fully in the modal window via AJAX. The modified code is as follows:
Hope this was helpful!
P.S. The next challenge will be to append this to images uploaded in the document. D.S.