Support

Account

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;
    }
    `