PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.0
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.0
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / vendor / hostinger / hostinger-wp-surveys / src / Loader.php
hostinger-reach / vendor / hostinger / hostinger-wp-surveys / src Last commit date
Ajax.php 3 months ago Assets.php 1 month ago Loader.php 1 year ago Rest.php 1 year ago SurveyLoader.php 1 year ago SurveyManager.php 1 month ago
Loader.php
127 lines
1 <?php
2
3 namespace Hostinger\Surveys;
4
5 use Hostinger\WpHelper\Config;
6 use Hostinger\WpHelper\Constants;
7 use Hostinger\WpHelper\Requests\Client;
8 use Hostinger\WpHelper\Utils;
9 use Hostinger\Surveys\Ajax as SurveysAjax;
10
11 class Loader
12 {
13 /**
14 * @var Loader instance.
15 */
16 private static ?Loader $instance = null;
17
18 /**
19 * @var array
20 */
21 private array $objects = [];
22
23 /**
24 * Allow only one instance of class
25 *
26 * @return self
27 */
28 public static function getInstance(): self
29 {
30 if (null === self::$instance) {
31 self::$instance = new self();
32 }
33
34 return self::$instance;
35 }
36
37 /**
38 * @return void
39 */
40 public function boot(): bool
41 {
42 $this->registerModules();
43 $this->loadTextDomain();
44
45 return true;
46 }
47
48 /**
49 * @return void
50 */
51 public function registerModules(): void
52 {
53 // Surveys.
54 $helper = new Utils();
55 $configHandler = new Config();
56 $surveyRest = new Rest(
57 new Client(
58 $configHandler->getConfigValue('base_rest_uri', Constants::HOSTINGER_REST_URI),
59 [
60 Config::TOKEN_HEADER => $helper::getApiToken(),
61 Config::DOMAIN_HEADER => $helper->getHostInfo(),
62 ]
63 )
64 );
65
66 $this->objects['ajax'] = new SurveysAjax($helper, $configHandler, $surveyRest);
67
68 // Assets.
69 $this->objects['assets'] = new Assets();
70 $this->objects['assets']->init();
71
72 $this->objects['survey_loader'] = new SurveyLoader();
73 $this->objects['survey_loader']->run();
74
75 $this->addContainer();
76 }
77
78 /**
79 * @return bool
80 */
81 public function addContainer(): bool
82 {
83 if (empty($this->objects)) {
84 return false;
85 }
86
87 foreach ($this->objects as $object) {
88 if (property_exists($object, 'surveys')) {
89 $object->surveys = $this;
90 }
91 }
92
93 return true;
94 }
95
96 /**
97 * @return string
98 */
99 public function getPluginInfo(): string
100 {
101 $plugin_url = '';
102
103 $plugins = get_plugins();
104 foreach ($plugins as $plugin_path => $plugin_info) {
105 if (str_contains(__FILE__, 'plugins/' . dirname($plugin_path) . '/')) {
106 $plugin_dir = dirname($plugin_path);
107
108 return plugins_url($plugin_dir);
109 }
110 }
111
112 return $plugin_url;
113 }
114
115 /**
116 * @return void
117 */
118 public function loadTextDomain(): void
119 {
120 load_plugin_textdomain(
121 'hostinger-wp-surveys',
122 false,
123 dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
124 );
125 }
126 }
127