Support » Plugin: User Switching » User Switching from Admin Bar

  • Resolved Mark Wilkinson


    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:

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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:

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

    Plugin Author John Blackbourn


    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.


    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:


    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?

    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:

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