Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta revisions revert to empty fields #21

Open
citelao opened this issue May 28, 2016 · 10 comments
Open

Meta revisions revert to empty fields #21

citelao opened this issue May 28, 2016 · 10 comments

Comments

@citelao
Copy link

citelao commented May 28, 2016

  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.
@Marus
Copy link

Marus commented Jun 21, 2016

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?

@davidbenton
Copy link

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

@sarahovenall
Copy link

sarahovenall commented Sep 9, 2016

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

@adamsilverstein
Copy link
Owner

@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.

@davidbenton
Copy link

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.

@citelao
Copy link
Author

citelao commented Feb 7, 2017

@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.

@tschortsch
Copy link

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.

@adamsilverstein
Copy link
Owner

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
Copy link
Owner

@Marus @sarahovenall ^^

@adamsilverstein
Copy link
Owner

for a workaround to the off by one issue, see this comment: #17 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants