Field visibility – REST API

[ad_1]

Hi,

Is there a way, on a field by field basis, to enable/disable the REST API read capibility based on if the user is logged in or not?

I know i can check “Read via REST API” under the REST API setting on a field by field basis. But doing so makes it visible to anyone even if checking “Restrict access to Logged In Users” it will still show the field in the JSON-response found at /wp-json/wp/v2/sampleposttype even if logged out.

Or is there a filter that i can use to enable/disable some rest fields based on if user is logged in or not?

Let’s say enable the rest api read capibility on the fields phone and email for a certain post type if logged in else disable.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer