forked from QuizandSurveyMaster/quiz_master_next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlw_quizmaster2.php
301 lines (265 loc) · 9.48 KB
/
mlw_quizmaster2.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
/**
* Plugin Name: Quiz And Survey Master
* Description: Easily and quickly add quizzes and surveys to your website.
* Version: 6.2.0
* Author: Frank Corso
* Author URI: https://www.quizandsurveymaster.com/
* Plugin URI: https://www.quizandsurveymaster.com/
* Text Domain: quiz-master-next
*
* @author Frank Corso
* @version 6.2.0
* @package QSM
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'QSM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
/**
* This class is the main class of the plugin
*
* When loaded, it loads the included plugin files and add functions to hooks or filters. The class also handles the admin menu
*
* @since 3.6.1
*/
class MLWQuizMasterNext {
/**
* QSM Version Number
*
* @var string
* @since 4.0.0
*/
public $version = '6.2.0';
/**
* QSM Alert Manager Object
*
* @var object
* @since 3.7.1
*/
public $alertManager;
/**
* QSM Plugin Helper Object
*
* @var object
* @since 4.0.0
*/
public $pluginHelper;
/**
* QSM Quiz Creator Object
*
* @var object
* @since 3.7.1
*/
public $quizCreator;
/**
* QSM Log Manager Object
*
* @var object
* @since 4.5.0
*/
public $log_manager;
/**
* QSM Audit Manager Object
*
* @var object
* @since 4.7.1
*/
public $audit_manager;
/**
* QSM Settings Object
*
* @var object
* @since 5.0.0
*/
public $quiz_settings;
/**
* Main Construct Function
*
* Call functions within class
*
* @since 3.6.1
* @uses MLWQuizMasterNext::load_dependencies() Loads required filed
* @uses MLWQuizMasterNext::add_hooks() Adds actions to hooks and filters
* @return void
*/
public function __construct() {
$this->load_dependencies();
$this->add_hooks();
}
/**
* Load File Dependencies
*
* @since 3.6.1
* @return void
*/
private function load_dependencies() {
include 'php/classes/class-qsm-install.php';
include 'php/classes/class-qsm-fields.php';
include 'php/classes/class-qmn-log-manager.php';
$this->log_manager = new QMN_Log_Manager();
include 'php/classes/class-qsm-audit.php';
$this->audit_manager = new QSM_Audit();
if ( is_admin() ) {
include 'php/admin/stats-page.php';
include 'php/admin/quizzes-page.php';
include 'php/admin/quiz-options-page.php';
include 'php/admin/admin-results-page.php';
include 'php/admin/admin-results-details-page.php';
include 'php/admin/tools-page.php';
include 'php/classes/class-qsm-changelog-generator.php';
include 'php/admin/about-page.php';
include 'php/admin/help-page.php';
include 'php/admin/dashboard-widgets.php';
include 'php/admin/options-page-questions-tab.php';
include 'php/admin/options-page-contact-tab.php';
include 'php/admin/options-page-text-tab.php';
include 'php/admin/options-page-option-tab.php';
include 'php/admin/options-page-email-tab.php';
include 'php/admin/options-page-results-page-tab.php';
include 'php/admin/options-page-style-tab.php';
include 'php/admin/options-page-preview-tab.php';
include 'php/admin/addons-page.php';
include 'php/admin/settings-page.php';
include 'php/classes/class-qsm-tracking.php';
include 'php/classes/class-qmn-review-message.php';
include 'php/gdpr.php';
}
include 'php/classes/class-qsm-questions.php';
include 'php/classes/class-qsm-contact-manager.php';
include 'php/classes/class-qsm-results-pages.php';
include 'php/classes/class-qsm-emails.php';
include 'php/classes/class-qmn-quiz-manager.php';
include 'php/template-variables.php';
include 'php/adverts-generate.php';
include 'php/question-types.php';
include 'php/default-templates.php';
include 'php/shortcodes.php';
if ( function_exists( 'register_block_type' ) ) {
include 'blocks/block.php';
}
include 'php/classes/class-qmn-alert-manager.php';
$this->alertManager = new MlwQmnAlertManager();
include 'php/classes/class-qmn-quiz-creator.php';
$this->quizCreator = new QMNQuizCreator();
include 'php/classes/class-qmn-plugin-helper.php';
$this->pluginHelper = new QMNPluginHelper();
include 'php/classes/class-qsm-settings.php';
$this->quiz_settings = new QSM_Quiz_Settings();
include 'php/rest-api.php';
}
/**
* Add Hooks
*
* Adds functions to relavent hooks and filters
*
* @since 3.6.1
* @return void
*/
private function add_hooks() {
add_action( 'admin_menu', array( $this, 'setup_admin_menu' ) );
add_action( 'admin_head', array( $this, 'admin_head' ), 900 );
add_action( 'init', array( $this, 'register_quiz_post_types' ) );
}
/**
* Creates Custom Quiz Post Type
*
* @since 4.1.0
* @return void
*/
public function register_quiz_post_types() {
// Checks settings to see if we need to alter the defaults.
$has_archive = true;
$exclude_search = false;
$cpt_slug = 'quiz';
$settings = (array) get_option( 'qmn-settings' );
$plural_name = __( 'Quizzes & Surveys', 'quiz-master-next' );
// Checks if admin turned off archive.
if ( isset( $settings['cpt_archive'] ) && '1' == $settings['cpt_archive'] ) {
$has_archive = false;
}
// Checks if admin turned off search.
if ( isset( $settings['cpt_search'] ) && '1' == $settings['cpt_search'] ) {
$exclude_search = true;
}
// Checks if admin changed slug.
if ( isset( $settings['cpt_slug'] ) ) {
$cpt_slug = trim( strtolower( str_replace( ' ', '-', $settings['cpt_slug'] ) ) );
}
// Checks if admin changed plural name.
if ( isset( $settings['plural_name'] ) ) {
$plural_name = trim( $settings['plural_name'] );
}
// Prepares labels.
$quiz_labels = array(
'name' => $plural_name,
'singular_name' => __( 'Quiz', 'quiz-master-next' ),
'menu_name' => __( 'Quiz', 'quiz-master-next' ),
'name_admin_bar' => __( 'Quiz', 'quiz-master-next' ),
'add_new' => __( 'Add New', 'quiz-master-next' ),
'add_new_item' => __( 'Add New Quiz', 'quiz-master-next' ),
'new_item' => __( 'New Quiz', 'quiz-master-next' ),
'edit_item' => __( 'Edit Quiz', 'quiz-master-next' ),
'view_item' => __( 'View Quiz', 'quiz-master-next' ),
'all_items' => __( 'All Quizzes', 'quiz-master-next' ),
'search_items' => __( 'Search Quizzes', 'quiz-master-next' ),
'parent_item_colon' => __( 'Parent Quiz:', 'quiz-master-next' ),
'not_found' => __( 'No Quiz Found', 'quiz-master-next' ),
'not_found_in_trash' => __( 'No Quiz Found In Trash', 'quiz-master-next' ),
);
// Prepares post type array.
$quiz_args = array(
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'show_in_nav_menus' => true,
'labels' => $quiz_labels,
'publicly_queryable' => true,
'exclude_from_search' => $exclude_search,
'label' => $plural_name,
'rewrite' => array( 'slug' => $cpt_slug ),
'has_archive' => $has_archive,
'supports' => array( 'title', 'author', 'comments' )
);
// Registers post type.
register_post_type( 'quiz', $quiz_args );
}
/**
* Setup Admin Menu
*
* Creates the admin menu and pages for the plugin and attaches functions to them
*
* @since 3.6.1
* @return void
*/
public function setup_admin_menu() {
if ( function_exists( 'add_menu_page' ) ) {
add_menu_page( 'Quiz And Survey Master', __( 'Quizzes/Surveys', 'quiz-master-next' ), 'moderate_comments', __FILE__, 'qsm_generate_quizzes_surveys_page', 'dashicons-feedback' );
add_submenu_page( __FILE__, __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_options', 'qsm_generate_quiz_options' );
add_submenu_page( __FILE__, __( 'Results', 'quiz-master-next' ), __( 'Results', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_results', 'qsm_generate_admin_results_page' );
add_submenu_page( __FILE__, __( 'Result Details', 'quiz-master-next' ), __( 'Result Details', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_result_details', 'qsm_generate_result_details' );
add_submenu_page( __FILE__, __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), 'manage_options', 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) );
add_submenu_page( __FILE__, __( 'Tools', 'quiz-master-next' ), __( 'Tools', 'quiz-master-next' ), 'manage_options', 'qsm_quiz_tools', 'qsm_generate_quiz_tools' );
add_submenu_page( __FILE__, __( 'Stats', 'quiz-master-next' ), __( 'Stats', 'quiz-master-next' ), 'moderate_comments', 'qmn_stats', 'qmn_generate_stats_page' );
add_submenu_page( __FILE__, __( 'Addon Settings', 'quiz-master-next' ), __( 'Addon Settings', 'quiz-master-next' ), 'moderate_comments', 'qmn_addons', 'qmn_addons_page' );
add_submenu_page( __FILE__, __( 'QSM About', 'quiz-master-next' ), __( 'QSM About', 'quiz-master-next' ), 'moderate_comments', 'qsm_about_page', 'qsm_generate_about_page' );
add_submenu_page( __FILE__, __( 'Help', 'quiz-master-next' ), __( 'Help', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_help', 'qsm_generate_help_page' );
}
}
/**
* Removes Unnecessary Admin Page
*
* Removes the update, quiz settings, and quiz results pages from the Quiz Menu
*
* @since 4.1.0
* @return void
*/
public function admin_head() {
remove_submenu_page( 'quiz-master-next/mlw_quizmaster2.php', 'mlw_quiz_options' );
remove_submenu_page( 'quiz-master-next/mlw_quizmaster2.php', 'qsm_quiz_result_details' );
}
}
global $mlwQuizMasterNext;
$mlwQuizMasterNext = new MLWQuizMasterNext();
register_activation_hook( __FILE__, array( 'QSM_Install', 'install' ) );
?>