WC_Session_Handler::init_session_cookie()
Setup cookie and customer ID.
Метод класса: WC_Session_Handler{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$WC_Session_Handler = new WC_Session_Handler(); $WC_Session_Handler->init_session_cookie();
Список изменений
С версии 3.6.0 | Введена. |
Код WC_Session_Handler::init_session_cookie() WC Session Handler::init session cookie WC 8.7.0
public function init_session_cookie() { $cookie = $this->get_session_cookie(); if ( $cookie ) { // Customer ID will be an MD5 hash id this is a guest session. $this->_customer_id = $cookie[0]; $this->_session_expiration = $cookie[1]; $this->_session_expiring = $cookie[2]; $this->_has_cookie = true; $this->_data = $this->get_session_data(); if ( ! $this->is_session_cookie_valid() ) { $this->destroy_session(); $this->set_session_expiration(); } // If the user logs in, update session. if ( is_user_logged_in() && strval( get_current_user_id() ) !== $this->_customer_id ) { $guest_session_id = $this->_customer_id; $this->_customer_id = strval( get_current_user_id() ); $this->_dirty = true; $this->save_data( $guest_session_id ); $this->set_customer_session_cookie( true ); } // Update session if its close to expiring. if ( time() > $this->_session_expiring ) { $this->set_session_expiration(); $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); } } else { $this->set_session_expiration(); $this->_customer_id = $this->generate_customer_id(); $this->_data = $this->get_session_data(); } }