Automatic login
-
I was looking for a way to login automatically and found this piece of code that I adjusted to suit my needs.
I wanted to be able to login as admin via an URL (mostly to be able to easily run upgrades of all my sites). But the code I found would login every visitor as admin – NOT what I was looking for… So I changed it slightly to be more secure:
Insert the following to your functions.php
function auto_login() { if (!is_user_logged_in()) { $user_login = $_GET['YOUR-OWN-SECRET-KEY']; $user = get_userdatabylogin($user_login); $user_id = $user->ID; wp_set_current_user($user_id, $user_login); wp_set_auth_cookie($user_id); do_action('wp_login', $user_login); } } add_action('init', 'auto_login');
Change YOUR-OWN-SECRET-KEY to something that’s not easy to find out, any password creator would help you with this.
Then just make a list of URLs to suit your needs. To go to WP-admin upgrade page, URL looks like:
https://www.domain.com/wp-admin/update-core.php?YOUR-OWN-SECRET-KEY=admin
That is if your admin account login is ‘admin’ (I suggest you change this due to security!)Now I need to find out how to actually start the upgrade via an URL – but maybe someone else knows how to make that happen…?
Tried adding action=do-core-upgrade, but failed…
- The topic ‘Automatic login’ is closed to new replies.