[wp-hackers] Custom Fields -- Lost by Autosave??

Sharon Chambers sharon at BrewerRadio.com
Thu Sep 17 20:17:00 UTC 2009


OK, with you now.  However, still experiencing same behavior after adding:

add_action('edit_post',     array($_bec, 'PostEventsMeta'));
add_action('save_post',     array($_bec, 'PostEventsMeta'));
function PostEventsMeta($id) {
	if ( wp_is_post_revision( $id ) || wp_is_post_autosave( $id ) )
		return;
	...
}

The autosave removes the custom fields I've added before, even though the autosave version *should* be saved as a revision, no?  

Looks to me like the autosave should contain the meta data for the post, but in that case, my plugin would not break.  Perhaps I don't understand autosave feature well enough...

Many thanks,
Sharon


-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of John Blackbourn
Sent: Thursday, September 17, 2009 4:02 PM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] Custom Fields -- Lost by Autosave??

What I meant was that your save_post hook is firing on every save. The
save_post hook is fired when an autosave occurs, *but* an autosave
won't contain the hidden field data that your hook expects, therefore
you should put the code above into your hook so that nothing occurs
when an autosave is saved.

2009/9/17 Sharon Chambers <sharon at brewerradio.com>:
> More testing...
> It is, in fact, the autosave.  If I pull up a post (with custom fields already saved to it) in the editor, leave it up mere seconds, the custom fields remain unchanged.
>
> However, if I allow the autosave to fire -- leaving the msg "Draft Saved at [...] Last edited by [...]" and then I close the UNCHANGED/UN-UPDATED post, and return to it again, custom fields are missing (my event data is not recognized and quick check of postmeta table comes up empty).
>
> I suppose I could workaround by not "hiding" my custom fields, but then I run the risk of users tinkering with the data.  Hmmm...sure wish I could figure out what's happening.
>
> -Sharon
>
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Sharon Chambers
> Sent: Thursday, September 17, 2009 3:32 PM
> To: 'wp-hackers at lists.automattic.com'
> Subject: Re: [wp-hackers] Custom Fields -- Lost by Autosave??
>
> Thanks, John.
> I'm not sure I follow though...
>
> It's not that I'm saving data for an autosave version, it's that my custom field is simply removed from the post.  Darndest thing, really.
>
> Good call for the revision check, though.  I'll see if I can't re-enabled that feature.
>
> Want me to setup an account for you to see what I'm talking about?
> -Sharon
>
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of John Blackbourn
> Sent: Thursday, September 17, 2009 3:26 PM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] Custom Fields -- Lost by Autosave??
>
> Sharon,
>
> When saving the custom field data inside the function that gets called
> with the save_post (or edit_post, can't remember off the top of my
> head) hook, you need to check that the post being saved isn't a
> revision or an autosave.
>
> Eg I use the following code:
>
> if ( wp_is_post_revision( $post_ID ) or wp_is_post_autosave( $post_ID ) )
>        return;
>
> HTH, John.
>
> 2009/9/17 Sharon Chambers <sharon at brewerradio.com>:
>> I've been testing some more...
>> It appears that a standard custom field (i.e., NOT one appended with underscore _), does not get affected the same way.  Is there special handling of "hidden" custom fields?  Or is there something else I'm not seeing...
>>
>>
>>
>> -----Original Message-----
>> From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Sharon Chambers
>> Sent: Thursday, September 17, 2009 1:29 PM
>> To: 'wp-hackers at lists.automattic.com'
>> Subject: [wp-hackers] Custom Fields -- Lost by Autosave??
>>
>> I originally posted this on Wordpress.org forum, but was directed here by a moderator.
>> Here's my question, I'll be happy to forward code, login, etc, to anyone willing to help debug:
>>
>> I'm writing a custom events plugin that integrates to the Wordpress edit post/page admin screen, and it works like a charm...
>> that is, until you leave the post open in the editor for "too long" (i'm guessing over 2 minutes, though I haven't verified this yet...that's the length of my autosave interval). Here's the gist:
>> My plugin adds an event box to the sidebar of the edit post/page screen using the following hooks/filters:
>> edit_post, publish_post, save_post, delete_post, admin_menu, manage_posts_columns, manage_pages_columns
>> When a post/page is published, if this event box is checked, then I write some stuff to the database and add 2 custom fields to the post/page: _bec_expiration (the expiration date of the event) and _bec_id (the db id of the event). (The underscores are so Wordpress doesn't display in the standard custom field section).
>> However, if I then leave the post up in the editor for a few minutes (?2 or longer?), then return and leave the page (without changing and/or updating my post), my custom fields, and hence my event information, is gone! -poof!-
>> I'm unable to find a hook into the autosave feature of Wordpress, and I'm unable to disable this functionality. (I already had to disable revisioning which interfered with my plugin also by pulling the post revision id instead of the post id).
>> Any ideas?
>>
>>
>>
>> Sharon Chambers
>> Webmaster
>> brewer media
>> 1305 Carter Street
>> Chattanooga, TN 37402
>> (423)242-7652 office
>> (423)266-2335 fax
>> Sharon at BrewerMediaGroup.com
>> Brewer Broadcasting:
>> Power 94.9 | Groove 93.7 | ESPN Chattanooga 105.1 | Pulse News 95.3
>> Brewer Interactive:
>> BOGONooga.com | ChattanoogaLivesGreen.com | ChattanoogaHasFun.com | ChattanoogaHasCars.com | ChattanoogaHasTravel.com | ChattanoogaCrime.com
>> Brewer Publishing:
>> ChattanoogaPulse.com, The Pulse - Chattanooga's Alternative Weekly Newspaper
>> Chattanooga Traffic Network:
>> 17 Radio Stations | 3 Television Stations | Traffic Reports & Sponsorships
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list