#10744 closed defect (bug) (worksforme)
autosaves deletes content for hidden meta_fields on custom widgets/plugins
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 2.8.4 |
Component: | Autosave | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
Steps to reproduce.
- create a new hidden meta field
add_post_meta($post_id, "_hidden", "under the table", true) or update_post_meta($post_id, $idx_item_name, $name);
- Create a regular meta field
add_post_meta($post_id, "Survive", "HI Im alive",true) or update_post_meta($post_di, "Survive", "HI Im alive");
using hook save_post
they save and be retrieved just fine but after the first call to autosave, _hidden will be be saved with "" instead of the value passed to the hook function
Change History (5)
#2
@
14 years ago
- Keywords reporter-feedback added
- Milestone changed from 2.8.5 to 2.9
- Priority changed from highest omg bbq to normal
- Version set to 2.8.4
#3
@
14 years ago
- Resolution set to worksforme
- Status changed from new to closed
Leogermani is right, also the first thing autosave does is define( 'DOING_AUTOSAVE', true );
so plugins can check whether that constant is defined and act accordingly.
#4
@
14 years ago
I have updated the example in the codex with a check for DOING_AUTOSAVE constant
http://codex.wordpress.org/Function_Reference/add_meta_box#Example
Leo
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:
you will erase your option in every auto-save becase $_POSTmy_field? will be empty.
What plugin writers must do is add a hidden field to their forms and check it before updating the option
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)