PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.13
ووسلام – همگام سازی ووکامرس و باسلام v1.10.13
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 1.8.7 1.8.4 1.7.6 All 50 releases
sync-basalam / includes / Plugin.php

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

128 lines 3.7 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.13';
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 if (!AdminRegistrar::isWoosalamRelatedAdminScreen()) return;
57
58 $template = syncBasalamPlugin()->templatePath("notifications/LikeAlert.php");
59 require_once $template;
60 });
61 }
62
63 if (!syncBasalamSettings()->hasToken()) {
64 add_action('admin_notices', function () {
65 if (!AdminRegistrar::isWoosalamRelatedAdminScreen()) return;
66
67 $template = syncBasalamPlugin()->templatePath("notifications/AccessAlert.php");
68 require_once($template);
69 });
70 }
71 add_action('admin_notices', function () {
72 if (!AdminRegistrar::isWoosalamRelatedAdminScreen()) return;
73
74 $template = syncBasalamPlugin()->templatePath("notifications/HttpBlock.php");
75 require_once($template);
76 });
77 add_action('admin_notices', function () {
78 if (!AdminRegistrar::isWoosalamRelatedAdminScreen()) return;
79
80 $circuitBreaker = new CircuitBreaker();
81
82 if ($circuitBreaker->getState() === CircuitBreaker::STATE_CLOSED) return;
83
84 $template = syncBasalamPlugin()->templatePath("notifications/CircuitBreakerAlert.php");
85 require $template;
86 });
87 }
88
89 private function registrars()
90 {
91 $registrars = [
92 AdminRegistrar::class,
93 ProductRegistrar::class,
94 OrderRegistrar::class,
95 ListenerRegistrar::class,
96 QueueRegistrar::class,
97 ];
98
99 foreach ($registrars as $registrarClass) {
100 $registrar = syncBasalamContainer()->get($registrarClass);
101 $registrar->register();
102 }
103 }
104
105 public function pluginPath()
106 {
107 return untrailingslashit(str_replace("includes", "", \plugin_dir_path(__FILE__)));
108 }
109
110 public function templatePath($path = null)
111 {
112
113 $path = $path ? "/" . $path : null;
114
115 return $this->pluginPath() . "/templates" . $path;
116 }
117
118 public function assetsUrl($path = null)
119 {
120 return plugin_dir_url(dirname(__FILE__, 1)) . "assets/" . $path;
121 }
122
123 public function getVersion()
124 {
125 return self::VERSION;
126 }
127 }
128