Example #1
0
 private function __construct()
 {
     // Determine with the user ID if the user is logged in.
     self::$userID = get_current_user_id();
     // Generate link for mark all forums read.
     self::$markAllReadLink = esc_url(add_query_arg(array('view' => 'markallread'), get_permalink()));
     // Initialize data. For guests we use a cookie as source, otherwise use database.
     if (self::$userID) {
         // Create database entry when it does not exist.
         if (!get_user_meta(self::$userID, 'asgarosforum_unread_cleared', true)) {
             add_user_meta(self::$userID, 'asgarosforum_unread_cleared', '0000-00-00 00:00:00');
         }
         // Get IDs of excluded topics.
         self::$excludedItems = get_user_meta(self::$userID, 'asgarosforum_unread_exclude', true);
     } else {
         // Create a cookie when it does not exist.
         if (!isset($_COOKIE['asgarosforum_unread_cleared'])) {
             // There is no cookie set so basically the forum has never been visited.
             setcookie('asgarosforum_unread_cleared', '0000-00-00 00:00:00', 2147483647);
         }
         // Get IDs of excluded topics.
         if (isset($_COOKIE['asgarosforum_unread_exclude'])) {
             self::$excludedItems = maybe_unserialize($_COOKIE['asgarosforum_unread_exclude']);
         }
     }
 }