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

Support non-unique meta key in autosave #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

grappler
Copy link

@grappler grappler commented Sep 23, 2021

Problem

#60

Solution

Pete mention in #24 that a filter to modify the metadata from the $_POST variable.

I looked at the PR #25 but soon realised this would not be a solution for this problem as add_metadata() needs to called multiple times for each non-unique meta data.

In addition there is a check if the data has been changed. get_post_meta() is setup to get only a single value, the first value which does not work for non-unique meta values.

get_post_meta( $new_autosave['ID'], $meta_key, true ) !== wp_unslash( $posted_data[ $meta_key ] )

In WP 4.9.8 register_post_meta() was introduced. This allows developers to register meta key as non-unique and allows us to use the data to save the data correctly. This is how I have done it in the test:

register_post_meta( '', 'meta_revision_test', [ 'single' => false ] );

I have added tests for autosaving both unique and non-unique meta data.

@@ -16,7 +16,7 @@ The goal of releasing this code as a plugin is to allow as many people as possib

Further development of the code for this plugin will continue on its <a href="https://github.com/adamsilverstein/wp-post-meta-revisions">GitHub repository</a>. Pull requests welcome!

To use this plugin, you must be running WordPress 4.1 or newer, two hooks were added in 4.1 that are required for this implementation.
To use this plugin, you must be running WordPress 4.9.8 or newer, a function were added in 4.9.8 that are required for this implementation.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To use this plugin, you must be running WordPress 4.9.8 or newer, a function were added in 4.9.8 that are required for this implementation.
To use this plugin, you must be running WordPress 4.9.8 or newer, a function was added in 4.9.8 that is required for this implementation.

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

Successfully merging this pull request may close these issues.

1 participant