Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 19471)
+++ wp-includes/post.php	(working copy)
@@ -2412,9 +2412,13 @@
  * @param bool $wp_error Optional. Allow return of WP_Error on failure.
  * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
  */
-function wp_insert_post($postarr, $wp_error = false) {
+function wp_insert_post($postarr, $wp_error = false, $user = null) {
 	global $wpdb, $wp_rewrite, $user_ID;
 
+	if ( is_null( $user ) ) {
+		$user = $user_ID;
+	}
+
 	$defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
 		'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
 		'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
@@ -2425,7 +2429,9 @@
 
 	unset( $postarr[ 'filter' ] );
 
-	$postarr = sanitize_post($postarr, 'db');
+	if ( $user ) {
+		$postarr = sanitize_post($postarr, 'db');
+	}
 
 	// export array as variables
 	extract($postarr, EXTR_SKIP);
@@ -2479,7 +2485,7 @@
 	}
 
 	// Don't allow contributors to set the post slug for pending review posts
-	if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) )
+	if ( 'pending' == $post_status && $user && !user_can( $user, 'publish_posts' ) )
 		$post_name = '';
 
 	// Create a valid post name.  Drafts and pending posts are allowed to have an empty
@@ -2615,7 +2621,7 @@
 			$taxonomy_obj = get_taxonomy($taxonomy);
 			if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
 				$tags = array_filter($tags);
-			if ( current_user_can($taxonomy_obj->cap->assign_terms) )
+			if ( !$user || user_can( $user, $taxonomy_obj->cap->assign_terms) )
 				wp_set_post_terms( $post_ID, $tags, $taxonomy );
 		}
 	}
