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