Automatically add image caption with values from a post parent field?

In the filter, you will need to find the post parent of $post, get the value of the custom field of parent post and then add that value to $post['post_excerpt'] (where the caption is stored):

add_filter('attachment_fields_to_save', 'wpse_insert_custom_caption', 10, 2);
function insert_custom_default_caption($post, $attachment) {

    //Check if the $post is attached to a parent post
    if( $post->post_parent ) {
        //Custom field of the attachment's parent post
        $custom_caption = get_post_meta( $post->post_parent, 'parent_custom_field', true );

        //captions are saved as the post_excerpt
        if ( !empty $custom_caption ) ) {
            $previous_caption = $post['post_excerpt'];
            $post['post_excerpt'] = $previous_caption.$custom_caption;
        }

    }

    return $post;
}

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)