Index: src/wp-includes/user.php
===================================================================
--- src/wp-includes/user.php	(revision 28936)
+++ src/wp-includes/user.php	(working copy)
@@ -250,16 +250,18 @@
  * Number of posts user has written.
  *
  * @since 3.0.0
+ * @since 4.0.0 Added $post_type parameter.
  *
  * @global wpdb $wpdb WordPress database object for queries.
  *
- * @param int $userid User ID.
- * @return int Amount of posts user has written.
+ * @param int    $userid    User ID.
+ * @param string $post_type Optional. Post type to count the number of posts for. Default 'post'.
+ * @return int Number of posts the user has written in this post type.
  */
-function count_user_posts($userid) {
+function count_user_posts( $userid, $post_type = 'post' ) {
 	global $wpdb;
 
-	$where = get_posts_by_author_sql('post', true, $userid);
+	$where = get_posts_by_author_sql( $post_type, true, $userid );
 
 	$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
 
@@ -267,11 +269,13 @@
 	 * Filter the number of posts a user has written.
 	 *
 	 * @since 2.7.0
+	 * @since 4.0.0 Added $post_type parameter.
 	 *
-	 * @param int $count  The user's post count.
-	 * @param int $userid User ID.
+	 * @param int    $count     The user's post count.
+	 * @param int    $userid    User ID.
+	 * @param string $post_type Post type to count the number of posts for.
 	 */
-	return apply_filters( 'get_usernumposts', $count, $userid );
+	return apply_filters( 'get_usernumposts', $count, $userid, $post_type );
 }
 
 /**
Index: tests/phpunit/tests/user.php
===================================================================
--- tests/phpunit/tests/user.php	(revision 28936)
+++ tests/phpunit/tests/user.php	(working copy)
@@ -616,6 +616,25 @@
 	}
 
 	/**
+	 * @ticket 21364
+	 */
+	function test_count_user_posts() {
+		$post_type = rand_str( 10 );
+		register_post_type( $post_type );
+
+		$user_id = $this->factory->user->create( array( 'role' => 'author' ) );
+
+		wp_set_current_user( $user_id );
+		$this->factory->post->create_many( 15, array(
+			'post_author' => $user_id,
+			'post_type'   => $post_type
+		) );
+
+		$count = count_user_posts( $user_id, $post_type );
+		$this->assertEquals( 15, $count );
+	}
+
+	/**
 	 * @ticket 22858
 	 */
 	function test_wp_update_user_on_nonexistent_users() {
