• Resolved cwgservices

    (@cwgservices)


    In your documentation you say ” Also keep in mind that switching to users that have equal roles is disabled. (regular admins to regular admins + super admins to super admins)”

    But that’s exactly what I need to do. My client insists on admin account, but I need to be able to see the site with his data.

    How can I modify this? Would be great if you made it an option in settings.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @cwgservices

    You can give your own user superior rights through a filter!
    See the view_admin_as_superior_admins filter with examples: https://github.com/JoryHogeveen/view-admin-as/wiki/Filters#view_admin_as_superior_admins
    You can add this filter in a simple custom plugin or the functions.php file in your theme.

    Please note that your user needs to be a super admin in a network setup. Also this filter requires you to return a ID only (not the user object).

    Hope this helps, let me know!

    Regards, Jory

    Thread Starter cwgservices

    (@cwgservices)

    It’s not a network setup. I tried this anyway but it did not work. Any suggestions?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Should work the same for a single installation.
    Can you copy/pase the hooked function in here so I can take a look? (GitHub snippet or anything is fine too!)

    Thread Starter cwgservices

    (@cwgservices)

    Sorry, didn’t see your reply. Here’s the code:

    add_filter( ‘view_admin_as_superior_admins’, ‘my_superior_admins’ );
    function my_superior_admins() {
    // Give user ID’s 1 and 2 superior access (future: check superadmin user field)
    return array( 1, 2 );
    }

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @cwgservices

    This should work if your user’s ID is 1 or 2. I’d advice to use the second example and first get the correct user.

    add_filter( 'view_admin_as_superior_admins', 'my_superior_admins' );
    function my_superior_admins() {
    	// Get your user object
    	$user = get_user_by( 'email', 'YOUR EMAIL' );
    	if ( isset( $user->ID ) ) {
    		// Return your user ID
    		return $user->ID;
    	}
    }

    Where you need to replace “YOUR EMAIL” with the email address of your account.

    EDIT:
    Also keep in mind that superior users cannot switch to eachother. In all cases the golden rule is that “equal” users cannot switch to eachother. So I’d advice to only make your own user account a superior admin for this plugin.
    This is a little security workflow I’ve added in there. I might thing about adding an option to disable this for super admins, not sure about the proper way to do this though. It won’t be in the UI since then it won’t serve any purpose anymore. Any ideas are welcome.

    • This reply was modified 9 years, 2 months ago by Jory Hogeveen.
    Thread Starter cwgservices

    (@cwgservices)

    OHHH. I used 1 and 2 because the two permanent admins have those ids, i.e. my client and I… but that means I made him same as me and still can’t see it the way he does. If I keep just mine in this function, that should do it. And if I use the email as you suggest, I can use it on any site. Thanks for clarification…

    My plan had been to have a user meta field, visible only for admins, that I could use to enable / disable ‘switch to any’ capability. That was based on my misunderstanding the way your security worked.

    Thread Starter cwgservices

    (@cwgservices)

    Ok, I made my account a ‘superior’ user and left others alone. Still can’t switch to another admin, only to lower level accounts.

    add_filter( 'view_admin_as_superior_admins', 'my_superior_admins' );
    function my_superior_admins() {
    	// Get your user object
    	$user = get_user_by( 'email', 'cwg@cwgservices.com' );
    	if ( isset( $user->ID ) ) {
    		// Return your user ID
    		return $user->ID;
    	}
    }
    Plugin Author Jory Hogeveen

    (@keraweb)

    Correct! Just adding yourself will do the trick!

    A metafield can in theory be edited through the UI by any admin so won’t do that security trick. Currently I think the superior admin option should be sufficient in most cases. I get that it’s a downside that it needs to be done in code but it’s the only way to prevent anyone from changing it in the WP UI.

    The best way to do this is by creating a new file in the /wp-content/mu-plugins/ directory. There you can create a new file vaa-superior-admin.php where you add this code.
    The mu-plugins are “Must Use plugins” that are loaded at the beginning of WP (even before all other plugins). Also, they cannot be edited anywhere in the WP UI.

    I’ve created a Gist snippet as an example: https://gist.github.com/JoryHogeveen/256292fc4bf87d69c0ba5ca473a61eee

    Regards, Jory

    • This reply was modified 9 years, 2 months ago by Jory Hogeveen.
    Plugin Author Jory Hogeveen

    (@keraweb)

    I now see your last comment that it’s not working. Changed resolved back to unresolved.

    Where did you place the code? In your theme functions?

    Plugin Author Jory Hogeveen

    (@keraweb)

    After some testing it seems you found a bug in here for single installations.
    Since the next release is 99% ready I’ve patched it and will release 1.7.2 as soon as possible.

    If you are interrested (and comfortable) to test, see here:
    https://github.com/JoryHogeveen/view-admin-as/pull/54/commits/0887ac06120d4abdb0fc849f96440ee6c1864e94

    Thank you for your bugreport!

    Plugin Author Jory Hogeveen

    (@keraweb)

    I’ve updated the dev (trunk) version on WP to the latest version (RC4):
    https://plugins.svn.wordpress.org/view-admin-as/trunk/

    Thread Starter cwgservices

    (@cwgservices)

    Wow thank you for all the work to solve my bug! I’m glad to know it wasn’t something I did… I’ll install new version shortly. Probably won’t report result here till morning. Thanks again

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @cwgservices

    I’m planning on releasing 1.7.2 tonight, did you manage to test to latest version from trunk?
    Thanks and let me know!

    Plugin Author Jory Hogeveen

    (@keraweb)

    1.7.2 is live!

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @cwgservices,

    I assume your issue is now fixed so I will close this topic. If not, feel free to reopen or start a new topic.

    Regards, Jory

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

The topic ‘Need to switch to another admin’ is closed to new replies.