User role issue

Support MB Include Exclude User role issue

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #6151
    woorisewoorise
    Participant

    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',
    ),

    #6158
    Anh TranAnh Tran
    Keymaster

    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'.

    #6160
    woorisewoorise
    Participant

    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.

    #6191
    Anh TranAnh Tran
    Keymaster

    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,
    );
    #6198
    woorisewoorise
    Participant

    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',
    ),

    #6211
    Anh TranAnh Tran
    Keymaster

    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.

    #6213
    woorisewoorise
    Participant

    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.

    #6216
    Anh TranAnh Tran
    Keymaster

    Can you please try download again? I think I uploaded the wrong file.

    #6219
    woorisewoorise
    Participant

    Thank you! Now it's working fine!

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘User role issue’ is closed to new replies.