I have multiple author accounts on one of my WordPress installs. Often I will create a post, and set the author to be a different account. However, when I upload images into that post, their attachment page lists the author as my account. How can I set the author for posts, and have it carry over to the media associated with that post?
2 Answers
Use this in your theme’s functions.php
:
add_filter( 'add_attachment', 'wpse_55801_attachment_author' );
function wpse_55801_attachment_author( $attachment_ID )
{
$attach = get_post( $attachment_ID );
$parent = get_post( $attach->post_parent );
$the_post = array();
$the_post['ID'] = $attachment_ID;
$the_post['post_author'] = $parent->post_author;
wp_update_post( $the_post );
}