A while ago I released a the Admin Bar User Swtiching plugin which was a dependancy of John Blackbourn‘s excellent User Switching plugin. After some community feedback I needed to make some changes. Therefore I am pleased to release version 1.0.
A number of users left feedback and support requests on the WordPress.org support forums. The main issue, which I actually already knew about and stated in the plugin readme.txt file was that the plugin was potentially quite resource hungry.
In order to build the “Switch to” links in the admin bar the plugin was querying all the sites users on every page load which was OK for sites with a low number of users but not great for sites with hundreds or even thousands of users. Therefore some changes needed to be made.
One support forum post outlined the following:
Had to manually remove Plugin as it consumed all available memory and killed the frontend & WP Admin. Consider adding an AJAX search instead of full hover list (site has 80,000+ users) 🙂
Therefore I had to go about solving this issue and started down the path suggested by the commenter. This was interesting for me and I had not really used the WordPress AJAX method before and therefore found it very interesting.
Anyway after about 3 – 4 hours of Dev time IÂ finally have version 1.0 of the Admin Bar User Switching plugin which, instead of listing all users in the admin bar dropdown, displays a search box so users can type a username (including the use of a wildcard). On submitting this search a list of users is presented and when clicked you are switched to that user.
The benefit here is that no queries are being run on every page load, only when a user runs a search for a specific user.
I hope this brings significant performance benefits to the plugin and allows sites with many users to take advantage of the plugin.
Leave a Reply