• Resolved Necrid

    (@necrid)


    Hi, I am having an issue where the Admin role of the site has multiple roles attached to it also, (so the admin can see data that is specifically only shown to those roles exclusively). When disabling a menu item for one of the lesser roles, it is also removing it from the administrator account because the role is attached to it there also. This was on a standard install, no alterations made other than disabling the menu items on the lesser roles.

    https://ww.wp.xz.cn/plugins/adminimize/

Viewing 15 replies - 1 through 15 (of 28 total)
  • Plugin Contributor Frank Bueltge

    (@bueltge)

    How do you create the multiple roles? The wp default use always one role for each user.

    Thread Starter Necrid

    (@necrid)

    I think it was WordPress 4 or maybe 4.1 that changed the capabilities of roles. Previously, there was only one role, and you had to edit the capabilities to include capabilities from other roles. The new way, simply assigns multiple roles to a user. – To do this, simply edit the user. and scroll down to where it says “Other Roles” which is a dropdown, and you can choose to associate multiple roles to the user. – I created the additional roles with “User Role Editor”, but this also works with the regular roles of contributor, editor, etc.

    Thread Starter Necrid

    (@necrid)

    Seems like your pplugin is doing something like… if $user (can ‘role’) (hide “menu item”)…. so, as an Admin with role 1, 2 and role 3 attached, the code is ignoreing that i (can ‘admin’) but hides it because I (can “role1”) and i (can “role2”) so it’s still hiding the items…. (((this is just my layman’s understanding/guess as to what’s happening))

    Plugin Contributor Frank Bueltge

    (@bueltge)

    Now, I see it. Currently not tested on my side. But yes, I check the role, there have the user and check the settings from Adminimize. I think at first, I use shure the first role, if is an array and check for this topic.
    I will debug this to create an idea.

    edit: it is a array with all roles:

    roles: Array[2]
             0: "editor"
             1: "author"

    Thread Starter Necrid

    (@necrid)

    or an alternative fix, would be something that ignore’s admin-level users entirely. – something like…
    If $user (can ‘admin’) (show all menu items)
    if $user (can_not “admin”) [follow through with hiding items by role] …

    (just saw your reply about checking first role, this also would work in theory, so long as the array is listing them in the right order, or going off the main role.)

    Either way, glad I’m not talking nonsense and it’s making sense. Thanks so much for your time and effort on it.

    Thread Starter Necrid

    (@necrid)

    ah, i see your edit. yeah it looks like the array could be limitted to only adjust based on the role in location 0, that would be perfect

    Plugin Contributor Frank Bueltge

    (@bueltge)

    I think I found a way. We should merge all areas, there is hiding via Settings page to an array and check about this. I mean, if the user have multiple roles, then I add all areas, items in one object to loop about this. So has the user all settings from all roles on hinding.

    Thread Starter Necrid

    (@necrid)

    Glad you found a fix! Should I wait for an update from you, or is this something you are asking me to do on my end? If so, what exactly do I need to do?

    Plugin Contributor Frank Bueltge

    (@bueltge)

    You can test šŸ˜‰
    I have build a version for this topic, but currently only on “Global Options” and “Menu Options” – Download here:https://github.com/bueltge/Adminimize/archive/master.zip

    I like the other areas later, next timeframe for development.
    Thanks for your test-feedback.

    Thread Starter Necrid

    (@necrid)

    I gave it a small test. I went to the “Menu Options” options, and disabled “Tools” for all but the admin. Upon refreshing the page, I also lost the tools menu. Sorry!

    Thread Starter Necrid

    (@necrid)

    I took a look at the code. (I am not an expert in this, but I “dabble” in edits.) It appears that the code that should seperate it is,

    foreach ( $user_roles as $role ) {
    if ( $role !== ‘administrator’ ) { // only admin disable items
    $disabled_subitem_adm = ”;
    $disabled_subitem_adm_hint = ”;
    echo ‘<td class=”num”>’ ……..

    I think the issue with this, is that my role does not equal ‘administrator’ exactly, it’s technically something like ‘administrator, role1, role2, role3’ so I don’t think it’s triggering on your ‘does_not_equal (!==)’ command. Is there a way to say ‘does not include’ instead?

    Thread Starter Necrid

    (@necrid)

    I’m thinking the solution lies in the “in_array” function – here is an example:
    $os = array(“Mac”, “NT”, “Irix”, “Linux”);
    if (in_array(“Irix”, $os)) {
    echo “Got Irix”;
    }
    if (in_array(“mac”, $os)) {
    echo “Got mac”;
    }
    …………..
    if you know how to use that instead to see if ‘administrator’ is in the role array, to hide only the items checked in the admin row.

    This could also lead to a baseline fix for all, where your comparing the items for the roles, and hiding only the items that are consistantly hidden accross the full array of roles for that user.

    Plugin Contributor Frank Bueltge

    (@bueltge)

    I think that is not the right approach.

    If a user have two roles, like Administrator and editor, then we should add all settings from each role to one role on hide objects.
    As example:
    On the Admin role, we hide tools.php and index.php.
    On the Editor role, we remove settings.php.

    Now the user with two roles logged in, then we should remove this three items: tools.php, index.php and settings.php.

    If not, please clear your goal for me, that I understand it.

    Thread Starter Necrid

    (@necrid)

    would this work?

    foreach ( $user_roles as $role ) {
    if (in_array(“administrator”, $role)) { // only admin disable items
    $disabled_subitem_adm = ”;
    $disabled_subitem_adm_hint = ”;
    }
    echo ‘<td class=”num”>’ ……

    Thread Starter Necrid

    (@necrid)

    Actually, it’s the opposite –
    Using something close to your example:
    On the Admin role, we hide tools.php and index.php.
    On the Editor role, we hide settings.php, and tools.php.

    Now the single user with two roles logged in, they should only have tools.php hidden, since their roles can see the other options. (their ‘editor’ part can see index.php; their ‘admin’ part can see settings.php; so, as a user with both, they should still see these options.)
    While “editor-only” users would have both settings.php and tools.php hidden, because they do not have another role that would otherwise show them the item. And “Admin Only” users would have tools and index hiddden.

    Basically: Hide the item, unless they have another role that does not hide the item

    Please let me know if that doesn’t clear it up.

Viewing 15 replies - 1 through 15 (of 28 total)

The topic ‘Hiding items for Admin when the Admin has multiple roles.’ is closed to new replies.