Plugin Fix for Wordpress “Edit Post” Cache Bug

Lately, after upgrading all of my blogs to the latest WordPress version, I've noticed a strange behavior when editing my posts. It appears that whenever I pressed "Save," the post content would not update on the administration console. On the other hand, it would update on the main site.
For example, if I edited a post, everything from the title to the actual body of the article would not change. I would still see the original content when logged into the administration console. But if I viewed my site, everything would appear normally. The changes would only have reflected on the actual public portion of the blog! Even weirder was that when I checked my MySQL database, nowhere was any record of the original version! So where was WordPress pulling this outdated post data from?
Research
Last night, I was getting really pissed fighting this problem. So, I scoured the message boards for choice keywords related to my dilemma. The following threads were really helpful in diagnosing the problem:
- Edited post not updating in edit window after submission
- Edit shows first version of post
- Edit post weird behavior
- Edit shows first version of post
- Website not updated when database changes
- Cache in WP 2.0 beta
- V2.0.2 and cache
WordPress Caching
Apparently, this glitch has to do with the new WordPress caching system. For some strange reason, the developers of WordPress (Don't get me wrong! They're awesome!) implemented caching in the administration console. Everyone knows that this is overkill and unnecessary! Server-side caching is best employed when a wide audience is accesses a page. Usually, only one person sees the administration console, five people tops.
Plugin Fix
So, after reading the threads, I took a member's suggestion of writing a plugin. But, instead of implementing a button that I would manually have to pressed each time things are acting up (like the person suggested), I wrote a plugin that automatically clears the cache on each administration page load.
I'm providing this plugin to the public so people will not have to go through the same ordeal. Just paste this code into a uniquely named *.php file in the "plugins" directory (Example: "admin_cache.php").
-
<?php
-
/*
-
Plugin Name: Admin Cache Disabler
-
Plugin URI: http://www.hackernotcracker.com
-
Description: A glitch in some WordPress installations does no update the "Write Post" (Edit Post) page after pressing "Save." This bug is due to the caching system in WordPress. This plugin flushes the cache on each page load in the administration console. THIS PLUGIN ONLY WORKS WITH WP 2.0 AND ABOVE!
-
Author: Allan Barizo
-
Version: 1.0
-
Author URI: http://www.hackernotcracker.com
-
*/
-
add_action('admin_head', 'wp_cache_flush');
-
?>

Subscribe by RSS Feed
Stumble it!
Furl This!
Reddit!
May 7th, 2006 at 3:20 pm
Hi! Thanks for this GREAT plugin; not the most flashy but one of the most USEFUL one may find, when struck by the "Write page gives me an older version" syndrome... Ok, I installed it a few days ago, and it would work great, what a relief... but now it seems to do it again
(( I tried deactivate/reactivate but it still gives me an older version at times, so I need to use the "Cache Swoosh" plugin (which still seems to work). Any idea? And thank you again. I though maybe, as a complement, someone could come up with a simple "Cache swoosh" direct link in Admin links general menu. FWIW.
May 8th, 2006 at 11:33 am
I looked at the code in the "Cache Swoosh" plugin (http://rane.hasitsown.com/blog/plink/technical/31/plugin-to-flush-wordpress-cache/) and I really found no difference in the core functionality. Both my plugin and the Cache Swoosh plugin use the same function wp_cache_flush(); to flush the cache.
May 27th, 2006 at 3:51 pm
Hi,
just installed your plugin into my WP 2.0.2 and I still get the old content in the edit post field while the preview is update.
I would really need to know how to solve this.
Many thanks.
HYG
May 28th, 2006 at 12:59 pm
Really, I cannot find any reason why it doesn't work. But if you are desperate, I suggest that you temporarily turn of the cache. In the wp-config.php file, insert this line of code, "define('DISABLE_CACHE', true);"
May 28th, 2006 at 3:48 pm
Thanks, really.
I did what you suggested, actually. It worked. What really strikes me is that Wordpress is still performing exceptionaly well, even without cache.
Thanks very much for your time and your disturb in responding me.
Ciao,
Max
July 11th, 2006 at 7:24 am
[...] Thank god there’s actually a solution for this. And blur me didn’t notice it until today even though a plugin fix was published three months back. ZZZzzz… [...]
June 17th, 2007 at 2:06 pm
[...] Except, this doesn’t work for me. I have scoured the web, including the Wordpress forums. People seem to have all sorts of problems, some have even created plugins to purge the cache when the admin loads. Am I missing something? Isn’t WP-Cache supposed to purge the static files when content is updated? And if not, shouldn’t there at least be an option to tell it to do so? [...]