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

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

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

Conversation

krilor
Copy link

@krilor krilor commented Jul 15, 2017

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.

@adamsilverstein
Copy link
Owner

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

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

5278f13

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

Can you take a look?

@krilor
Copy link
Author

krilor commented Dec 8, 2017

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.

@adamsilverstein
Copy link
Owner

Great, thanks! Finally getting back to work on this plugin after a long break. See this related PR - #27

@adamsilverstein
Copy link
Owner

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

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

Successfully merging this pull request may close these issues.

2 participants