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

Allow for whitelisting/blacklisting keys #19

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

Conversation

ivankruchkoff
Copy link

Allow for whitelisting / blacklisting of meta keys e.g. blacklisting:

add_filter( 'wp_post_revision_meta_keys', function( $keys ) {
return array_diff( $keys, array(
'foo',
'bar',
'_edit_last',
'_edit_lock',
'_encloseme',
'_pingme',
)});

This is a breaking change as previously the filter had array() passed to it.

To continue with the whitelisting approach is as simple as:
add_filter( 'wp_post_revision_meta_keys', function( $keys ) {
return array( 'foo', 'bar' );
)});

Also, now we prevent creating revisions for meta that doesn't exist. Previously, we'd save the result of get_post_meta( $post_id, $meta_key ) which would be the empty string.

@adamsilverstein
Copy link
Owner

adamsilverstein commented Apr 27, 2016

@ivankruchkoff Thanks for this PR!

The checks for empty meta seem useful, I want to test with empty meta and make sure the unit tests account for that as well.

Regarding the blacklist/whitelist approach - in my original version i had complicated code that tracked which meta fields where revisioned for each revision - I like how your code does something similar to that by checking which meta keys were actually stored against the revision.

I also like how you turned the existing filter into a white/blacklist by passing the existing meta, however one of the big concerns for core is potential db bloat.

The idea of a pure whitelist approach is we only revision meta by request so there is no additional db use unless you explicitly revision some meta. This change appears to revision all meta by default. Still: I can see the use case for revisioning all meta and using a blacklist to exclude certain fields so it would be good to make that easier/possible.

I'm open to suggestions for the best approach here, ideally something with the flexibility of a single filter as you propose, with the default being no meta is revisioned. Perhaps a theme setting or separate filter that is used to turn on revisioning of ALL meta (without this the existing empty array would be the default)?

@ivankruchkoff
Copy link
Author

My concern with the approach for whitelist/blacklist as two separate actions is that you will run into usecases of priority for each, that is:
whitelist everything in whitelist except for those items in the blacklist
blacklist everything in blacklist except for those items in the whitelist

That implies either mandating one approach over the other, or three filters whitelist1, blacklist, whitelist2 which allows for both examples above.

The alternative with one filter is that it's up to the plugin user to decide what is whitelist and blacklisted and which list takes precedence.

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.

2 participants