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 Answer 1

2

You need wp_set_auth_cookie:

wp_set_auth_cookie( $user_id, ( bool ) $remember );
3
  • It is safe? I don't see any password validation or hash parring. Basically it bypass all verification done in normal login. May 1, 2016 at 9:59
  • 1
    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. May 1, 2016 at 10:00
  • Perfect solution. Aug 22, 2017 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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