Hi everybody,
I’m using ACF PRO and I’m trying to disable a field group for specific userid.
I’m using the prepare_field filter to hook into this. My code works if I’m using this whit a fieldkey but not with a group.
// key=group_… // doesn’t get trigged
// key=field_… // works
I do have a lot of field inside this group, is there a better way to achieve this?
function ial_enable_acf_office_site( $field ) {
$currentUserId = get_current_user_id();
$user = wp_get_current_user();
$allowed_roles = array( ‘editor’, ‘administrator’ );
$userEnabled = array(
15 // list of user id enabled
);
// Always enable for editor and admin
if ( array_intersect( $allowed_roles, $user->roles ) || in_array($currentUserId, $userEnabled) ) {
return $field;
}else{
return false; //hide the field
}
}
add_filter(‘acf/prepare_field/key=group_62b5e82341764’, ‘ial_enable_acf_office_site’);
Thanks in advance
You cannot use acf/prepare_field for entire field groups. Only individual fields.
You use location rules to hide field groups for specific user roles.