cookies = $cookies; } /** * @return bool */ public function is_empty() { return count( $this->cookies ) === 0; } /** * @param string $name * * @return bool */ public function has_cookie( $name ) { return isset( $this->cookies[ $name ] ); } /** * @param string $name * @param string $value * @param int $lifespan Time in seconds the cookie exists. * @param bool $http_only * * @return bool */ public function set_cookie( $name, $value, $lifespan, $http_only = false ) { $expire = time() + $lifespan; return setcookie( $name, $value, $expire, '/', '', false, $http_only ); } /** * @param string $name * * @return array|string */ public function get_cookie( $name ) { if ( $this->has_cookie( $name ) ) { return $this->cookies[ $name ]; } return ''; } /** * @return array */ public function get_cookies() { return $this->cookies; } /** * @param string $name */ public function delete_cookie( $name ) { $this->set_cookie( $name, '', -3600 ); if ( $this->has_cookie( $name ) ) { unset( $_COOKIE[ $name ] ); } } public function delete_wp_cookies() { foreach ( $this->wp_cookies as $cookie ) { foreach ( $_COOKIE as $cookie_name => $cookie_value ) { if ( strpos( $cookie_name, $cookie ) !== false ) { $this->delete_cookie( $cookie_name ); } } } } }