Home › Forums › Backend Issues (wp-admin) › Set fields to readonly based on user-role in wp-admin › Reply To: Set fields to readonly based on user-role in wp-admin
It is not possible to set every field type in ACF to read only, at least I’m pretty sure that it’s not possible. It really depends on the type of field it is. The fields types that use Select2 are the most problematic.
If it can be done you would do this using a prepare field filter on each field https://www.advancedcustomfields.com/resources/acf-prepare_field/. In this filter you would need to see if the post is a new post of not (post_type = “auto-draft”) and then you’d need to check the user role. Depending on these, some of the fields can be set to read only by
$field['readonly'] = 1;
Some fields you’d need to use the disabled propery
$field['disabled'] = 1;
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.