Here’s a new tiny function that will help you run PHP code in WordPress only when you (or other admin-level users) are logged in.
login
How to automatically login a user into WordPress
When developing for WordPress, sometimes you may need to create a PHP script that will automatically login a user so you can enable user functions. The WorpPress function wp_singon() is the perfect solution.