PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / Settings.php
shop-press Last commit date
Admin 1 week ago Elementor 1 week ago Modules 1 week ago Templates 1 week ago blocks 1 week ago build 1 week ago includes 1 week ago languages 1 week ago public 1 week ago vendor 1 week ago Assets.php 1 year ago Plugin.php 1 week ago Settings.php 2 years ago changelog.txt 1 week ago readme.txt 1 week ago shop-press.php 1 week ago
Settings.php
127 lines
1 <?php
2 /**
3 * Settings.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress;
9
10 defined( 'ABSPATH' ) || exit;
11
12 class Settings {
13 /**
14 * Settings
15 *
16 * @var array
17 */
18 private static $settings = array();
19
20 /**
21 * Get settings.
22 *
23 * @since 1.0.0
24 */
25 public static function get_settings() {
26
27 if ( empty( static::$settings ) ) {
28
29 static::$settings = get_option( 'sp_admin' );
30
31 if ( ! is_array( static::$settings ) ) {
32 $settings = json_decode( static::$settings, true );
33
34 static::$settings = $settings;
35 }
36 }
37
38 return static::$settings;
39 }
40
41 /**
42 * Update settings.
43 *
44 * @since 1.2.0
45 */
46 public static function update_settings( $settings ) {
47
48 static::$settings = $settings;
49
50 update_option( 'sp_admin', json_encode( $settings ) );
51 }
52
53 /**
54 * Returns the component settings
55 *
56 * @param string $template_id
57 * @param string $setting_key
58 * @param mixed $default
59 *
60 * @since 1.2.0
61 *
62 * @return mixed
63 */
64 public static function get_template_settings( $template_id, $setting_key = null, $default = '' ) {
65 $settings = static::get_settings();
66
67 if ( ! is_null( $setting_key ) ) {
68
69 return $settings['templates'][ $template_id ][ $setting_key ] ?? $default;
70 }
71
72 return $settings['templates'][ $template_id ] ?? $default;
73 }
74
75 /**
76 * Returns the module settings
77 *
78 * @param string $module_id
79 * @param string $setting_key
80 * @param mixed $default
81 *
82 * @since 1.2.0
83 *
84 * @return array
85 */
86 public static function get_module_settings( $module_id, $setting_key = null, $default = '' ) {
87 $settings = static::get_settings();
88
89 if ( ! is_null( $setting_key ) ) {
90
91 return $settings['modules'][ $module_id ][ $setting_key ] ?? $default;
92 }
93
94 return $settings['modules'][ $module_id ] ?? $default;
95 }
96
97 /**
98 * Check the component status
99 *
100 * @param string $template_id
101 *
102 * @since 1.2.0
103 *
104 * @return boolean
105 */
106 public static function is_template_active( $template_id ) {
107 $settings = static::get_template_settings( $template_id );
108
109 return (bool) ( $settings['status'] ?? false );
110 }
111
112 /**
113 * Check the module status
114 *
115 * @param string $module_id
116 *
117 * @since 1.2.0
118 *
119 * @return boolean
120 */
121 public static function is_module_active( $module_id ) {
122 $settings = static::get_module_settings( $module_id );
123
124 return (bool) ( $settings['status'] ?? false );
125 }
126 }
127