[wp-hackers] problem with wp_signon

Otto otto at ottodestruct.com
Sun May 4 19:39:31 UTC 2014


This isn't really a bug. I think you're just using the wrong function for
your purpose.

The purpose of calling wp_signon is to validate credentials and then send
back appropriate authentication cookies to the visitor's browser. It
doesn't set the current user because it doesn't have to do that. Setting
the current user in wp_signon would serve no real purpose at this point in
the code.

The thing is, you don't need a username or password or anything else to set
the current user. Just call wp_set_current_user with the user's ID, and
bam, you're that user.

In your _my_user_login function, you call wp_signon totally unnecessarily.
You can just take the ID you got from the user you created in the function
before that and simple set the current user to that ID. The only thing
calling wp_signon will do here is send the auth cookie back to the browser.

-Otto



On Sun, May 4, 2014 at 5:30 AM, Guus (IFS) <guus at inspiration-for-success.com
> wrote:

> Thanks for your reply. Tried that and didn't work. I just found myself
> it's a bug in is_user_logged_in().
>
> Nicest work around I found is to call set_current_user() just after the
> wp_signon(), of course if the user was really logged in. Answer is here:
> http://blog.rhysgoodwin.com/programming/wordpress-wp_
> signon-current_user-is-not-populated/.
>
> I guess it's time for the Wordpress team to fix that bug as it took me
> hours and hours to figure this out. Didn't expect this type of bug in
> Wordpress.
>
> Guys,  please fix.
>
> -----Original Message----- From: Nikola Nikolov
> Sent: Sunday, May 04, 2014 4:31 PM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] problem with wp_signon
>
>
> I think the cookies are not set on the first load - so you'd have to
> redirect them in order for WordPress to detect that the user is actually
> logged-in.
>
> I could be wrong though, so if someone else has a clue...
>
>
> On Sun, May 4, 2014 at 11:18 AM, Guus (IFS) <
> guus at inspiration-for-success.com> wrote:
>
>  Hi,
>>
>> I am having a problem signing a user in with wp_signon. When calling it
>> (before the headers have been sent) the first time the user appears not to
>> be logged in when using is_user_logged_in. When going to another page the
>> user is signed in however. Only the first page opened tells the users is
>> signed in, which apparently somehow is the case.
>>
>> Please advise,
>>
>> Guus
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>>  _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list