User role issue
Support › MB Include Exclude › User role issue
- This topic has 8 replies, 2 voices, and was last updated 8 years, 4 months ago by 
woorise.
 
- 
		AuthorPosts
 - 
		
			
				
June 22, 2017 at 11:30 PM #6151
woorise
ParticipantHello,
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',
),June 23, 2017 at 3:15 PM #6158Anh Tran
KeymasterThe
user_roleis the role of the being edited users, not the current users. In this case, if you want to editeditorusers, you need to set'user_role' => 'editor'.June 23, 2017 at 4:06 PM #6160woorise
ParticipantWhat 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.
June 28, 2017 at 8:35 AM #6191Anh Tran
KeymasterHi,
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, );June 28, 2017 at 5:48 PM #6198woorise
ParticipantThank 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',
),June 30, 2017 at 1:34 PM #6211Anh Tran
KeymasterHi,
We probably haven't supported it yet. The
user_roleactually 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.June 30, 2017 at 9:23 PM #6213woorise
ParticipantThank 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.
July 3, 2017 at 7:58 AM #6216Anh Tran
KeymasterCan you please try download again? I think I uploaded the wrong file.
July 3, 2017 at 12:55 PM #6219woorise
ParticipantThank you! Now it's working fine!
 - 
		AuthorPosts
 
- The topic ‘User role issue’ is closed to new replies.