activation-tracker.php
1 week ago
display-options.php
1 week ago
field-type-settings.php
1 week ago
field.php
1 week ago
filed-validation.php
1 week ago
myaccount-edit-address.php
1 week ago
myaccount-field-processor.php
1 week ago
plugin.php
1 week ago
settings.php
1 week ago
tracker.php
1 week ago
user-meta-checkout.php
1 week ago
user-meta.php
1 week ago
user-profile.php
1 week ago
activation-tracker.php
67 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } // Exit if accessed directly |
| 5 | |
| 6 | class Flexible_Checkout_Fields_Activation_Tracker { |
| 7 | |
| 8 | /** @var string */ |
| 9 | private $namespace; |
| 10 | |
| 11 | /** |
| 12 | * Flexible_Checkout_Fields_Activation_Tracker constructor. |
| 13 | * |
| 14 | * @param $namespace string for settings |
| 15 | */ |
| 16 | public function __construct( $namespace ) { |
| 17 | $this->namespace = $namespace; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Option name for date storage |
| 22 | * |
| 23 | * @return string |
| 24 | */ |
| 25 | private function get_option_name_activation_date() { |
| 26 | return $this->namespace . '_activation'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Returns activation date and sets it if were not set before |
| 31 | * |
| 32 | * @return int unix timestamp for activation datetime |
| 33 | */ |
| 34 | public function get_activation_date() { |
| 35 | $activation_date |
| 36 | = get_option( $this->get_option_name_activation_date() ); |
| 37 | if ( empty( $activation_date ) ) { |
| 38 | return $this->touch_activation_date(); |
| 39 | } |
| 40 | |
| 41 | return intval( $activation_date ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Was activation more than two weeks before today |
| 46 | * |
| 47 | * @return bool |
| 48 | */ |
| 49 | public function is_activated_more_than_two_weeks() { |
| 50 | $two_weeks = 60 * 60 * 24 * 7 * 2; |
| 51 | |
| 52 | return $this->get_activation_date() + $two_weeks < time(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Sets activatiion date for today |
| 57 | * |
| 58 | * @return int unit timestamp for now |
| 59 | */ |
| 60 | public function touch_activation_date() { |
| 61 | $now = time(); |
| 62 | update_option( $this->get_option_name_activation_date(), $now ); |
| 63 | |
| 64 | return $now; |
| 65 | } |
| 66 | } |
| 67 |