From 84b26d8271ed4580febd4532d7e5dd1c0669ddb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 25 Aug 2021 17:16:49 +0200 Subject: [PATCH] add methods unsetActive user try session timeout --- src/WordPress/WPCrm.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/WordPress/WPCrm.php b/src/WordPress/WPCrm.php index 4d86310..04a71ec 100644 --- a/src/WordPress/WPCrm.php +++ b/src/WordPress/WPCrm.php @@ -360,6 +360,17 @@ class WPCrm return self::$user = new WPCrmUser(); } + /** + * Remove active user + * to prevent WPCrm::check to return true + * + * @return void + */ + public static function unsetActiveUser() + { + self::$user = null; + } + // --- PRIVATE --- METHODS /** @@ -457,6 +468,16 @@ class WPCrm if (!session_id() && !self::$sessionDestroyed) { session_start(); } + if ( + isset($_SESSION[self::$sessionKey]) and + isset($_SESSION['lastActivity']) and + ($_SESSION['lastActivity'] + 120) < time() + ) { + self::$sessionDestroyed = true; + unset($_SESSION[self::$sessionKey]); + } else { + $_SESSION['lastActivity'] = time(); + } if (!self::$user and array_key_exists(self::$sessionKey, $_SESSION)) { /** * The user object