Support Forum
Support › Meta Box Include Exclude › User role issue
Hello,
I have created some fields using the MB User Meta. I use the following code to restrict some fields from other roles except administrator.
My issue is that when I am logged in as administrator and visit the profile of a non-admin user (custom role) I can't see the field.
'include' => array(
'user_role' => 'administrator',
),
The user_role
is the role of the being edited users, not the current users. In this case, if you want to edit editor
users, you need to set 'user_role' => 'editor'
.
What I want to do is to hide a profile field from a user with custom role "myrole" but administrator will be able to edit that field.
Is that possible?
Thanks.
Hi,
Just realized that you asked about a field, not a meta box. The include / exclude extension works for meta boxes only, not for fields.
So, in this situation, you probably need to use PHP code to check and register a field for a meta box. Something like:
$fields = array(); // Define all your fields here
if ( current_user_can( 'manage_options' ) ) {
$fields[] = array(
'type' => 'text',
'name' => 'Custom field for admin only',
'id' => 'admin_only',
);
}
// Register meta box
$meta_boxes[] = array(
'type' => 'user',
'title' => 'Profile fields',
'fields' => $fields,
);
Thank you for the tip is very useful.
I actually want to hide a meta box (I just have only one field).
I tried the following code in order to make the meta box available only to administrators but administrators can't see the meta box when editing other users profile with role "myrole". Maybe there is a bug here.
'include' => array(
'user_role' => 'administrator',
),
Hi,
We probably haven't supported it yet. The user_role
actually is the role for being edited users. It's not for the current user, who is editing. We'll update the extension to add more condition for the current user.
Thank you for the fast update!
I saw that you have add "edited_user_role" and "edited_user_id" parameter in the 1.0.9 version but when I am trying to update the plugin I get the 1.0.8 version even with manual download.
Can you please try download again? I think I uploaded the wrong file.
Thank you! Now it's working fine!