[wp-hackers] WP Auto-Save drafts causing slight havoc with my plugin

Jeremy Visser jeremy.visser at gmail.com
Tue Oct 17 14:08:36 GMT 2006

Hi. I'm writing a plugin dubbed "Match Scores" which is designed for
sports club blogs, where it will allow you to input the score of a
match into a post (via the dbx_post_advanced hook) and it will use
add_post_meta to add it to the table.

This is not my main problem, but I noticed that add_post_meta will
refuse to overwrite already existing metas. I realise there is an
update_post_meta function but then I will also have to use
get_post_meta to see if the meta already exists and whether I should
use add_post_meta or update_post_meta.

Anyway, my main question was this. What's the best way to work around
the auto-saving drafts feature of WordPress 2.1 not sending along the
custom form fields. The AJAX drafting will send only the contents of
the post, not my custom scoring fields, but the wp_insert_post hook is
still being called.

My plugin makes use of the wp_insert_post hook by deleting the post
meta if it is blank, i.e. if the user blanked the form to get rid of
the scores, or the side-effect of it also being blank when the AJAX
draft posts, thus deleting the post meta. If the custom fields are
sent along, then any of my post meta is deleted (only for this plugin)
and the fresher one is updated.

I would presume that is the normal way to do it, but the AJAX drafts
seem to have funny side-effects. Perhaps the wp_insert_post hook
should not be called when the draft is auto-saved? I noticed this
side-effect also affects Ultimate Tag Warrior, which also works in the
same way. I find that my tags are blanked after an auto-save took

My project page is here, where there is a link to the current source code:

Jeremy Visser
Email: jeremy.visser at gmail.com
Website: http://narnia.bounceme.net/jeremy/

More information about the wp-hackers mailing list