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
I can give you a basic example
add_filter('acf/prepare_field/key=field_123abc456
, ‘maybe_set_readonly’);
function maybe_set_readonly($field) {
// check post type to see if it’s a new post
global $post
$new_post = true
if (get_post_type($post->ID)) != ‘auto-draft’) {
// this is not a new post
$new_post = false;
}
// check current user role
// I really don’t know off the top of my head how to check this
// if conditions are not met to allow editing
// set field to readonly
if (your conditions here) {
$field[‘readonly’] = 1;
}
return $field;
}
`
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.