Index: functions-post.php
===================================================================
--- functions-post.php	(revision 2786)
+++ functions-post.php	(working copy)
@@ -7,6 +7,9 @@
  */
 function wp_insert_post($postarr = array()) {
 	global $wpdb, $allowedtags, $user_ID;
+	
+	// for content prerendering, to simulate the loop
+	global $post, $id;
 
 	// export array as variables
 	extract($postarr);
@@ -15,8 +18,8 @@
 	$update = false;
 	if ( !empty($ID) ) {
 		$update = true;
-		$post = & get_post($ID);
-		$previous_status = $post->post_status;
+		$previous_version = & get_post($ID);
+		$previous_status = $previous_version->post_status;
 	}
 
 	// Get the basics.
@@ -104,7 +107,27 @@
 			$post_name = $alt_post_name;
 		}
 	}
+	
+	/* WP Content Prerendering by Mark Jaquith */
+	// In order to maintain backwards compatability with plugins that may be designed to be run from within the loop, we
+	// will now "simulate" the conditions of the loop, so that all expected global variables are availiable to the filters.
+	$post = $previous_version;
+	$fields = array(
+		'post_author',  'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt',
+		'post_status', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping',
+		'post_modified', 'post_modified_gmt', 'post_parent','menu_order'
+		);
 
+	// creating the post object, as it would look in the loop
+	foreach ( $fields as $field ) {
+		$post->$field = $$field;	
+	}
+	$post->ID = $post_ID;
+	$id = $post_ID;
+	
+	$post_content_filtered = apply_filters('the_content_filtered', $post_content);
+
+
 	if ($update) {
 		$postquery =
 			"UPDATE $wpdb->posts SET
@@ -112,6 +135,7 @@
 			post_date = '$post_date',
 			post_date_gmt = '$post_date_gmt',
 			post_content = '$post_content',
+			post_content_filtered = '$post_content_filtered',
 			post_title = '$post_title',
 			post_excerpt = '$post_excerpt',
 			post_status = '$post_status',
@@ -128,9 +152,9 @@
 	} else {
 		$postquery =
 			"INSERT INTO $wpdb->posts
-			(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order)
+			(ID, post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order)
 			VALUES
-			('$post_ID', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order')";
+			('$post_ID', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order')";
 	}
 	
 	$result = $wpdb->query($postquery);

