Hello,
Using advanced custom field for a while now but never tried something that is in my head right now and I dont know if it is possible and if yes, how.
I want to create a field that is only visible for users I say can see the field. So for example I have a field (FIELD 1) that normaly is visible for everyone I only want user_name_1, user_name_2 and user_name_3 to see this field when they are logged in.
Is something like this possible and if yes, how.
Any help would be very welcome
Kind regards.
Joep
I managed to get it to work this far:
function my_acf_prepare_field_wordpress( $field ) {
$current_user = wp_get_current_user();
if( $current_user->user_login == "Username" ) {
if( $field['value'] ) {
$field['disabled'] = true;
}
}
return $field;
}
add_filter('acf/prepare_field/name=pakket-of-dienst', 'my_acf_prepare_field_wordpress');
The whole field is disabled with this function but I only need to disable a specific option of this select field.
Is this possible, if yes, could anybody point me in the right direction?
Fixed it with this function:
function my_acf_prepare_field_wordpress( $field ) {
$current_user = wp_get_current_user();
if( $current_user->user_login != "User1" && $current_user->user_login != "User2") {
$choices = $field['choices'];
unset($field['choices']['your-field-option']);
}
return $field;
}
add_filter('acf/prepare_field/name=pakket-of-dienst', 'my_acf_prepare_field_wordpress');