0

The problem is that wp_signon function requires password as plain text. Where WP_User object returns user password as hashed.

There is any way to safety login using user WP_User object? Something like this:

$user = new WP_User(1);

wp_signon([
    'user_login' => $user->user_login,
    'user_password' => $user->user_pass,
    'remember' => true,
]);
1

You need wp_set_auth_cookie:

wp_set_auth_cookie( $user_id, ( bool ) $remember );
  • It is safe? I don't see any password validation or hash parring. Basically it bypass all verification done in normal login. – Jędrzej Chałubek May 1 '16 at 9:59
  • Yes because there is nothing to verify - you already have the user ID that you want to log in, it's on you to make sure it's okay to do so. – TheDeadMedic May 1 '16 at 10:00
  • Perfect solution. – Shakeel Ahmed Aug 22 '17 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.