PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.3
ووسلام – همگام سازی ووکامرس و باسلام v1.10.3
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Plugin.php

Plugin.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.3, at includes/Plugin.php

120 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam;
4
5 use SyncBasalam\Migrations\MigrationManager;
6 use SyncBasalam\Registrar\AdminRegistrar;
7 use SyncBasalam\Registrar\ListenerRegistrar;
8 use SyncBasalam\Registrar\OrderRegistrar;
9 use SyncBasalam\Registrar\ProductRegistrar;
10 use SyncBasalam\Registrar\QueueRegistrar;
11 use SyncBasalam\Services\Api\CircuitBreaker;
12 use SyncBasalam\Services\FetchVersionDetail;
13
14 defined('ABSPATH') || exit;
15
16 class Plugin
17 {
18 public const VERSION = '1.10.3';
19
20 public function __construct()
21 {
22 $this->onboarding();
23 $this->handleVersionUpdate();
24 $this->registrars();
25 $this->notices();
26 }
27
28 private function onboarding()
29 {
30 if (get_transient('sync_basalam_just_activated')) {
31 delete_transient('sync_basalam_just_activated');
32 if (!syncBasalamSettings()->hasToken()) {
33 wp_safe_redirect(admin_url('admin.php?page=basalam-onboarding'));
34 exit();
35 }
36 }
37 }
38
39 private function handleVersionUpdate()
40 {
41 $currentVersion = \get_option('sync_basalam_version') ?: '0.0.0';
42 if (version_compare($currentVersion, self::VERSION, '<')) {
43
44 $fetchVersionDetail = new FetchVersionDetail(self::VERSION);
45 $fetchVersionDetail->checkForceUpdate();
46
47 $manager = new MigrationManager();
48 $manager->runMigrations($currentVersion, self::VERSION);
49 }
50 }
51
52 private function notices()
53 {
54 if (!get_option('sync_basalam_review_never_remind')) {
55 add_action('admin_notices', function () {
56 $template = syncBasalamPlugin()->templatePath("notifications/LikeAlert.php");
57 require_once $template;
58 });
59 }
60
61 if (!syncBasalamSettings()->hasToken()) {
62 add_action('admin_notices', function () {
63 $template = syncBasalamPlugin()->templatePath("notifications/AccessAlert.php");
64 require_once($template);
65 });
66 }
67 add_action('admin_notices', function () {
68 $template = syncBasalamPlugin()->templatePath("notifications/HttpBlock.php");
69 require_once($template);
70 });
71 add_action('admin_notices', function () {
72 $circuitBreaker = new CircuitBreaker();
73
74 if ($circuitBreaker->getState() === CircuitBreaker::STATE_CLOSED) return;
75
76 $template = syncBasalamPlugin()->templatePath("notifications/CircuitBreakerAlert.php");
77 require $template;
78 });
79 }
80
81 private function registrars()
82 {
83 $registrars = [
84 AdminRegistrar::class,
85 ProductRegistrar::class,
86 OrderRegistrar::class,
87 ListenerRegistrar::class,
88 QueueRegistrar::class,
89 ];
90
91 foreach ($registrars as $registrarClass) {
92 $registrar = syncBasalamContainer()->get($registrarClass);
93 $registrar->register();
94 }
95 }
96
97 public function pluginPath()
98 {
99 return untrailingslashit(str_replace("includes", "", \plugin_dir_path(__FILE__)));
100 }
101
102 public function templatePath($path = null)
103 {
104
105 $path = $path ? "/" . $path : null;
106
107 return $this->pluginPath() . "/templates" . $path;
108 }
109
110 public function assetsUrl($path = null)
111 {
112 return plugin_dir_url(dirname(__FILE__, 1)) . "assets/" . $path;
113 }
114
115 public function getVersion()
116 {
117 return self::VERSION;
118 }
119 }
120