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

Adds array of meta keys that should be handled as single/not serialized.

Open krilor opened this issue 7 years ago • 5 comments

Hey Adam

Love the plugin! It does exactly what I want it to do :)

But I plan on doing meta queries on the revisions. To be able to do that, I need the keys to be stored as single values (and not serialized arrays) the the db table.

I've taken a stab at forcing certain keys to be single. It's basically an array and a filter just like the list of keys to store revisions for.

Use:

function add_meta_keys_to_revision( $keys ) {
	$keys[] = 'meta-key-to-revision';
	return $keys;
}
add_filter( 'wp_post_revision_meta_keys', 'add_meta_keys_to_revision' );
add_filter( 'wp_post_revision_single_meta_keys', 'add_meta_keys_to_revision' );

Single meta keys has to be a subset of meta keys.

Should be backwards compatible.

krilor avatar Jul 15 '17 08:07 krilor

Hi @krilor Thanks for the PR and apologies for the delay in responding. I agree it would be great to store single values as single values so they are queryable. While a whitelist would work, is there any way we can automate this/eg determine single vs array or multiple programmatically? Also, can we add some unit tests to verify this behavior.

adamsilverstein avatar Dec 01 '17 22:12 adamsilverstein

@krilor I tried testing for this by adding the test key as a single via the filter -

https://github.com/adamsilverstein/wp-post-meta-revisions/commit/5278f130cb19e39765c4919f0aa53de43a45b97e

one of the existing unit tests failed: https://travis-ci.org/adamsilverstein/wp-post-meta-revisions/jobs/311869964

Can you take a look?

adamsilverstein avatar Dec 05 '17 14:12 adamsilverstein

Thanks for replying. I agree that it maybe would be best to programmatically determine single vs array. I'll have a look at that, and at unit tests. I'll see what I can do over the weekend.

krilor avatar Dec 08 '17 05:12 krilor

Great, thanks! Finally getting back to work on this plugin after a long break. See this related PR - https://github.com/adamsilverstein/wp-post-meta-revisions/pull/27

adamsilverstein avatar Dec 08 '17 15:12 adamsilverstein

@krilor - I resolved some merge conflicts, still needs tests.

adamsilverstein avatar Mar 15 '19 15:03 adamsilverstein