If we look at the source of wp_insert_attachment()
we find the hooks edit_attachment
and add_attachment
. In your case we could use the add_attachment
hook. The callback takes the attachment’s ID as a parameter. By looking at the database table wp_posts
we see that the description is saved as post_content
and the caption as post_excerpt
:
Then you could try this snippet:
/**
* Default title, caption and description to uploaded attachments
*
* @param integer $post_ID The attachment's ID
* @return void
*/
function wpse_121709_upload_defaults( $post_ID )
{
$args = array(
'ID' => $post_ID,
'post_title' => 'My default title ...',
'post_excerpt' => 'My default caption ...',
'post_content' => 'My default description ...',
);
wp_update_post( $args );
}
add_action( 'add_attachment', 'wpse_121709_upload_defaults' );
It should give you this result when you upload your file in the media uploader: