I want to log in automatically to WP admin/dashboard from another site without going thru the login process.. I\'ve tried the following but with no luck:
<
If you have access to the files of the website where you trying to login. You could add a auto login php script and $_POST the username and password to this script, example:
if ($_POST) {
$errors = array();
$username = esc_sql($_REQUEST['username']);
$password = esc_sql($_REQUEST['password']);
$remember = esc_sql($_REQUEST['rememberme']);
$remember = ($remember) ? "true" : "false";
$login_data = array();
$login_data['user_login'] = $username;
$login_data['user_password'] = $password;
$login_data['remember'] = $remember;
$user_verify = wp_signon($login_data, true);
if (is_wp_error($user_verify)) {
$errors[] = 'Invalid username or password. Please try again!';
} else {
wp_set_auth_cookie($user_verify->ID);
wp_redirect(admin_url());
exit;
}
}
Wordpress codex references:
Hope it helps.
Edit: $wpdb->escape is deprecated since Wordpress version 3.6, use wpdb::prepare() or esc_sql() instead! I've changed the code to use esc_sql().