PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 1.2.2
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v1.2.2
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / class-hurrytimer-evergreen.php

class-hurrytimer-evergreen.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 1.2.2, at includes/class-hurrytimer-evergreen.php

59 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer;
4
5 class Evergreen_Countdown
6 {
7 public $cookie_detection;
8 public $ip_detection;
9
10 public function __construct()
11 {
12 $this->cookie_detection = new Cookie_Detection();
13 $this->ip_detection = new IP_Detection();
14 }
15
16 public function reset($countdown_id)
17 {
18 $this->ip_detection->forget($countdown_id);
19 update_post_meta($countdown_id, '_hurrytimer_reset_countdown', 1);
20 }
21
22 public function expires_at($countdown_id)
23 {
24 // Get expire timestamp if cookie exists.
25 $client_expires_at = $this->cookie_detection->find($countdown_id);
26
27 // If cookie is not created or deleted.
28 if (is_null($client_expires_at)) {
29
30 // Fallback to IP detection
31 $result = $this->ip_detection->find($countdown_id);
32
33 if ($result) {
34
35 // Return IP `client_expires_at`.
36 return $result['client_expires_at'];
37 }
38
39 // A new cookie will be created from client side
40 // containing the expiration timestamp.
41 return null;
42 }
43
44 $result = $this->ip_detection->find($countdown_id);
45
46 if ($result) {
47
48 // Update IP expiration timestamp.
49 $this->ip_detection->update($result['id'], $client_expires_at);
50 } else {
51
52 // We create an IP entry.
53 $this->ip_detection->create($countdown_id, $client_expires_at);
54 }
55
56 return $client_expires_at;
57 }
58 }
59