Get count of custom post type created by current user

I’m posting a new answer because I found this thread while searching for the same thing and the solutions here weren’t optimal.

The post_type argument can be a string or an array of post types.

function custom_count_posts_by_author($user_id, $post_type = array('post', 'page', 'custom_post_type'))
{
    $args = array(
        'post_type'      => $post_type,
        'author'         => $user_id,
        'post_status'    => 'publish',
        'posts_per_page' => -1
    );

    $query = new WP_Query($args);

    return $query->found_posts;
}

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