PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / trunk
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar vtrunk
3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.2 All 155 releases
notificationx / includes / Core / Modules.php

Modules.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar trunk, at includes/Core/Modules.php

103 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Extension Factory
4 *
5 * @package NotificationX\Extensions
6 */
7
8 namespace NotificationX\Core;
9
10 use NotificationX\Admin\Settings;
11 use NotificationX\GetInstance;
12
13 /**
14 * Modules Class
15 * @method static Modules get_instance($args = null)
16 */
17 class Modules {
18 /**
19 * Instance of Modules
20 *
21 * @var Modules
22 */
23 use GetInstance;
24
25 protected $modules = [];
26
27 /**
28 * Initially Invoked when initialized.
29 */
30 public function __construct(){
31 // echo 'ExtensionFactory';
32 add_filter('nx_settings_page_settings', [$this, 'modules_defaults']);
33 }
34
35 /**
36 * Adds a Module
37 *
38 * @param array $module
39 * @return array
40 */
41 public function add($module){
42 $this->modules[$module['value']] = $module;
43 return $module['value'];
44 }
45
46 /**
47 * Adds a Module
48 *
49 * @param array $module
50 * @return array
51 */
52 public function update($module, $key, $value){
53 if( !empty( $this->modules[$module] ) ) {
54 $this->modules[$module][$key] = $value;
55 return true;
56 }
57 return false;
58 }
59
60 /**
61 * Checks whether a module is enabled.
62 *
63 * @param string $module name of module
64 * @return boolean
65 */
66 public function is_enabled($module) {
67 $enabled_types = (array) Settings::get_instance()->get('settings.modules');
68 $module_key = $module ?? ''; // Use empty string if null
69 if( isset( $enabled_types[ $module_key ] ) && $enabled_types[ $module_key] ) {
70 return $enabled_types[ $module_key ];
71 } elseif( ! isset( $enabled_types[ $module_key ] ) ) {
72 return true;
73 }
74
75 return false;
76 }
77
78 /**
79 * Returns all the registered modules.
80 *
81 * @return array
82 */
83 public function get_all(){
84 return $this->modules;
85 }
86
87 public function modules_defaults($settings) {
88 if (!isset($settings) || !is_array($settings)) {
89 $settings = [];
90 }
91 if( !isset( $settings['modules'] ) || !is_array( $settings['modules'] ) ) {
92 $settings['modules'] = [];
93 }
94 $modules = $this->get_all();
95 foreach ($modules as $key => $value) {
96 if (!isset($settings['modules'][$key])) {
97 $settings['modules'][$key] = true;
98 }
99 }
100 return $settings;
101 }
102 }
103