Skip to content

Instantly share code, notes, and snippets.

@andersonmadeira
Last active August 29, 2015 14:05
Show Gist options
  • Save andersonmadeira/8d5aeb959710a79b3013 to your computer and use it in GitHub Desktop.
Save andersonmadeira/8d5aeb959710a79b3013 to your computer and use it in GitHub Desktop.
Programmatically change media author on upload
<?php
/**
* Add this chunk of code to your functions.php (your theme)
* This hook will called when an attachment created.
* http://codex.wordpress.org/Plugin_API/Action_Reference/add_attachment
**/
add_filter( 'add_attachment', 'f77_change_author_attachment_author' );
function f77_change_author_attachment_author( $attachment_ID ) {
// get post (attachment)
$attachment = get_post( $attachment_ID );
$parent = get_post( $attachment->post_parent );
$toUpdate = array();
$toUpdate['ID'] = $attachment_ID;
$toUpdate['post_author'] = 38; // 38 is the user id
// actualy changes the post_author
wp_update_post( $toUpdate );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment