PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.8.6
ووسلام – همگام سازی ووکامرس و باسلام v1.8.6
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.8.6, at includes/Plugin.php

111 lines 3.0 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\FetchVersionDetail;
12
13 defined('ABSPATH') || exit;
14
15 class Plugin
16 {
17 public const VERSION = '1.8.6';
18
19 public function __construct()
20 {
21 $this->onboarding();
22 $this->handleVersionUpdate();
23 $this->registrars();
24 $this->notices();
25 }
26
27 private function onboarding()
28 {
29 if (get_transient('sync_basalam_just_activated')) {
30 delete_transient('sync_basalam_just_activated');
31 if (!syncBasalamSettings()->hasToken()) {
32 wp_redirect(admin_url('admin.php?page=basalam-onboarding'));
33 exit();
34 }
35 }
36 }
37
38 private function handleVersionUpdate()
39 {
40 $currentVersion = \get_option('sync_basalam_version') ?: '0.0.0';
41 if (version_compare($currentVersion, self::VERSION, '<')) {
42
43 $fetchVersionDetail = new FetchVersionDetail(self::VERSION);
44 $fetchVersionDetail->checkForceUpdate();
45
46 $manager = new MigrationManager();
47 $manager->runMigrations($currentVersion, self::VERSION);
48 }
49 }
50
51 private function notices()
52 {
53 if (!get_option('sync_basalam_review_never_remind')) {
54 add_action('admin_notices', function () {
55 $template = syncBasalamPlugin()->templatePath("notifications/LikeAlert.php");
56 require_once $template;
57 });
58 }
59
60 if (!syncBasalamSettings()->hasToken()) {
61 add_action('admin_notices', function () {
62 $template = syncBasalamPlugin()->templatePath("notifications/AccessAlert.php");
63 require_once($template);
64 });
65 }
66 add_action('admin_notices', function () {
67 $template = syncBasalamPlugin()->templatePath("notifications/HttpBlock.php");
68 require_once($template);
69 });
70 }
71
72 private function registrars()
73 {
74 $registrars = [
75 AdminRegistrar::class,
76 ProductRegistrar::class,
77 OrderRegistrar::class,
78 ListenerRegistrar::class,
79 QueueRegistrar::class,
80 ];
81
82 foreach ($registrars as $registrarClass) {
83 $registrar = syncBasalamContainer()->get($registrarClass);
84 $registrar->register();
85 }
86 }
87
88 public function pluginPath()
89 {
90 return untrailingslashit(str_replace("includes", "", \plugin_dir_path(__FILE__)));
91 }
92
93 public function templatePath($path = null)
94 {
95
96 $path = $path ? "/" . $path : null;
97
98 return $this->pluginPath() . "/templates" . $path;
99 }
100
101 public function assetsUrl($path = null)
102 {
103 return plugin_dir_url(dirname(__FILE__, 1)) . "assets/" . $path;
104 }
105
106 public function getVersion()
107 {
108 return self::VERSION;
109 }
110 }
111