[wp-hackers] post processing weirdness

Daniel Westermann-Clark daniel at acceleration.net
Wed Jul 6 13:48:09 GMT 2005


On 2005-07-06 01:50:01 -0400, Mark Jaquith wrote:
> Daniel, could you please post that patch to this list?  It's 404 for
> me.  WP 1.6 is quite a ways from being usable, and this bug is
> driving me crazy.

Oops.  Here's the patch.

To get a cruft-free permalink, the patch removes the current post from
the cache before setting the permalink.  Posts which move from draft
to publish status were cached as being in draft status when
get_permalink was called.

I realize it sets the permalink twice the 'post' action; previously I
had removed the first call but noticed that previews of posts in draft
status were broken (specifically the link in the title).

-- 
Daniel Westermann-Clark
-------------- next part --------------
Index: wp-admin/post.php
===================================================================
--- wp-admin/post.php	(revision 2700)
+++ wp-admin/post.php	(working copy)
@@ -188,11 +188,19 @@
 
 	add_meta($post_ID);
 
+	// Set the permalink regardless of post status so drafts have a valid link in the preview
 	$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
 
 	do_action('save_post', $post_ID);
 
 	if ('publish' == $post_status) {
+		// Bust the post cache to make sure permalinks work
+		global $post_cache;
+		if (isset($post_cache[$post_ID]))
+			unset($post_cache[$post_ID]);
+
+		$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
+
 		do_action('publish_post', $post_ID);
 		if ($post_pingback)
 			pingback($content, $post_ID);
@@ -433,6 +441,13 @@
 	do_action('edit_post', $post_ID);
 
 	if ($post_status == 'publish') {
+		// Bust the post cache to make sure permalinks work
+		global $post_cache;
+		if (isset($post_cache[$post_ID]))
+			unset($post_cache[$post_ID]);
+
+		$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
+
 		do_action('publish_post', $post_ID);
 		do_trackbacks($post_ID);
 		do_enclose( $content, $post_ID );


More information about the wp-hackers mailing list