PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / trunk
Disable Admin Notices – Hide Dashboard Notifications vtrunk
1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / libs / factory / core / includes / class-factory-plugin-abstract.php
disable-admin-notices / libs / factory / core / includes Last commit date
activation 1 year ago assets-managment 1 year ago components 1 year ago entities 1 year ago updates 5 months ago class-check-compatibility.php 1 year ago class-factory-migrations.php 6 months ago class-factory-notices.php 1 year ago class-factory-options.php 1 year ago class-factory-plugin-abstract.php 5 months ago class-factory-plugin-base.php 1 year ago class-factory-requests.php 1 year ago class-factory-requirements.php 5 months ago functions.php 1 year ago index.php 3 years ago
class-factory-plugin-abstract.php
885 lines
1 <?php
2 // Exit if accessed directly
3 if( !defined('ABSPATH') ) {
4 exit;
5 }
6
7 /**
8 * Основной класс для создания плагина.
9 *
10 * Это основной класс плагина. который отвечает за подключение модулей фреймворка, линзирование, обновление,
11 * миграции разрабатываемого плагина. При создании нового плагина, вы должны создать основной класс реализующий
12 * функции плагина, этот класс будет наследовать текущий.
13 *
14 * Смотрите подробную инструкцию по созданию плагина и экземпляра основного класса в документации по созданию
15 * плагина для Wordpress.
16 *
17 * Документация по классу: https://webcraftic.atlassian.net/wiki/spaces/FFD/pages/393052164
18 * Документация по созданию плагина: https://webcraftic.atlassian.net/wiki/spaces/CNCFC/pages/327828
19 *
20 * @author Alex Kovalev <alex.kovalevv@gmail.com>, repo: https://github.com/alexkovalevv
21 * @author Webcraftic <wordpress.webraftic@gmail.com>, site: https://webcraftic.com
22 *
23 * @since 1.0.0
24 * @package factory-core
25 *
26 */
27 abstract class Wbcr_Factory480_Plugin extends Wbcr_Factory480_Base {
28
29 /**
30 * Instance class Wbcr_Factory480_Request, required manages http requests
31 *
32 * @see https://webcraftic.atlassian.net/wiki/spaces/FFD/pages/390561806
33 * @var Wbcr_Factory480_Request
34 */
35 public $request;
36
37 /**
38 * @see https://webcraftic.atlassian.net/wiki/spaces/FFD/pages/393936924
39 * @var \WBCR\Factory_480\Premium\Provider
40 */
41 public $premium;
42
43 /**
44 * The Bootstrap Manager class
45 *
46 * @var Wbcr_FactoryBootstrap482_Manager
47 */
48 public $bootstrap;
49
50 /**
51 * The Bootstrap Manager class
52 *
53 * @var Wbcr_FactoryForms480_Manager
54 */
55 public $forms;
56
57 /**
58 * Простой массив со списком зарегистрированны�
59 классов унаследованны�
60 от Wbcr_Factory480_Activator.
61 * Классы активации используются для упаковки набора функций, которые нужно выполнить во время
62 * активации плагина.
63 *
64 * @var array[] Wbcr_Factory480_Activator
65 */
66 protected $activator_class = [];
67
68 /**
69 * Ассоциативный массив со списком уже загруженны�
70 модулей фреймворка. Используется для того, чтобы
71 * проверить, каки�
72 модули уже были загружены, а какие еще нет.
73 *
74 * @var array
75 */
76 private $loaded_factory_modules = [];
77
78 /**
79 * Ассоциативный массив со списком аддонов плагина. Аддоны плагина являются частью одного проекта,
80 * но не как отдельный плагин.
81 *
82 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
83 * @since 4.2.0
84 * @var array
85 */
86 private $loaded_plugin_components = [];
87
88 /**
89 * The Adverts Manager class
90 *
91 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
92 * @since 4.1.9
93 * @var WBCR\Factory_Adverts_159\Base
94 */
95 private $adverts;
96
97 /**
98 * The Logger class
99 *
100 * @author Artem Prihodko <webtemyk@yandex.ru>
101 * @since 4.3.7
102 * @var WBCR\Factory_Logger_149\Logger
103 */
104 public $logger;
105
106 /**
107 * Инициализирует компоненты фреймворка и плагина.
108 *
109 * @param array $data A set of plugin data.
110 *
111 * @param string $plugin_path A full path to the main plugin file.
112 *
113 * @throws Exception
114 * @since 1.0.0
115 *
116 */
117 public function __construct($plugin_path, $data)
118 {
119
120 parent::__construct($plugin_path, $data);
121
122 $this->request = new Wbcr_Factory480_Request();
123 //$this->route = new Wbcr_Factory480_Route();
124
125 // INIT PLUGIN FRAMEWORK MODULES
126 // Framework modules should always be loaded first,
127 // since all other functions depend on them.
128 $this->init_framework_modules();
129
130 // INIT PLUGIN MIGRATIONS
131 $this->init_plugin_migrations();
132
133 // INIT PLUGIN NOTICES
134 $this->init_plugin_notices();
135
136 // INIT PLUGIN UPDATES
137 $this->init_plugin_updates();
138
139 // init actions
140 $this->register_plugin_hooks();
141
142 // INIT PLUGIN COMPONENTS
143 $this->init_plugin_components();
144
145 if( wp_doing_ajax() && isset($_REQUEST['action']) ) {
146 if( "wfactory-480-intall-component" == $_REQUEST['action'] ) {
147 add_action('wp_ajax_wfactory-480-intall-component', [$this, 'ajax_handler_install_components']);
148 }
149
150 if( "wfactory-480-prepare-component" == $_REQUEST['action'] ) {
151 add_action('wp_ajax_wfactory-480-prepare-component', [$this, 'ajax_handler_prepare_component']);
152 }
153 if( "wfactory-480-creativemotion-install-plugin" == $_REQUEST['action'] ) {
154 add_action('wp_ajax_wfactory-480-creativemotion-install-plugin', [
155 $this,
156 'ajax_handler_install_creativemotion_plugins'
157 ]);
158 }
159 }
160 }
161
162 // Ajax Handlers
163 // --------------------------------------------------------
164
165 public function ajax_handler_install_components()
166 {
167 require_once FACTORY_480_DIR . '/ajax/install-addons.php';
168 wfactory_480_install_components($this);
169 }
170
171 public function ajax_handler_prepare_component()
172 {
173 require_once FACTORY_480_DIR . '/ajax/install-addons.php';
174 wfactory_480_prepare_component($this);
175 }
176
177 public function ajax_handler_install_creativemotion_plugins()
178 {
179 require_once FACTORY_480_DIR . '/ajax/install-addons.php';
180 wfactory_480_creativemotion_install_plugin($this);
181 }
182 // --------------------------------------------------------
183
184 /**
185 * Устанавливает класс менеджер, которому плагин будет делегировать подключение ресурсов (картинок,
186 * скриптов, стилей) фреймворка.
187 *
188 * @param Wbcr_FactoryBootstrap482_Manager $bootstrap
189 */
190 public function setBootstap(Wbcr_FactoryBootstrap482_Manager $bootstrap)
191 {
192 $this->bootstrap = $bootstrap;
193 }
194
195 /**
196 * Устанавливает класс менеджер, которому будет делегирована работа с html формами фреймворка.
197 *
198 * @param Wbcr_FactoryForms480_Manager $forms
199 */
200 public function setForms(Wbcr_FactoryForms480_Manager $forms)
201 {
202 $this->forms = $forms;
203 }
204
205 /**
206 * Устанавливает класс менеджер, которому будет делегирована работа с объявлениями в Wordpress
207 *
208 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
209 * @since 4.1.9
210 */
211 public function set_adverts_manager($class_name)
212 {
213 if( empty($this->adverts) && $this->render_adverts ) {
214 $this->adverts = new $class_name($this, $this->adverts_settings);
215 }
216 }
217
218 /**
219 * Устанавливает класс менеджер, которому будет делегирована работа с объявлениями в Wordpress
220 *
221 * @param string $class_name Logger class name
222 * @param array $settings Logger settings
223 *
224 * @author Artem Prihodko <webtemyk@yandex.ru>
225 * @since 4.3.7
226 */
227 public function set_logger($class_name, $settings = [])
228 {
229 if( empty($this->logger) ) {
230 $this->logger = new $class_name($this, $settings);
231 }
232 }
233
234 /**
235 * Устанавливает класс провайдера лицензий
236 *
237 * С помощью этого класса, мы проверяем валидность лицензий и получаем дополнительную информацию
238 * о лицензии и ее покупателе. Класс используется в премиум менеджере.
239 *
240 * @param string $name Имя провайдер
241 * @param string $class_name Имя класса провайдера
242 *
243 * @since 4.1.6 - Добавлен
244 *
245 */
246 public function set_license_provider($name, $class_name)
247 {
248 if( !isset(WBCR\Factory_480\Premium\Manager::$providers[$name]) ) {
249 WBCR\Factory_480\Premium\Manager::$providers[$name] = $class_name;
250 }
251 }
252
253 /**
254 * Регистрируем класс репозитория
255 *
256 * С помощью этого класса мы реализиуем доставку и откат обновлений плагина, на сайт пользователя.
257 * Скачиваение премиум версий проис�
258 одит по защенному каналу. Класс используется в менеджере обновлений.
259 *
260 * @param string $name Имя репозитория
261 * @param string $class_name Имя класса репозитория
262 *
263 * @since 4.1.7 - Добавлен
264 *
265 */
266 public function set_update_repository($name, $class_name)
267 {
268 if( !isset(WBCR\Factory_480\Updates\Upgrader::$repositories[$name]) ) {
269 WBCR\Factory_480\Updates\Upgrader::$repositories[$name] = $class_name;
270 }
271 }
272
273 /**
274 * Позволяет получить экземпляр менеджера объявления
275 *
276 * Доступен глобально через метод app(), чаще всего используется для создания точек для ротации
277 * рекламны�
278 объявлений.
279 *
280 * @return \WBCR\Factory_Adverts_159\Base
281 * @since 1.1
282 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
283 */
284 public function get_adverts_manager()
285 {
286 return $this->adverts;
287 }
288
289 /**
290 * Устанавливает текстовый домен для плагина. Текстовый домен берется из заголовка в�
291 одного
292 * файла плагина.
293 *
294 * @since 4.2.5 - Добавлены 2 аргумента $text_domain, $plugin_dir. Теперь protected
295 * @since 4.0.8 - Добавлен
296 *
297 * @see https://codex.wordpress.org/I18n_for_WordPress_Developers
298 * @see https://webcraftic.atlassian.net/wiki/spaces/CNCFC/pages/327828 - документация по в�
299 одному файлу
300 */
301 protected function set_text_domain($text_domain, $plugin_dir)
302 {
303 if( empty($text_domain) || empty($plugin_dir) ) {
304 return;
305 }
306
307 $locale = apply_filters('plugin_locale', is_admin() ? get_user_locale() : get_locale(), $text_domain);
308
309 $mofile = $text_domain . '-' . $locale . '.mo';
310
311 if( !load_textdomain($text_domain, $plugin_dir . '/languages/' . $mofile) ) {
312 load_muplugin_textdomain($text_domain);
313 }
314 }
315
316 public function newScriptList()
317 {
318 return new Wbcr_Factory480_ScriptList($this);
319 }
320
321 public function newStyleList()
322 {
323 return new Wbcr_Factory480_StyleList($this);
324 }
325
326 /**
327 * Все страницы плагина создаются через специальную обертку, за которую отвечает модуль
328 * фреймворка pages. Разработчик создает собственный класс, унаследованный от
329 * Wbcr_FactoryPages480_AdminPage, а затем регистрирует его через этот метод.
330 * Метод выполняет подключение класса страницы и регистрирует его в модуле фреймворка
331 * pages.
332 *
333 * Больше информации о создании и регистрации страниц, вы можете узнать из документации по созданию
334 * страниц плагина.
335 *
336 * @see https://webcraftic.atlassian.net/wiki/spaces/CNCFC/pages/222887949 - документация по созданию страниц
337 *
338 * @param string $class_name Имя регистрируемого класса страницы. Пример: WCL_Page_Name.
339 * Регистрируемый класс должен быть унаследован от класса Wbcr_FactoryPages480_AdminPage.
340 * @param string $file_path Абсолютный путь к файлу с классом страницы.
341 *
342 * @throws Exception
343 */
344 public function registerPage($class_name, $file_path)
345 {
346 // todo: https://webcraftic.atlassian.net/projects/PCS/issues/PCS-88
347 // if ( $this->isNetworkActive() && ! is_network_admin() ) {
348 // return;
349 // }
350
351 if( !file_exists($file_path) ) {
352 throw new Exception('The page file was not found by the path {' . $file_path . '} you set.');
353 }
354
355 require_once($file_path);
356
357 if( !class_exists($class_name) ) {
358 throw new Exception('A class with this name {' . $class_name . '} does not exist.');
359 }
360
361 if( !class_exists('Wbcr_FactoryPages480') ) {
362 throw new Exception('The factory_pages_480 module is not included.');
363 }
364
365 Wbcr_FactoryPages480::register($this, $class_name);
366 }
367
368 /**
369 * Произвольные типы записей в плагине, создаются через специальную обертку, за которую отвечает
370 * модуль фреймворка types. Разработчик создает собственный класс, унаследованный от
371 * Wbcr_FactoryTypes000_Type, а затем регистрирует его через этот метод. Метод выполняет
372 * подключение класса с новым типом записи и регистрирует его в модуле фреймворка types. *
373 *
374 * @param string $class_name Имя регистрируемого класса страницы. Пример: WCL_Type_Name.
375 * Регистрируемый класс должен быть унаследован от класса Wbcr_FactoryTypes000_Type.
376 * @param string $file_path Абсолютный путь к файлу с классом страницы.
377 *
378 * @throws Exception
379 * @deprecated 4.1.7 You cannot use it!
380 */
381 public function registerType($class_name, $file_path)
382 {
383 throw new Exception('As of factory core module 4.1.7, the "registerType" method is deprecated. You cannot use it!');
384 }
385
386 /**
387 * Registers a class to activate the plugin.
388 *
389 * @param string $className class name of the plugin activator.
390 *
391 * @return void
392 * @since 1.0.0
393 *
394 */
395 public function registerActivation($className)
396 {
397 $this->activator_class[] = $className;
398 }
399
400 /* end services region
401 /* -------------------------------------------------------------*/
402
403 /**
404 * It's invoked on plugin activation. Don't excite it directly.
405 *
406 * @return void
407 * @since 1.0.0
408 */
409 public function activation_hook()
410 {
411
412 /**
413 * @since 4.1.1 - change hook name
414 */
415 if( apply_filters("wbcr/factory_480/cancel_plugin_activation_{$this->plugin_name}", false) ) {
416 return;
417 }
418
419 /**
420 * wbcr_factory_480_plugin_activation
421 *
422 * @since 4.1.1 - deprecated
423 */
424 wbcr_factory_480_do_action_deprecated('wbcr_factory_480_plugin_activation', [
425 $this
426 ], '4.1.1', "wbcr/factory/plugin_activation");
427
428 /**
429 * wbcr/factory/plugin_activation
430 *
431 * @since 4.1.2 - deprecated
432 */
433 wbcr_factory_480_do_action_deprecated('wbcr/factory/plugin_activation', [
434 $this
435 ], '4.1.2', "wbcr/factory/before_plugin_activation");
436
437 /**
438 * wbcr/factory/before_plugin_activation
439 *
440 * @since 4.1.2 - added
441 */
442 do_action('wbcr/factory/before_plugin_activation', $this);
443
444 /**
445 * # wbcr/factory/plugin_{$this->plugin_name}_activation
446 *
447 * @since 4.1.2 - deprecated
448 */
449 wbcr_factory_480_do_action_deprecated("wbcr/factory/plugin_{$this->plugin_name}_activation", [
450 $this
451 ], '4.1.2', "wbcr/factory/before_plugin_{$this->plugin_name}_activation");
452
453 /**
454 * wbcr_factory_480_plugin_activation_' . $this->plugin_name
455 *
456 * @since 4.1.1 - deprecated
457 */
458 wbcr_factory_480_do_action_deprecated('wbcr_factory_480_plugin_activation_' . $this->plugin_name, [
459 $this
460 ], '4.1.1', "wbcr/factory/before_plugin_{$this->plugin_name}_activation");
461
462 /**
463 * wbcr/factory/plugin_{$this->plugin_name}_activation
464 *
465 * @since 4.1.2 - added
466 */
467 do_action("wbcr/factory/plugin_{$this->plugin_name}_activation", $this);
468
469 if( !empty($this->activator_class) ) {
470 foreach((array)$this->activator_class as $activator_class) {
471 $activator = new $activator_class($this);
472 $activator->activate();
473 }
474 }
475
476 /**
477 * @since 4.1.2 - added
478 */
479 do_action('wbcr/factory/plugin_activated', $this);
480
481 /**
482 * @since 4.1.2 - added
483 */
484 do_action("wbcr/factory/plugin_{$this->plugin_name}_activated", $this);
485 }
486
487 /**
488 * It's invoked on plugin deactionvation. Don't excite it directly.
489 *
490 * @return void
491 * @since 1.0.0
492 */
493 public function deactivation_hook()
494 {
495
496 /**
497 * @since 4.1.1 - change hook name
498 */
499 if( apply_filters("wbcr/factory_480/cancel_plugin_deactivation_{$this->plugin_name}", false) ) {
500 return;
501 }
502
503 /**
504 * wbcr_factory_480_plugin_deactivation
505 *
506 * @since 4.1.1 - deprecated
507 */
508 wbcr_factory_480_do_action_deprecated('wbcr_factory_480_plugin_deactivation', [
509 $this
510 ], '4.1.1', "wbcr/factory/plugin_deactivation");
511
512 /**
513 * wbcr/factory/plugin_deactivation
514 *
515 * @since 4.1.2 - deprecated
516 */
517 wbcr_factory_480_do_action_deprecated('wbcr/factory/plugin_deactivation', [
518 $this
519 ], '4.1.2', "wbcr/factory/before_plugin_deactivation");
520
521 /**
522 * wbcr/factory/plugin_deactivation
523 *
524 * @since 4.1.2 - added
525 */
526 do_action('wbcr/factory/plugin_deactivation', $this);
527
528 /**
529 * wbcr_factory_480_plugin_deactivation_ . $this->plugin_name
530 *
531 * @since 4.1.1 - deprecated
532 */
533 wbcr_factory_480_do_action_deprecated('wbcr_factory_480_plugin_deactivation_' . $this->plugin_name, [
534 $this
535 ], '4.1.1', "wbcr/factory/before_plugin_{$this->plugin_name}_deactivation");
536
537 /**
538 * wbcr/factory/plugin_{$this->plugin_name}_deactivation
539 *
540 * @since 4.1.2 - deprecated
541 */
542 wbcr_factory_480_do_action_deprecated("wbcr/factory/plugin_{$this->plugin_name}_deactivation", [
543 $this
544 ], '4.1.2', "wbcr/factory/before_plugin_{$this->plugin_name}_deactivation");
545
546 /**
547 * @since 4.1.2 - added
548 */
549 do_action("wbcr/factory/before_plugin_{$this->plugin_name}_deactivation");
550
551 if( !empty($this->activator_class) ) {
552 foreach((array)$this->activator_class as $activator_class) {
553 $activator = new $activator_class($this);
554 $activator->deactivate();
555 }
556 }
557
558 /**
559 * @since 4.1.2 - added
560 */
561 do_action('wbcr/factory/plugin_deactivated', $this);
562
563 /**
564 * @since 4.1.2 - added
565 */
566 do_action("wbcr/factory/plugin_{$this->plugin_name}_deactivated", $this);
567 }
568
569 /**
570 * Возвращает ссылку на внутреннюю страницу плагина
571 *
572 * @param string $page_id
573 *
574 * @sicne: 4.0.8
575 * @return string|void
576 * @throws Exception
577 */
578 public function getPluginPageUrl($page_id, $args = [])
579 {
580 if( !class_exists('Wbcr_FactoryPages480') ) {
581 throw new Exception('The factory_pages_480 module is not included.');
582 }
583
584 if( !is_admin() ) {
585 _doing_it_wrong(__METHOD__, __('You cannot use this feature on the frontend.'), '4.0.8');
586
587 return null;
588 }
589
590 return Wbcr_FactoryPages480::getPageUrl($this, $page_id, $args);
591 }
592
593 /**
594 * Allows you to get a button to install the plugin component
595 *
596 * @param $component_type
597 * @param $slug
598 * param $premium
599 *
600 * @return \WBCR\Factory_480\Components\Install_Button
601 */
602 public function get_install_component_button($component_type, $slug)
603 {
604 require_once FACTORY_480_DIR . '/includes/components/class-install-component-button.php';
605
606 return new \WBCR\Factory_480\Components\Install_Button($this, $component_type, $slug);
607 }
608
609 /**
610 * Allows you to get a button to delete the plugin component
611 *
612 * @param $component_type
613 * @param $slug
614 *
615 * @return \WBCR\Factory_480\Components\Delete_Button
616 */
617 public function get_delete_component_button($component_type, $slug)
618 {
619 require_once FACTORY_480_DIR . '/includes/components/class-delete-component-button.php';
620
621 return new WBCR\Factory_480\Components\Delete_Button($this, $component_type, $slug);
622 }
623
624 /**
625 * @param string $component_name
626 *
627 * @return bool
628 */
629 public function is_activate_component($component_name)
630 {
631 if( !is_string($component_name) ) {
632 return false;
633 }
634
635 $deactivate_components = $this->getPopulateOption('deactive_preinstall_components', []);
636
637 if( !is_array($deactivate_components) ) {
638 $deactivate_components = [];
639 }
640
641 if( $deactivate_components && in_array($component_name, $deactivate_components) ) {
642 return false;
643 }
644
645 return true;
646 }
647
648 /**
649 * @param string $component_name
650 *
651 * @return bool
652 */
653 public function activate_component($component_name)
654 {
655 if( $this->is_activate_component($component_name) ) {
656 return true;
657 }
658
659 do_action('wfactory/pre_activate_component', $component_name);
660
661 $deactivate_components = $this->getPopulateOption('deactive_preinstall_components', []);
662
663 if( !empty($deactivate_components) && is_array($deactivate_components) ) {
664 $index = array_search($component_name, $deactivate_components);
665 unset($deactivate_components[$index]);
666 }
667
668 if( empty($deactivate_components) ) {
669 $this->deletePopulateOption('deactive_preinstall_components');
670 } else {
671 $this->updatePopulateOption('deactive_preinstall_components', $deactivate_components);
672 }
673
674 return true;
675 }
676
677 /**
678 * @param string $component_name
679 *
680 * @return bool
681 */
682 public function deactivate_component($component_name)
683 {
684 if( !$this->is_activate_component($component_name) ) {
685 return true;
686 }
687
688 do_action('wfactory/pre_deactivate_component', $component_name);
689
690 $deactivate_components = $this->getPopulateOption('deactive_preinstall_components', []);
691
692 if( !empty($deactivate_components) && is_array($deactivate_components) ) {
693 $deactivate_components[] = $component_name;
694 } else {
695 $deactivate_components = [];
696 $deactivate_components[] = $component_name;
697 }
698
699 $this->updatePopulateOption('deactive_preinstall_components', $deactivate_components);
700
701 do_action('wfactory/deactivated_component', $component_name);
702
703 return true;
704 }
705
706 /**
707 * Загружает аддоны для плагина, как часть проекта, а не как отдельный плагин
708 *
709 * @throws \Exception
710 */
711 private function init_plugin_components()
712 {
713
714 $load_plugin_components = $this->get_load_plugin_components();
715
716 if( empty($load_plugin_components) || !is_array($load_plugin_components) ) {
717 return;
718 }
719
720 foreach($load_plugin_components as $component_ID => $component) {
721 if( !isset($this->loaded_plugin_components[$component_ID]) ) {
722
723 if( !isset($component['autoload']) || !isset($component['plugin_prefix']) ) {
724 throw new Exception(sprintf("Component %s cannot be loaded, you must specify the path to the component autoload file and plugin prefix!", $component_ID));
725 }
726
727 $prefix = rtrim($component['plugin_prefix'], '_') . '_';
728
729 if( defined($prefix . 'PLUGIN_ACTIVE') ) {
730 continue;
731 }
732
733 $autoload_file = trailingslashit($this->get_paths()->absolute) . $component['autoload'];
734
735 if( !file_exists($autoload_file) ) {
736 throw new Exception(sprintf("Component %s autoload file not found!", $component_ID));
737 }
738
739 $plugin_var_name = strtolower($prefix . 'plugin');
740 global $$plugin_var_name;
741 $$plugin_var_name = $this;
742
743 require_once($autoload_file);
744
745 if( defined($prefix . 'PLUGIN_ACTIVE') ) {
746 $this->loaded_plugin_components[$component_ID] = [
747 'plugin_dir' => constant($prefix . 'PLUGIN_DIR'),
748 'plugin_url' => constant($prefix . 'PLUGIN_URL'),
749 'plugin_base' => constant($prefix . 'PLUGIN_BASE'),
750 'text_domain' => constant($prefix . 'TEXT_DOMAIN'),
751 'plugin_version' => constant($prefix . 'PLUGIN_VERSION')
752 ];
753
754 /**
755 * Оповещает внешние приложения, что компонент плагина был загружен
756 *
757 * @param array $load_plugin_components Информация о загруженном компоненте
758 * @param string $plugin_name Имя плагина
759 */
760 do_action("wbcr/factory/component_{$component_ID}_loaded", $this->loaded_plugin_components[$component_ID], $this->getPluginName());
761 } else {
762 throw new Exception(sprintf("Сomponent %s does not meet development standards!", $component_ID));
763 }
764 }
765 }
766 }
767
768 /**
769 * Загружает специальные модули для расширения Factory фреймворка.
770 * Разработчик плагина сам выбирает, какие модули ему нужны для
771 * создания плагина.
772 *
773 * Модули фреймворка �
774 ранятся в libs/factory/framework
775 *
776 * @return void
777 * @throws Exception
778 */
779 private function init_framework_modules()
780 {
781
782 if( !empty($this->load_factory_modules) ) {
783 foreach((array)$this->load_factory_modules as $module) {
784 $scope = isset($module[2]) ? $module[2] : 'all';
785
786 if( $scope == 'all' || (is_admin() && $scope == 'admin') || (!is_admin() && $scope == 'public') ) {
787
788 if( !file_exists($this->get_paths()->absolute . '/' . $module[0] . '/boot.php') ) {
789 throw new Exception('Module ' . $module[1] . ' is not included.');
790 }
791
792 $module_boot_file = $this->get_paths()->absolute . '/' . $module[0] . '/boot.php';
793 require_once $module_boot_file;
794
795 $this->loaded_factory_modules[$module[1]] = $module_boot_file;
796
797 do_action('wbcr_' . $module[1] . '_plugin_created', $this);
798 }
799 }
800 }
801
802 /**
803 * @since 4.1.1 - deprecated
804 */
805 wbcr_factory_480_do_action_deprecated('wbcr_factory_480_core_modules_loaded-' . $this->plugin_name, [], '4.1.1', "wbcr/factory_480/modules_loaded-" . $this->plugin_name);
806
807 /**
808 * @since 4.1.1 - add
809 */
810 do_action('wbcr/factory_480/modules_loaded-' . $this->plugin_name);
811 }
812
813
814 /**
815 * Setups actions related with the Factory Plugin.
816 *
817 * @since 1.0.0
818 */
819 private function register_plugin_hooks()
820 {
821
822 add_action('plugins_loaded', function () {
823 $this->set_text_domain($this->plugin_text_domain, $this->paths->absolute);
824
825 if( !empty($this->loaded_plugin_components) ) {
826 foreach($this->loaded_plugin_components as $component) {
827 if( empty($component['text_domain']) ) {
828 continue;
829 }
830
831 $this->set_text_domain($component['text_domain'], $component['plugin_dir']);
832 }
833 }
834 });
835
836 if( is_admin() ) {
837 add_filter('wbcr_factory_480_core_admin_allow_multisite', '__return_true');
838
839 register_activation_hook($this->get_paths()->main_file, [$this, 'activation_hook']);
840 register_deactivation_hook($this->get_paths()->main_file, [$this, 'deactivation_hook']);
841 }
842 }
843
844 /**
845 * Инициализируем миграции плагина
846 *
847 * @return void
848 * @throws Exception
849 * @since 4.1.1
850 */
851 protected function init_plugin_migrations()
852 {
853 new WBCR\Factory_480\Migrations($this);
854 }
855
856 /**
857 * Инициализируем уведомления плагина
858 *
859 * @return void
860 * @since 4.1.1
861 */
862 protected function init_plugin_notices()
863 {
864 new Wbcr\Factory_480\Notices($this);
865 }
866
867 /**
868 * Создает нового рабочего для проверки обновлений и апгрейда текущего плагина.
869 *
870 * @param array $data
871 *
872 * @return void
873 * @throws Exception
874 * @since 4.1.1
875 *
876 */
877 protected function init_plugin_updates()
878 {
879 if( $this->has_updates ) {
880 new WBCR\Factory_480\Updates\Upgrader($this);
881 }
882 }
883 }
884
885