| 1 |
<?php |
| 2 |
|
| 3 |
namespace Cookiez\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
require_once COOKIEZ_PATH . 'modules/connect/classes/config.php'; |
| 10 |
|
| 11 |
use Cookiez\Modules\Connect\Classes\Config as CookiezConfig; |
| 12 |
use ElementorOne\Admin\Components\Fields; |
| 13 |
use ElementorOne\Admin\Config; |
| 14 |
use ElementorOne\Connect\Classes\Data; |
| 15 |
|
| 16 |
final class Plugin_Activation { |
| 17 |
public function __construct( $file ) { |
| 18 |
register_activation_hook( $file, [ $this, 'handle' ] ); |
| 19 |
} |
| 20 |
|
| 21 |
public function handle(): void { |
| 22 |
$cookiez_token_option = CookiezConfig::APP_PREFIX . Data::ACCESS_TOKEN; |
| 23 |
$one_token_option = Config::APP_PREFIX . Data::ACCESS_TOKEN; |
| 24 |
$migrated_plugins_option = Fields::SETTING_PREFIX . 'migrated_plugins'; |
| 25 |
|
| 26 |
$is_cookiez_connected = ! empty( get_option( $cookiez_token_option ) ); |
| 27 |
$is_one_connected = ! empty( get_option( $one_token_option ) ); |
| 28 |
|
| 29 |
if ( $is_cookiez_connected || ! $is_one_connected ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$migrated_plugins = get_option( $migrated_plugins_option, [] ); |
| 34 |
if ( in_array( CookiezConfig::PLUGIN_SLUG, $migrated_plugins, true ) ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
$migrated_plugins[] = CookiezConfig::PLUGIN_SLUG; |
| 39 |
update_option( $migrated_plugins_option, $migrated_plugins, false ); |
| 40 |
} |
| 41 |
} |
| 42 |
|