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;
and some fields you’d need to research and probably us custom javascript. I don’t begin to know how to do this with the select2 fields.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.