WordPress.org

Ready to get started?Download WordPress

Forums

User Switching
[resolved] User Switching from Admin Bar (6 posts)

  1. Mark Wilkinson
    Member
    Posted 1 year ago #

    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/

  2. Mark Wilkinson
    Member
    Posted 1 year ago #

    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?

  3. John Blackbourn
    Member
    Plugin Author

    Posted 1 year ago #

    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

  4. Mark Wilkinson
    Member
    Posted 1 year ago #

    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

  5. dreamgrowers
    Member
    Posted 9 months ago #

    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?

  6. Mark Wilkinson
    Member
    Posted 9 months ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic