The 'uploaded' date field for Media Library entries is read only. Is there a way to make it editable from the Attachment Details window in upload.php?
I've tried the following code as a plug-in. It looks like I'm half way there. This gives me the the Uploaded Date as an input field (good).
However, I can see that I am not hooking into the proper function to actually write that value back to wp_posts along with the other post fields.
SO: How do I hook my input field so that it is part of the object that updates wp_posts?
function jch_attachment_fields_to_edit( $form_fields, $post ){
$post_date = $post->post_date;
$form_fields['post_date'] = array(
'value' => $post_date ? $post_date : '',
'label' => __( 'Uploaded Date' )
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'jch_attachment_fields_to_edit', 10, 2 );
/**
* Update attachment metadata
*
* @param int $post_ID Attachment ID.
// this actually works, but only when the user clicks 'Edit more details'
*/
function jch_edit_attachment( $attachment_id ){
$post_ID = $_REQUEST['post_ID'];
if ( isset( $_REQUEST['attachments'][$attachment_id]['media_date'] ) ) {
$media_date = $_REQUEST['attachments'][$attachment_id]['media_date'];
$wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_date = %s WHERE ID = %s", $media_date, $post_ID));
}
}
add_action( 'edit_attachment', 'jch_edit_attachment' );
wp-admin/includes/template.php
has the date fields available in post edit form, andwp-admin/includes/meta-boxes.php
where the media date fields are... let us know how you tried to achieve something... good luck.