WithoutNamespace
2 weeks ago
AbstractPlugin.php
2 weeks ago
Activateable.php
2 weeks ago
ActivationAware.php
2 weeks ago
ActivationTracker.php
2 weeks ago
Conditional.php
2 weeks ago
Deactivateable.php
2 weeks ago
Hookable.php
2 weeks ago
HookableCollection.php
2 weeks ago
HookableParent.php
2 weeks ago
HookablePluginDependant.php
2 weeks ago
PluginAccess.php
2 weeks ago
SlimPlugin.php
2 weeks ago
TemplateLoad.php
2 weeks ago
ActivationTracker.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\PluginBuilder\Plugin; |
| 4 | |
| 5 | /** |
| 6 | * @deprecated nobody uses it :) And also this library is not a place for this class |
| 7 | * |
| 8 | * @package WPDesk\PluginBuilder\Plugin |
| 9 | */ |
| 10 | class ActivationTracker |
| 11 | { |
| 12 | /** |
| 13 | * Namespace. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | private $namespace; |
| 18 | /** |
| 19 | * ActivationTracker constructor. |
| 20 | * |
| 21 | * @param string $namespace Namespace for settings. |
| 22 | */ |
| 23 | public function __construct($namespace) |
| 24 | { |
| 25 | $this->namespace = $namespace; |
| 26 | } |
| 27 | /** |
| 28 | * Option name for date storage |
| 29 | * |
| 30 | * @return string |
| 31 | */ |
| 32 | private function get_option_name_activation_date() |
| 33 | { |
| 34 | return $this->namespace . '_activation'; |
| 35 | } |
| 36 | /** |
| 37 | * Returns activation date and sets it if were not set before |
| 38 | * |
| 39 | * @return int unix timestamp for activation datetime |
| 40 | */ |
| 41 | public function get_activation_date() |
| 42 | { |
| 43 | $activation_date = get_option($this->get_option_name_activation_date()); |
| 44 | if (empty($activation_date)) { |
| 45 | return $this->touch_activation_date(); |
| 46 | } |
| 47 | return intval($activation_date); |
| 48 | } |
| 49 | /** |
| 50 | * Was activation more than two weeks before today |
| 51 | * |
| 52 | * @return bool |
| 53 | */ |
| 54 | public function is_activated_more_than_two_weeks() |
| 55 | { |
| 56 | $two_weeks = 60 * 60 * 24 * 7 * 2; |
| 57 | return $this->get_activation_date() + $two_weeks < time(); |
| 58 | } |
| 59 | /** |
| 60 | * Sets activatiion date for today |
| 61 | * |
| 62 | * @return int unit timestamp for now |
| 63 | */ |
| 64 | public function touch_activation_date() |
| 65 | { |
| 66 | $now = time(); |
| 67 | update_option($this->get_option_name_activation_date(), $now); |
| 68 | return $now; |
| 69 | } |
| 70 | } |
| 71 |