User Switching from The WordPress Admin Bar

Recently I have been working on a number of multisite installs of WordPress. The largest of these has been for a multisite install that is being used as an Intranet in a corporate environment. To help see the site from other users’ perspective I have been using the excellent User Switching plugin by John Blackbourn. However much of the switching I wanted was from the front end. This post looks at how I solved this problem.

Since WordPress 3.0 (ish) the WordPress admin bar has provided easy access to a lot of the dashboard functions such as writing new posts and pages and moderating comments etc. Along with this came the ability to easily customise the WordPress admin bar, adding your own content to it. With this in mind it seemed the obvious solution was to add User Switching to the admin bar, so that it would be enabled from the front end of the site.

Therefore I went about building a plugin to do this which you can see below:

[gist id=5007195 bump=1]

Initially I had a problem with the plugin in that I could not get the wpnonce working for the switch to user links. However excellent support from the plugin author helped me solve this problems in minutes. Thanks to John for a speedy and precise answer to the query.

The plugin works great, but if you do not have User Switching installed, the plugin checks for this and then does nothing. What I really need is for the plugin to not activate if the User Switching plugin is not installed. If anyone could help me out with this I would be very grateful.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.