--- post.php.orig	Sat Jan 27 15:32:57 2007
+++ post.php	Sat Feb 24 18:30:16 2007
@@ -1554,4 +1554,30 @@
 	return $post_id;
 }
 
+/**
+ * This function provides a standardized way to appropriately select on
+ * the post_status of posts/pages. The function will return a piece of
+ * SQL code that can be added to a WHERE clause; this SQL is constructed
+ * to allow all published posts, and all private posts to which the user
+ * has access.
+ * @param string $post_type currently only supports 'post' or 'page'.
+ * @return string SQL code that can be added to a where clause.
+ */
+function wp_get_pub_priv_sql($post_type) {
+	global $user_ID;
+	$cap = '';
+	if ( $post_type === 'post' ) $cap = 'read_private_posts';
+	elseif ( $post_type === 'page' ) $cap = 'read_private_pages';
+	else return '1 = 0'; // unknown post_type, make the query return nada
+	$sql = "(post_status = 'publish'";	
+	if ( current_user_can($cap) ) {
+		$sql .= " OR post_status = 'private'";
+	}
+	elseif ( is_user_logged_in() ) {
+		$sql .= " OR post_status = 'private' AND post_author = $user_ID";
+	}
+	$sql .= ')';
+	return $sql;
+}
+
 ?>
