Home › Forums › Backend Issues (wp-admin) › All role in the User list field
Hi,
For a user that has shop manager role, i need to be display all role and not only customer role in the field User list.
thanks
I don’t have all of the code for this. Basically you need to create an acf/prepare_field filter https://www.advancedcustomfields.com/resources/acf-prepare_field/. In this filter you need to get the current user’s role and then update the field setting for role accordingly.
// to set roles to all
$field['role'] = '';
do you mean simply this ? $field[‘role’] = ‘shop_manager’;
my need is that the user shop manager could see all the role in the list (like admnitrator can see). Actually the list is limited to customers.
thanks
no, something like this, but I have not testing this
add_filter('acf/prepare_field/key=field_XXXXX', 'my_set_role_filter');
function my_set_role_filter($field) {
if (current_user_can('shop_manager')) {
$field['role'] = '';
}
return $field;
}
No, to set the field to show all roles you want that value to be an empty string
thanks unfortunately i have tried with name=_user_id and key=select2-acf-field_5a47128676459 but it still display only customers…
Please see the instructions for the filter. You probably need to use the field key. The field key looks something like field_XXXXXXXXX
yes i did , strange…
i have tried both…
add_filter('acf/prepare_field/key=field_5a47128676459', 'my_set_role_filter');
function my_set_role_filter($field) {
if (current_user_can('shop_manager')) {
$field['role'] = '';
}
return $field;
}
add_filter('acf/prepare_field/key=acf-field_5a47128676459', 'my_set_role_filter');
function my_set_role_filter($field) {
if (current_user_can('shop_manager')) {
$field['role'] = '';
}
return $field;
}
I can see yy with this but unfortunately i only see customer role in the list
add_filter('acf/prepare_field/key=field_5a47128676459', 'my_set_role_filter');
function my_set_role_filter($field) {
print_r ("yy");
if (current_user_can('shop_manager')) {
$field['role'] = '';
}
return $field;
}
I can see yy with this but unfortunately i only see customer role in the list
add_filter(‘acf/prepare_field/key=field_5a47128676459’, ‘my_set_role_filter’);
function my_set_role_filter($field) {
print_r (“yy”);
if (current_user_can(‘shop_manager’)) {
$field[‘role’] = ”;
}
return $field;
}
this is what is returned in $field
Array ( [ID] => 0 [key] => field_5a47128676459 [label] => Utilisateur [name] => acf[field_5a47128676459] [prefix] => acf [type] => user [value] => [menu_order] => 0 [instructions] => [required] => 0 [id] => acf-field_5a47128676459 [class] => [conditional_logic] => 0 [parent] => group_5a471067bee5c [wrapper] => Array ( [width] => [class] => [id] => ) [role] => [allow_null] => 0 [multiple] => 0 [return_format] => id [_name] => _user_id [_valid] => 1 [_prepare] => 1 )
The topic ‘All role in the User list field’ is closed to new replies.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.