-
Notifications
You must be signed in to change notification settings - Fork 0
/
qsm-theme-serene.php
239 lines (221 loc) · 5.95 KB
/
qsm-theme-serene.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
/**
* Plugin Name: QSM Theme - Serene
* Plugin URI: https://quizandsurveymaster.com
* Description: Free quiz theme for Quiz & Survey Master plugin
* Author: QSM Team
* Author URI: https://quizandsurveymaster.com
* Version: 1.0.0
*
* @author QSM Team
* @version 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* This class is the main class of the plugin
*
* When loaded, it loads the included plugin files and add functions to hooks or filters.
*
* @since 1.0.0
*/
class QSMThemeSerene {
/**
* Version Number
*
* @var string
* @since 1.0.0
*/
public $version = '1.0.0';
/**
* Main Construct Function
*
* Call functions within class
*
* @since 1.0.0
* @uses QSMThemeSerene::load_dependencies() Loads required filed
* @uses QSMThemeSerene::check_license() check license
* @uses QSMThemeSerene::add_hooks() Adds actions to hooks and filters
* @return void
*/
public function __construct() {
define( 'QSM_THEME_SERENE_VERSION', $this->version );
define( 'QSM_THEME_SERENE_URL', plugin_dir_url( __FILE__ ) );
define( 'QSM_THEME_SERENE_PATH', plugin_dir_path( __FILE__ ) );
define( 'QSM_THEME_SERENE_CSS_URL', QSM_THEME_SERENE_URL . 'css' );
define( 'QSM_THEME_SERENE_JS_URL', QSM_THEME_SERENE_URL . 'js' );
define( 'QSM_THEME_SERENE_PHP_DIR', QSM_THEME_SERENE_PATH . 'php' );
$this->load_dependencies();
$this->check_license();
$this->add_hooks();
}
/**
* Load File Dependencies
*
* @since 1.0.0
* @return void
*/
public function load_dependencies() {
include QSM_THEME_SERENE_PHP_DIR . '/license.php';
include QSM_THEME_SERENE_PHP_DIR . '/addon-settings-tab-content.php';
include QSM_THEME_SERENE_PHP_DIR . '/admin_hooks.php';
}
/**
* Add Hooks
*
* Adds functions to relavent hooks and filters
*
* @since 1.0.0
* @return void
*/
public function add_hooks() {
add_action( 'admin_init', 'qsm_addon_theme_serene_register_stats_tabs' );
}
/**
* Checks license
*
* Checks to see if license is active and, if so, checks for updates
*
* @since 1.0.0
* @return void
*/
public function check_license() {
if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
// Loads our custom updater.
include 'php/EDD_SL_Plugin_Updater.php';
}
// Retrieves our license key from the DB.
$settings = get_option( 'qsm_addon_theme_serene_settings', '' );
$license_key = isset( $settings['license_key'] ) ? trim( $settings['license_key'] ) : '';
// Sets up the updater.
$edd_updater = new EDD_SL_Plugin_Updater(
'https://quizandsurveymaster.com',
__FILE__,
array(
'version' => $this->version,
'license' => $license_key,
'item_name' => 'serene',
'author' => 'QSM Team',
)
);
}
/**
* Default settings value
*
* @since 1.0.0
* @return array
*/
public static function default_setting() {
$settings = array();
$settings[] = array(
'id' => 'background_color',
'label' => __( 'Background Color', 'qsm-theme-serene' ),
'type' => 'color',
'default' => '#ffffff',
);
$settings[] = array(
'id' => 'primary_color',
'label' => __( 'Primary Color', 'qsm-theme-serene' ),
'type' => 'color',
'default' => '#229ACD',
);
$settings[] = array(
'id' => 'secondary_color',
'label' => __( 'Secondary Color', 'qsm-theme-serene' ),
'type' => 'color',
'default' => '#ffffff',
);
$settings[] = array(
'id' => 'title_color',
'label' => __( 'Question Color', 'qsm-theme-serene' ),
'type' => 'color',
'default' => '#1D4759',
);
$settings[] = array(
'id' => 'text_color',
'label' => __( 'Text Color', 'qsm-theme-serene' ),
'type' => 'color',
'default' => '#547482',
);
return maybe_serialize( $settings );
}
}
add_action( 'plugins_loaded', 'qsm_addon_serene_load' );
/**
* Checks if QSM version 7.2.0 or above is installed
*
* @since 1.0.0
* @return void
*/
function qsm_addon_serene_load() {
$deactivate = true;
if ( class_exists( 'MLWQuizMasterNext' ) ) {
global $mlwQuizMasterNext;
$current_version = $mlwQuizMasterNext->version;
if ( version_compare( $current_version, '7.2.0', '>=' ) ) {
new QSMThemeSerene();
$deactivate = false;
} else {
add_action( 'admin_notices', 'qsm_addon_serene_version_qsm' );
}
} else {
add_action( 'admin_notices', 'qsm_addon_serene_missing_qsm' );
}
if ( $deactivate ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
$dir = basename( dirname( __FILE__ ) );
$file = basename( __FILE__ );
deactivate_plugins( $dir . '/' . $file );
}
}
/**
* Generates admin notice if QSM is not installed
*
* @since 1.0.0
* @return void
*/
function qsm_addon_serene_missing_qsm() {
echo '<div class="error"><p>QSM - Themes requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.</p></div>';
}
/**
* Genereates admin notice if installed QSM in below 7.2.0
*
* @return void
*/
function qsm_addon_serene_version_qsm() {
echo '<div class="error"><p>QSM - Themes requires at least Quiz And Survey Master V 7.2.0. Please update and reinstall</p></div>';
}
/**
* Updates theme and default settings
*/
register_activation_hook(
__FILE__,
function () {
if ( class_exists( 'MLWQuizMasterNext' ) ) {
global $mlwQuizMasterNext;
$current_version = $mlwQuizMasterNext->version;
if ( version_compare( $current_version, '7.2.0', '>=' ) ) {
$name = 'Serene';
$settings = QSMThemeSerene::default_setting();
$dir = basename( dirname( __FILE__ ) );
$mlwQuizMasterNext->theme_settings->update_theme_status( true, $dir, $name, $settings );
}
}
}
);
/**
* Deactivates theme
*/
register_deactivation_hook(
__FILE__,
function () {
if ( class_exists( 'MLWQuizMasterNext' ) ) {
global $mlwQuizMasterNext;
$current_version = $mlwQuizMasterNext->version;
if ( version_compare( $current_version, '7.2.0', '>=' ) ) {
$dir = basename( dirname( __FILE__ ) );
$mlwQuizMasterNext->theme_settings->update_theme_status( false, $dir );}
}
}
);