| 1 |
<?php |
| 2 |
namespace Hurrytimer; |
| 3 |
|
| 4 |
/** |
| 5 |
* Fired during plugin activation |
| 6 |
* |
| 7 |
* @link http://nabillemsieh.com |
| 8 |
* @since 1.0.0 |
| 9 |
* |
| 10 |
* @package Hurrytimer |
| 11 |
* @subpackage Hurrytimer/includes |
| 12 |
*/ |
| 13 |
|
| 14 |
/** |
| 15 |
* Fired during plugin activation. |
| 16 |
* |
| 17 |
* This class defines all code necessary to run during the plugin's activation. |
| 18 |
* |
| 19 |
* @since 1.0.0 |
| 20 |
* @package Hurrytimer |
| 21 |
* @subpackage Hurrytimer/includes |
| 22 |
* @author Nabil Lemsieh <contact@nabillemsieh.com> |
| 23 |
*/ |
| 24 |
class Hurrytimer_Activator |
| 25 |
{ |
| 26 |
|
| 27 |
/** |
| 28 |
* Short Description. (use period) |
| 29 |
* |
| 30 |
* Long Description. |
| 31 |
* |
| 32 |
* @since 1.0.0 |
| 33 |
*/ |
| 34 |
public static function activate() |
| 35 |
{ |
| 36 |
$sql_builder = new SQL_Builder('hurrytimer_evergreen'); |
| 37 |
$sql_builder |
| 38 |
->create() |
| 39 |
->bigint('id', 20, true, false, true) |
| 40 |
->bigint('countdown_id', 20, true) |
| 41 |
->string('client_ip_address', 50, false) |
| 42 |
->boolean('expired') |
| 43 |
->bigint('client_expires_at', 20, true) |
| 44 |
->timestamp('destroy_at', true) |
| 45 |
->primary_key('id') |
| 46 |
->run(); |
| 47 |
add_option('hurrytimer_db_version', HURRYTIMER_DB_VERSION); |
| 48 |
static::maybe_backward_compat(); |
| 49 |
add_option('hurrytimer_version', HURRYTIMER_PLUGIN_VERSION); |
| 50 |
} |
| 51 |
|
| 52 |
public static function maybe_backward_compat() |
| 53 |
{ |
| 54 |
$current_version = get_option('hurrytimer_version'); |
| 55 |
if (version_compare($current_version, '1.1.3', '<=')) { |
| 56 |
@delete_option('_htmr_reset_cookie'); |
| 57 |
} |
| 58 |
if (version_compare($current_version, '1.0.1', '<=')) { |
| 59 |
$result = get_posts(['post_type' => 'hurrytimer_countdown']); |
| 60 |
foreach ($result as $item) { |
| 61 |
$countdown = new Hurrytimer_Countdown($item->ID); |
| 62 |
$headline_status = get_post_meta($item->ID, 'headline_status', true); |
| 63 |
if (intval($headline_status) === Headline_Status::HIDE) { |
| 64 |
$countdown->set_display_headline(false); |
| 65 |
$countdown->set_headline_position(Headline_Position::ABOVE_TIMER); |
| 66 |
} else { |
| 67 |
$countdown->set_display_headline(true); |
| 68 |
$countdown->set_headline_position($headline_status); |
| 69 |
} |
| 70 |
delete_post_meta($item->ID, 'headline_status'); |
| 71 |
} |
| 72 |
|
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|