• Resolved Mark Wilkinson

    (@wpmarkuk)


    This is a great plugin and a real time saver when it comes to switching to other users to check how they are seeing things.

    This is perhaps more of a feature request or to get a little help to get me started with this.

    What would be really good would be to have a “Switch To” link in the WordPress admin bar (for Admins and Super Admins only) and when you hover it, it lists all the users, clicking one then switches to that user.

    I am comfortable with creating the admin bar list etc. but how would I go about getting the URL for each user to switch to that user? I notice on the admin pages where it lists users the URL takes the form of:

    http://yourdomain.com/wp-login.php?action=switch_to_user&user_id=10&_wpnonce=891df8af7e

    It is the &_wpnonce=891df8af7e part that I would need help generating.

    Would be delighted if someone could assist me with this and thanks in anticipation.

    http://wordpress.org/extend/plugins/user-switching/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Mark Wilkinson

    (@wpmarkuk)

    The plugin below handles all of the admin bar list of users etc and the URL to link to switch except the _wpnonce at the end:

    https://gist.github.com/wpmark/5007195

    Anyone any ideas how to get the wpnonce on the end of those URLs?

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Rather than constructing the URL yourself the best way to do it would be to use the switch_to_url() method in User Switching.

    $pxjn_full_menu_url = $user_switching->switch_to_url( $pxjn_user->ID );

    You’ll need to import the $user_switching global into your function’s scope by putting this at the top of the pxjn_user_switching_adminbar() function:

    global $user_switching;

    See how that goes.

    John

    Thread Starter Mark Wilkinson

    (@wpmarkuk)

    Excellent thanks for that – it works a treat. I thought there would be an easier way, it was just getting to know how the plugin did this.

    Thanks again.

    My amended plugin is now here:

    https://gist.github.com/wpmark/5007195

    wpmarkuk,

    does this code allow you to switch the user from the admin bar (upper right) instead of from the user page?

    What’s the overall additional overhead added to WordPress – will it impact the performance from the customer side?

    Thread Starter Mark Wilkinson

    (@wpmarkuk)

    Yes that is correct it does as you have described. I have not noticed any performance loss but only really tested it with max 10 users on a site.

    There is also a github repo for this now too:

    https://github.com/wpmark/admin-bar-user-switching

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘User Switching from Admin Bar’ is closed to new replies.