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

Filtering of option fields #40

Open
jasonagnew opened this issue Feb 1, 2016 · 0 comments
Open

Filtering of option fields #40

jasonagnew opened this issue Feb 1, 2016 · 0 comments

Comments

@jasonagnew
Copy link

Great work on the plugin. I was wondering if it would be worth having a way to filter the option fields, like you do with the standard rest_prepare_x. Maybe adding the filter to addACFOptionRouteV2cb

return apply_filters( 'rest_prepare_acf_options', $request, $fields, $option );

Allowing you to do:

function remove_private_options($request, $fields, $option) {

    $private_prefix = '_private_';

    if ( substr($option, 0, strlen($private_prefix) ) === $private_prefix )
    {
        return false;
    }

    foreach($fields as $name => $value)
    {
        if ( substr($name, 0, strlen($private_prefix) ) === $private_prefix )
        {
            unset($fields[$name]);
        }
    }

    return $fields;
}

Above is an example of removing any field in the options with a prefix of _private_

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

No branches or pull requests

1 participant