Elasticpress: New hook 'ep_prepare_meta_allowed_public_keys' would be very helpful

Created on 1 Feb 2018  路  2Comments  路  Source: 10up/ElasticPress

Hi,
When setting public post meta keys to index you have a hook to only exclude keys 'ep_prepare_meta_excluded_public_keys'. I have posts with over 40 postmeta fields and only wish to index a few. A hook allowing which keys to include would be very helpful and to be honest feels less counter-intuitive.
I added my own but obviously would make sense to have it in the core.
Its a simple change that complements the existing exclude hook.
Note i also added a third arg array_keys($meta) which i believe is also v helpful
Thanks for the plugin.

class EP_API


$allowed_public_keys = apply_filters( 'ep_prepare_meta_allowed_public_keys', false, $post, array_keys($meta));


foreach ( $meta as $key => $value ) {

        $allow_index = false;

        if ( is_protected_meta( $key ) ) {

            if ( true === $allowed_protected_keys || in_array( $key, $allowed_protected_keys ) ) {
                $allow_index = true;
            }
        } else {

            //*****************************************************************************
            if ( true === $allowed_public_keys || in_array( $key, $allowed_public_keys ) ) {
                $allow_index = true;
            }
            //*****************************************************************************

            if ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys )  ) {
                $allow_index = true;
            }
        }

        if ( true === $allow_index || apply_filters( 'ep_prepare_meta_whitelist_key', false, $key, $post ) ) {
            $prepared_meta[ $key ] = maybe_unserialize( $value );
        }
    }
enhancement

Most helpful comment

Can someone please write an example of how to use ep_prepare_meta_whitelist_key filter to index some meta keys? I can't figure it out by looking at it.

All 2 comments

Feel free to open a PR.

Can someone please write an example of how to use ep_prepare_meta_whitelist_key filter to index some meta keys? I can't figure it out by looking at it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brunocrosier picture brunocrosier  路  3Comments

keg picture keg  路  4Comments

jakejackson1 picture jakejackson1  路  8Comments

barryceelen picture barryceelen  路  4Comments

j3j5 picture j3j5  路  5Comments