[wp-trac] [WordPress Trac] #10744: autosaves deletes content for hidden meta_fields on custom widgets/plugins

WordPress Trac wp-trac at lists.automattic.com
Mon Sep 7 20:19:16 UTC 2009


#10744: autosaves deletes content for hidden meta_fields on custom widgets/plugins
-----------------------------+----------------------------------------------
 Reporter:  hertzel          |       Owner:  azaozz
     Type:  defect (bug)     |      Status:  new   
 Priority:  highest omg bbq  |   Milestone:  2.8.5 
Component:  Autosave         |     Version:        
 Severity:  major            |    Keywords:        
-----------------------------+----------------------------------------------

Comment(by leogermani):

 I am not sure if this can be considered a bug. Auto save only save the
 core information of a post, so if your plugin inadvertly does something
 like:

 {{{
 update_option('my_option' $_POST['my_field'];
 }}}

 you will erase your option in every auto-save becase $_POST['my_field']
 will be empty.

 What plugin writers must do is add a hidden field to their forms and check
 it before updating the option

 {{{
 if ($_POST['my_hidden_field']) update_option('my_option'
 $_POST['my_field'];
 }}}

 And why checking upon a hidden field and not the field itself? because you
 may want to clear the information on your field, and if you check upon it,
 you would never be able to set it to empty again.

 Conclusion: In my opinion this is not a bug and the documentation for
 add_meta_box should include the procedure above (I can do that if we
 agree)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10744#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list