times / acf-to-wp-api

Puts all ACF fields from posts, pages, custom post types, attachments and taxonomy terms, into the WP-API output under the 'acf' key

Home Page:http://wordpress.org/plugins/acf-to-wp-api/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filtering of option fields

jasonagnew opened this issue · comments

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_