admin管理员组

文章数量:1332890

In WordPress, is there anything on a server that may inhibit wp_set_auth_cookie() and/or is_user_logged_in() from working correctly?

I've had this functionality working for a while, until today. No code changes in this area. Possible server settings? The functionality still works on my dev server at home, but not the live hosted server.

Code snippet hooked to 'init' after some logic which sets the $uid:

wp_clear_auth_cookie();
wp_set_auth_cookie( $uid, false, true );
wp_set_current_user( $uid );

I then redirect to a page where user can confirm if they're on a trusted device: wp_safe_redirect( $redirect_url );

In the main part of the page (called via shortcode), the following logic then fails:

if ( ! is_user_logged_in() ) {
    return '<p>You must be logged in to view this page.</p>';
}

While this used to work fine, it doesn't work now. It continues to work fine on my home dev server.

Is it possible there is some server setting now interfering?

In WordPress, is there anything on a server that may inhibit wp_set_auth_cookie() and/or is_user_logged_in() from working correctly?

I've had this functionality working for a while, until today. No code changes in this area. Possible server settings? The functionality still works on my dev server at home, but not the live hosted server.

Code snippet hooked to 'init' after some logic which sets the $uid:

wp_clear_auth_cookie();
wp_set_auth_cookie( $uid, false, true );
wp_set_current_user( $uid );

I then redirect to a page where user can confirm if they're on a trusted device: wp_safe_redirect( $redirect_url );

In the main part of the page (called via shortcode), the following logic then fails:

if ( ! is_user_logged_in() ) {
    return '<p>You must be logged in to view this page.</p>';
}

While this used to work fine, it doesn't work now. It continues to work fine on my home dev server.

Is it possible there is some server setting now interfering?

Share Improve this question asked Nov 21, 2024 at 2:47 gazergazer 214 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It looks like this was a cookie issue on my browsers.

Clearing cookies and caches on my troublesome browsers helped this to work as expected.

本文标签: Wordpress server preventing wpsetauthcookie() from working correctlyStack Overflow