Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 17663)
+++ wp-includes/post.php	(working copy)
@@ -4063,8 +4063,8 @@
  * @param string $post_type currently only supports 'post' or 'page'.
  * @return string SQL code that can be added to a where clause.
  */
-function get_private_posts_cap_sql($post_type) {
-	return get_posts_by_author_sql($post_type, FALSE);
+function get_private_posts_cap_sql( $post_type ) {
+	return get_posts_by_author_sql( $post_type, false );
 }
 
 /**
@@ -4078,32 +4078,20 @@
  * @param int $post_author Optional.  Query posts having a single author ID.
  * @return string SQL WHERE code that can be added to a query.
  */
-function get_posts_by_author_sql($post_type, $full = TRUE, $post_author = NULL) {
+function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) {
 	global $user_ID, $wpdb;
 
 	// Private posts
-	if ($post_type == 'post') {
-		$cap = 'read_private_posts';
-	// Private pages
-	} elseif ($post_type == 'page') {
-		$cap = 'read_private_pages';
-	// Dunno what it is, maybe plugins have their own post type?
-	} else {
-		$cap = '';
-		$cap = apply_filters('pub_priv_sql_capability', $cap);
+	$post_type_obj = get_post_type_object( $post_type );
+	if ( ! $post_type_obj )
+		return ' 1 = 0 ';
+	$cap = $post_type_object->cap->read_private_posts;
 
-		if (empty($cap)) {
-			// We don't know what it is, filters don't change anything,
-			// so set the SQL up to return nothing.
-			return ' 1 = 0 ';
-		}
-	}
-
-	if ($full) {
-		if (is_null($post_author)) {
-			$sql = $wpdb->prepare('WHERE post_type = %s AND ', $post_type);
+	if ( $full ) {
+		if ( null === $post_author ) {
+			$sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type );
 		} else {
-			$sql = $wpdb->prepare('WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type);
+			$sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type );
 		}
 	} else {
 		$sql = '';
@@ -4111,15 +4099,15 @@
 
 	$sql .= "(post_status = 'publish'";
 
-	if (current_user_can($cap)) {
+	if ( current_user_can( $cap ) ) {
 		// Does the user have the capability to view private posts? Guess so.
 		$sql .= " OR post_status = 'private'";
-	} elseif (is_user_logged_in()) {
+	} elseif ( is_user_logged_in() ) {
 		// Users can view their own private posts.
 		$id = (int) $user_ID;
-		if (is_null($post_author) || !$full) {
+		if ( null === $post_author || ! $full ) {
 			$sql .= " OR post_status = 'private' AND post_author = $id";
-		} elseif ($id == (int)$post_author) {
+		} elseif ( $id == (int) $post_author ) {
 			$sql .= " OR post_status = 'private'";
 		} // else none
 	} // else none
Index: wp-includes/user.php
===================================================================
--- wp-includes/user.php	(revision 17663)
+++ wp-includes/user.php	(working copy)
@@ -165,18 +165,19 @@
  * Number of posts written by a list of users.
  *
  * @since 3.0.0
- * @param array $users User ID number list.
+ * @param array $user_ids Array of user IDs.
+ * @param string|array $post_type Optional. Post type to check. Defaults to post.
  * @return array Amount of posts each user has written.
  */
-function count_many_users_posts($users) {
+function count_many_users_posts($users, $post_type = 'post' ) {
 	global $wpdb;
 
 	$count = array();
-	if ( ! is_array($users) || empty( $users ) )
+	if ( empty( $users ) || ! is_array( $users ) )
 		return $count;
 
-	$userlist = implode( ',', $users );
-	$where = get_posts_by_author_sql( 'post' );
+	$userlist = implode( ',', array_map( 'absint', $users ) );
+	$where = get_posts_by_author_sql( $post_type );
 
 	$result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
 	foreach ( $result as $row ) {
