adamsilverstein / wp-post-meta-revisions

plugin for https://core.trac.wordpress.org/ticket/20564
GNU General Public License v2.0
86 stars 32 forks source link

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

Open krilor opened 7 years ago

krilor commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

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

krilor commented 6 years ago

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 commented 6 years ago

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 commented 5 years ago

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