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

Support non-unique meta key in autosave

Open grappler opened this issue 4 years ago • 0 comments

Problem

https://github.com/adamsilverstein/wp-post-meta-revisions/issues/60

Solution

Pete mention in https://github.com/adamsilverstein/wp-post-meta-revisions/issues/24 that a filter to modify the metadata from the $_POST variable.

I looked at the PR https://github.com/adamsilverstein/wp-post-meta-revisions/pull/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. https://github.com/adamsilverstein/wp-post-meta-revisions/blob/ca459926808b025c256654962e577c91597dd0e0/wp-post-meta-revisions.php#L88

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.

grappler avatar Sep 23 '21 09:09 grappler