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

Michael D Adams mikea at turbonet.com
Tue Oct 17 22:54:27 GMT 2006


On Oct 17, 2006, at 11:16 AM, Mark Jaquith wrote:

> On Oct 17, 2006, at 1:01 PM, Alex King wrote:
>
>> Should there be an "auto-save" state that doesn't fire any of the  
>> standard "post creation" hooks?
>
> At first glance, that sounds like the best solution.  I really  
> don't think auto-save should be saving any other data, like custom  
> post fields.

I don't see why autosave shouldn't save *everything*.

Here's an idea:
1. Submit the entire form via ajax.
2. That entire post array is saved in the appropriate post's  
'_wp_auto_save' custom field.
3. On normal save, delete that field.
4. On edit of post with that field, say "WP has recovered some  
automatically saved data for this post, would you like to use it".   
Click the link and it populates the form with the data from the  
custom field.

Advantages:
1. When working on an already published post, changes won't go live  
as WP autosaves.
2. Since the post and the autosave data are stored in different  
places, there's no chance for a data destroying race condition.
3. Easy to maintain on the JS side.  We just grab everything in the  
form and send it.  No need to pick out specific fields.
4. Autosave wouldn't need to trigger post_save or post_edit (or  
whatever the hooks are).

Disadvantages:
1. More bandwidth.
2. A little more coding on the backend.

Michael


More information about the wp-hackers mailing list