wp-post-meta-revisions icon indicating copy to clipboard operation
wp-post-meta-revisions copied to clipboard

Meta revisions revert to empty fields

Open citelao opened this issue 8 years ago • 10 comments

  1. Add versioning to any meta field
  2. Make a post with that field
  3. Edit that post's field
  4. Revert
  5. Post has now reverted to empty field.

citelao avatar May 28 '16 16:05 citelao

Well - for me it didn't seem to be going to blank specifically - but it seems to be going one revision off.

Here is what I had tried:

  1. Add versioning to a meta field
  2. Made a post with that field - I used "Test 1" for both values to make it easy to see
  3. Edited both title and that field - I used "Test 2" for both values
  4. Edit a second time both title and that field - I used "Test 3" for both values.
  5. Try to restore the revision with title of "Test 2" - at this point the title will be properly restored to "Test 2" - but the meta field will have "Test 1"

Can you try to extend your test to see if that is what is happening for you?

Marus avatar Jun 21 '16 13:06 Marus

@Marus, I'm experiencing the same as you. Any progress? Will update here if I learn anything of value.

davidbenton avatar Aug 03 '16 17:08 davidbenton

I have exactly the same experience @Marus described. Is there any progress on this?

sarahovenall avatar Sep 09 '16 13:09 sarahovenall

@davidbenton @Marus @sarahovenall Thanks for your reports and patience in me getting back to you here.

Are you using a custom post type or standard WordPress posts? Can you give me more details about how you are creating the custom meta fields and how you are saving them?

With standard posts the plugin should actually work as expected. Because of the way WordPress core fires revisions and this plugin hooks in, you will find meta revisions 'off by one' for custom post types (and probably pages) because the revision is saved before the meta gets updated. You can correct this by hooking your meta save on 'save_postinstead ofsave_post_{post_type}` (you can bail early in the callback to only handle your CPT). Can you give this a try and let me know if this works for you? I'm working on addressing directly in WordPress core.

For testing, you may want to check out this branch where I have the meta fields showing in the revisions UI so you can see what was saved with each post and if they match.

adamsilverstein avatar Feb 01 '17 18:02 adamsilverstein

It was a custom post type in my case, @adamsilverstein, so it sounds like you have a solution. I ended up rolling the basic functionality we needed into the plugin we were building, so we're not using wp-post-meta-revisions anymore. Thanks for your work on this; seems like it'll be a great contribution to core.

davidbenton avatar Feb 03 '17 21:02 davidbenton

@adamsilverstein If you can link me to your work on core I'm happy to add my voice supporting a fix to the off-by-one bug.

I can double-check my scenario, but you and @Marus make it seem like the issue is off-by-one rather than empty fields.

citelao avatar Feb 07 '17 18:02 citelao

I think this should be fixed in PR #28.

Since the meta values of the revision got selected with the $single parameter set to true (get_post_meta( $revision_id, $meta_key, true );) the add_post_meta( $post_id, $meta_key, $meta_value ); below was never called.

tschortsch avatar Feb 27 '17 13:02 tschortsch

The off by one issue is can be corrected this by hooking your meta save on 'save_post' instead of 'save_post_{post_type}` (you can bail early in the callback to only handle your CPT).

adamsilverstein avatar Dec 01 '17 22:12 adamsilverstein

@Marus @sarahovenall ^^

adamsilverstein avatar Dec 01 '17 23:12 adamsilverstein

for a workaround to the off by one issue, see this comment: https://github.com/adamsilverstein/wp-post-meta-revisions/issues/17#issuecomment-282719776

adamsilverstein avatar Feb 02 '18 16:02 adamsilverstein