airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 111 forks source link

Filter conflict – show_in_rest overrides other filters? #263

Open evvvritt opened 6 years ago

evvvritt commented 6 years ago

Hi, thanks for developing this plugin.

I'm trying to restrict get_fields for User types to only those that can edit_posts. I have the show_in_rest option enabled, but I think it's overriding the filter I setup below.

// Enable the option show in rest
add_filter( 'acf/rest_api/field_settings/show_in_rest', '__return_true' );

// Restrict get_fields of Users
add_filter( 'acf/rest_api/users/get_fields', function( $data, $request ) {
  if (!current_user_can( 'edit_posts' )) return false;
  return $data;
});

Any help much appreciated.