PluginProbe
Ultimate Post Kit / trunk
Ultimate Post Kit vtrunk
4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 All 145 releases
ultimate-post-kit / includes / modules-manager.php

modules-manager.php in Ultimate Post Kit trunk, at includes/modules-manager.php

136 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimatePostKit;
4
5 use UltimatePostKit\Admin\ModuleService;
6
7 if (!defined('ABSPATH')) {
8 exit;
9 } // Exit if accessed directly
10
11 if (!function_exists('is_plugin_active')) {
12 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
13 }
14
15 final class Manager
16 {
17 private $_modules = [];
18
19 private function is_module_active($module_id)
20 {
21
22 $module_data = $this->get_module_data($module_id);
23 $options = get_option('ultimate_post_kit_active_modules', []);
24
25 if (!isset($options[$module_id])) {
26 return $module_data['default_activation'];
27 } else {
28 if ($options[$module_id] == "on") {
29 return true;
30 } else {
31 return false;
32 }
33 }
34 }
35
36 private function has_module_style($module_id)
37 {
38
39 $module_data = $this->get_module_data($module_id);
40
41 if (isset($module_data['has_style'])) {
42 return $module_data['has_style'];
43 } else {
44 return false;
45 }
46 }
47 private function has_module_script($module_id)
48 {
49
50 $module_data = $this->get_module_data($module_id);
51
52 if (isset($module_data['has_script'])) {
53 return $module_data['has_script'];
54 } else {
55 return false;
56 }
57 }
58
59 private function get_module_data($module_id)
60 {
61 return isset($this->_modules[$module_id]) ? $this->_modules[$module_id] : false;
62 }
63
64 public function register_module_and_assets()
65 {
66
67 ModuleService::get_widget_settings(function ($settings) {
68 $core_widgets = $settings['settings_fields']['ultimate_post_kit_active_modules'];
69 $extensions = $settings['settings_fields']['ultimate_post_kit_elementor_extend'];
70 // $third_party_widgets = $settings['settings_fields']['ultimate_post_kit_third_party_widget'];
71
72 /**
73 * Our Widget
74 */
75 foreach ($core_widgets as $widget) {
76 if (ultimate_post_kit_is_widget_enabled($widget['name'])) {
77 $this->load_module_instance($widget);
78 }
79 }
80
81 /**
82 * Extension
83 */
84 foreach ($extensions as $extension) {
85 if (ultimate_post_kit_is_extend_enabled($extension['name'])) {
86 $this->load_module_instance($extension);
87 }
88 }
89
90 // Static module if need
91 $this->load_module_instance(['name' => 'elementor']);
92
93 });
94 }
95
96 public function load_module_instance($module)
97 {
98
99 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check of the current admin page slug for module-loading routing, no form data processed.
100 if(isset($_GET['page']) && 'ultimate_post_kit_options' == $_GET['page']){
101 return;
102 }
103
104 $direction = is_rtl() ? '.rtl' : '';
105 $suffix = '.min';
106
107 $module_id = $module['name'];
108 $class_name = str_replace('-', ' ', $module_id);
109 $class_name = str_replace(' ', '', ucwords($class_name));
110 $class_name = __NAMESPACE__ . '\\Modules\\' . $class_name . '\\Module';
111
112
113 if (!ultimate_post_kit_is_preview()) {
114 // register widgets css
115 if (ModuleService::has_module_style( $module_id, BDTUPK_MODULES_PATH )) {
116 wp_register_style('upk-' . $module_id, BDTUPK_URL . 'assets/css/upk-' . $module_id . $direction . '.css', [], BDTUPK_VER);
117 }
118 // register widget JS
119 if (ModuleService::has_module_script( $module_id, BDTUPK_MODULES_PATH )) {
120 wp_register_script('upk-' . $module_id, BDTUPK_URL . 'assets/js/widgets/upk-' . $module_id . $suffix . '.js', ['jquery'], BDTUPK_VER, true);
121 }
122 }
123
124
125 if (class_exists($class_name)) {
126 $class_name::instance();
127 }
128 }
129
130 public function __construct()
131 {
132
133 $this->register_module_and_assets();
134 }
135 }
136