| 1 |
<?php |
| 2 |
|
| 3 |
namespace PixelGallery; |
| 4 |
|
| 5 |
use PixelGallery\Admin\ModuleService; |
| 6 |
|
| 7 |
if (!defined('ABSPATH')) { |
| 8 |
exit; |
| 9 |
} // Exit if accessed directly |
| 10 |
|
| 11 |
final class Manager |
| 12 |
{ |
| 13 |
|
| 14 |
|
| 15 |
public function register_module_and_assets() |
| 16 |
{ |
| 17 |
|
| 18 |
ModuleService::get_widget_settings(function ($settings) { |
| 19 |
$core_widgets = $settings['settings_fields']['pixel_gallery_active_modules']; |
| 20 |
$extensions = $settings['settings_fields']['pixel_gallery_elementor_extend']; |
| 21 |
// $third_party_widgets = $settings['settings_fields']['pixel_gallery_third_party_widget']; |
| 22 |
|
| 23 |
/** |
| 24 |
* Our Widget |
| 25 |
*/ |
| 26 |
foreach ($core_widgets as $widget) { |
| 27 |
if (pixel_gallery_is_widget_enabled($widget['name'])) { |
| 28 |
$this->load_module_instance($widget); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Extension |
| 34 |
*/ |
| 35 |
foreach ($extensions as $extension) { |
| 36 |
if (pixel_gallery_is_extend_enabled($extension['name'])) { |
| 37 |
$this->load_module_instance($extension); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Third Party Widget |
| 43 |
*/ |
| 44 |
// foreach ($third_party_widgets as $widget) { |
| 45 |
// if (pixel_gallery_is_third_party_enabled($widget['name'])) { |
| 46 |
// if (isset($widget['plugin_path']) && ModuleService::is_plugin_active($widget['plugin_path'])) { |
| 47 |
// $this->load_module_instance($widget); |
| 48 |
// } |
| 49 |
// } |
| 50 |
// } |
| 51 |
// Static module if need |
| 52 |
$this->load_module_instance(['name' => 'elementor']); |
| 53 |
}); |
| 54 |
} |
| 55 |
|
| 56 |
public function load_module_instance($module) |
| 57 |
{ |
| 58 |
|
| 59 |
$direction = is_rtl() ? '.rtl' : ''; |
| 60 |
|
| 61 |
$module_id = $module['name']; |
| 62 |
$class_name = str_replace('-', ' ', $module_id); |
| 63 |
$class_name = str_replace(' ', '', ucwords($class_name)); |
| 64 |
$class_name = __NAMESPACE__ . '\\Modules\\' . $class_name . '\\Module'; |
| 65 |
|
| 66 |
if (!pixel_gallery_is_asset_optimization_enabled()) { |
| 67 |
if (!pixel_gallery_is_preview()) { |
| 68 |
// register widgets css |
| 69 |
if (ModuleService::has_module_style($module_id)) { |
| 70 |
wp_register_style('pg-' . $module_id, BDTPG_URL . 'assets/css/pg-' . $module_id . '.css', [], BDTPG_VER); |
| 71 |
} |
| 72 |
|
| 73 |
// register widget JS |
| 74 |
if (ModuleService::has_module_script($module_id)) { |
| 75 |
wp_register_script('pg-' . $module_id, BDTPG_URL . 'assets/js/modules/pg-' . $module_id . '.min.js', ['jquery', 'elementor-frontend'], BDTPG_VER, true); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
if (class_exists($class_name)) { |
| 81 |
$class_name::instance(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public function __construct() |
| 86 |
{ |
| 87 |
|
| 88 |
$this->register_module_and_assets(); |
| 89 |
} |
| 90 |
} |
| 91 |
|