简体   繁体   中英

Set a cookie on using wp_login() hook

Im trying to set a cookie when my user logs into WP.

Im using the wp_login hook like so:

add_action('wp_login', array($this, 'knp_aci_login_check'), 1, 2);

And my cookie function:

public function knp_aci_login_check( $user_login, $user ) {
    $contact = $this->request->api_connect('contacts?filters[email]='.$user_login, 'GET');

    if (wp_remote_retrieve_response_code( $contact ) == 200) {
        setcookie('ac-status', 'true', 365 * DAY_IN_SECONDS, '/', get_site_url());
    }
}

My cookie, just never saves.

Have you tried setting the cookie without the condition? Maybe it's not the setcookie, but that if statement is returning false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM