PluginProbe
Watu Quiz / 3.4.7
Watu Quiz v3.4.7
3.4.8 trunk 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.5.3 3.4.6 3.4.7
watu / watu.php

watu.php in Watu Quiz 3.4.7, at watu.php

468 lines 19.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 *Plugin Name: Watu Quiz
4 *Plugin URI: http://calendarscripts.info/watu-wordpress.html
5 *Description: Create exams and quizzes and display the result immediately after the user takes the exam. Watu for Wordpress is a light version of <a href="http://calendarscripts.info/watupro/" target="_blank">WatuPRO</a>. Check it if you want to run fully featured exams with data exports, student logins, timers, random questions and more. Free support and upgrades are available. Go to <a href="admin.php?page=watu_settings">Watu Settings</a> or <a href="tools.php?page=watu_exams">Manage Your Exams</a>
6
7 *Version: 3.4.7
8 *Author: Kiboko Labs
9 *License: GPLv2 or later
10 *Text domain: watu
11 *Domain Path: /languages
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27
28 define( 'WATU_PATH', dirname( __FILE__ ) );
29 define( 'WATU_URL', plugin_dir_url( __FILE__ ));
30 include( WATU_PATH.'/controllers/exam.php');
31 include( WATU_PATH.'/controllers/questions.php');
32 include( WATU_PATH.'/controllers/takings.php');
33 include( WATU_PATH.'/controllers/ajax.php');
34 include( WATU_PATH.'/controllers/grades.php');
35 include( WATU_PATH.'/controllers/social-sharing.php');
36 include( WATU_PATH.'/models/question.php');
37 include( WATU_PATH.'/lib/functions.php');
38 include( WATU_PATH.'/lib/text-captcha.php');
39 include( WATU_PATH."/models/exam.php");
40 include( WATU_PATH.'/controllers/shortcodes.php');
41
42 function watu_init() {
43 global $wpdb;
44
45 load_plugin_textdomain('watu', false, dirname( plugin_basename( __FILE__ )).'/langs/' );
46
47 if(get_option('watu_debug_mode')) {
48 $wpdb->show_errors();
49 if(!defined('DIEONDBERROR')) define( 'DIEONDBERROR', true );
50 }
51
52 $version = get_bloginfo('version');
53 if($version <= 3.3) add_action('wp_enqueue_scripts', 'watu_vc_scripts');
54 add_action('admin_enqueue_scripts', 'watu_vc_scripts');
55 add_action('wp_enqueue_scripts', 'watu_vc_jquery');
56
57 add_shortcode( 'WATU', 'watu_shortcode' );
58 add_shortcode( 'watu', 'watu_shortcode' );
59 add_shortcode( 'watushare-buttons', array('WatuSharing', 'display') );
60 add_shortcode( 'watu-basic-chart', 'watu_basic_chart' );
61 add_shortcode( 'watu-takings', 'watu_shortcode_takings' );
62 add_shortcode( 'watu-userinfo', array('WatuShortcodes', 'userinfo') );
63
64 // table names as constants
65 define('WATU_EXAMS', $wpdb->prefix.'watu_master');
66 define('WATU_QUESTIONS', $wpdb->prefix.'watu_question');
67 define('WATU_ANSWERS', $wpdb->prefix.'watu_answer');
68 define('WATU_GRADES', $wpdb->prefix.'watu_grading');
69 define('WATU_TAKINGS', $wpdb->prefix.'watu_takings');
70 define('WATU_QCATS', $wpdb->prefix.'watu_qcats');
71
72 // which filter to use
73 $content_filter = get_option('watu_use_the_content') ? 'the_content' : 'watu_content';
74 define('WATU_CONTENT_FILTER', $content_filter);
75
76 // word used for quiz
77 $quiz_word = get_option('watu_quiz_word');
78 $quiz_word = $quiz_word ? $quiz_word : __('quiz', 'watu');
79 $quiz_word_plural = get_option('watu_quiz_word_plural');
80 $quiz_word_plural = $quiz_word_plural ? $quiz_word_plural : __('quizzes', 'watu');
81 define('WATU_QUIZ_WORD', $quiz_word);
82 define('WATU_QUIZ_WORD_PLURAL', $quiz_word_plural);
83
84 // handle tablepress
85 if(class_exists('TablePress')) {
86 //TablePress::$controller = TablePress::load_controller( 'frontend' );
87 //TablePress::$controller->init_shortcodes();
88 }
89
90 // add_filter( 'watu_content', 'watu_autop' );
91 add_filter( 'watu_content', 'wptexturize' );
92 // add_filter( 'watu_content', 'convert_smilies' );
93 add_filter( 'watu_content', 'convert_chars' );
94 add_filter( 'watu_content', 'shortcode_unautop' );
95 add_filter( 'watu_content', 'do_shortcode' );
96
97 // Compatibility with specific plugins
98 // qTranslate
99 if(function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) add_filter('watu_content', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage');
100 // WP QuickLaTeX
101 if(function_exists('quicklatex_parser')) add_filter( 'watu_content', 'quicklatex_parser', 7);
102 // handle the MoolaMojo integration
103 add_action('watu_exam_submitted_detailed', 'watu_taking_transfer_moola', 10, 5);
104
105 $version = get_option('watu_version');
106 if(version_compare($version, '2.88') == -1) watu_activate(true);
107
108 add_action('admin_notices', 'watu_admin_notice');
109 }
110
111 function watu_autop($content) {
112 //return wpautop($content, false);
113 return nl2br($content);
114 }
115
116 /**
117 * Add a new menu under Manage, visible for all users with template viewing level.
118 */
119 add_action( 'admin_menu', 'watu_add_menu_links' );
120 add_action ( 'watu_exam', 'watu_exam' );
121 function watu_add_menu_links() {
122 global $wp_version, $_registered_pages;
123 $view_level = current_user_can('watu_manage') ? 'watu_manage' : 'manage_options';
124
125
126 add_menu_page(sprintf(__('Watu %s', 'watu'), ucfirst(WATU_QUIZ_WORD_PLURAL)), sprintf(__('Watu %s', 'watu'), ucfirst(WATU_QUIZ_WORD_PLURAL)), $view_level, 'watu_exams', 'watu_exams');
127 add_submenu_page('watu_exams', __('Settings', 'watu'), __('Settings', 'watu'), $view_level , 'watu_options', 'watu_options');
128 add_submenu_page('watu_exams', __('Social Sharing', 'watu'), __('Social Sharing', 'watu'), $view_level , 'watu_social_sharing', array('WatuSharing', 'options'));
129 add_submenu_page('watu_exams', __('Help &amp; Support', 'watu'), __('Help &amp; Support', 'watu'), $view_level , 'watu_help', 'watu_help');
130
131 do_action('watu_admin_menu');
132
133 // hidden pages
134 add_submenu_page("", sprintf(__('Add/Edit %s', 'watu'), ucfirst(WATU_QUIZ_WORD)), sprintf(__('Add/Edit %s', 'watu'), ucfirst(WATU_QUIZ_WORD)), $view_level , 'watu_exam', 'watu_exam');
135
136 add_submenu_page('', __('Manage Questions', 'watu'), __('Manage Questions', 'watu'), $view_level , 'watu_questions', 'watu_questions');
137 add_submenu_page('', __('Add/Edit Question', 'watu'), __('Add/Edit Question', 'watu'), $view_level , 'watu_question', 'watu_question');
138 add_submenu_page('', __('Manage Grades', 'watu'), __('Manage Grades', 'watu'), $view_level , 'watu_grades', 'watu_grades');
139 add_submenu_page('', sprintf(__('%s submissions', 'watu'), ucfirst(WATU_QUIZ_WORD)), sprintf(__('%s submissions', 'watu'), ucfirst(WATU_QUIZ_WORD)), $view_level, 'watu_takings', 'watu_takings');
140 add_submenu_page('', __('Import Questions', 'watu'), __('Import Questions', 'watu'), $view_level, 'watu_import_questions', 'watu_import_questions');
141
142 }
143
144 function watu_options() {
145 if ( function_exists('current_user_can') && !current_user_can('manage_options') ) die(__("Your are not allowed to to perform this operation", 'watu'));
146 if (! user_can_access_admin_page()) wp_die( __('You do not have sufficient permissions to access this page', 'watu') );
147
148 require(WATU_PATH.'/options.php');
149 }
150
151 /**
152 * This will scan all the content pages that WordPress outputs for our special code. If the code is found, it will replace the requested quiz.
153 */
154 function watu_shortcode( $attr ) {
155 $exam_id = $attr[0] ?? 0;
156
157 $contents = '';
158 if(!is_numeric($exam_id)) return $contents;
159
160 watu_vc_scripts();
161
162 // submitting without ajax?
163 if(!empty($_POST['no_ajax']) and !empty($exam->no_ajax)) {
164 require(WATU_PATH."/show_exam.php");
165 $contents = ob_get_clean();
166 $contents = apply_filters('watu_content', $contents);
167 return $contents;
168 }
169
170 ob_start();
171 include(WATU_PATH . '/controllers/show_exam.php');
172 $contents = ob_get_contents();
173 ob_end_clean();
174
175 return $contents;
176 }
177
178 add_action('activate_watu/watu.php','watu_activate');
179 function watu_activate($update = false) {
180 global $wpdb;
181
182 $wpdb-> show_errors();
183 $collation = $wpdb->get_charset_collate();
184 $version = get_option('watu_version');
185 if(!$update) watu_init();
186
187 // Initial options.
188 update_option('watu_show_answers', 1, false);
189 update_option('watu_single_page', 0, false);
190 update_option('watu_answer_type', 'radio', false);
191
192 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
193
194 if($wpdb->get_var("SHOW TABLES LIKE '".WATU_EXAMS."'") != WATU_EXAMS) {
195 $sql = "CREATE TABLE `".WATU_EXAMS."`(
196 ID int(11) unsigned NOT NULL auto_increment,
197 name varchar(50) NOT NULL DEFAULT '',
198 description mediumtext NOT NULL,
199 final_screen mediumtext NOT NULL,
200 added_on datetime NOT NULL DEFAULT '1900-01-01',
201 PRIMARY KEY (ID)
202 ) $collation ";
203 $wpdb->query($sql);
204 }
205
206 if($wpdb->get_var("SHOW TABLES LIKE '".WATU_QUESTIONS."'") != WATU_QUESTIONS) {
207 $sql = "CREATE TABLE ".WATU_QUESTIONS." (
208 ID int(11) unsigned NOT NULL auto_increment,
209 exam_id int(11) unsigned NOT NULL DEFAULT 0,
210 question mediumtext NOT NULL,
211 answer_type char(15) NOT NULL DEFAULT '',
212 sort_order int(3) NOT NULL default 0,
213 PRIMARY KEY (ID),
214 KEY quiz_id (exam_id)
215 ) $collation";
216 $wpdb->query($sql);
217 }
218
219 if($wpdb->get_var("SHOW TABLES LIKE '".WATU_ANSWERS."'") != WATU_ANSWERS) {
220 $sql = "CREATE TABLE ".WATU_ANSWERS." (
221 ID int(11) unsigned NOT NULL auto_increment,
222 question_id int(11) unsigned NOT NULL,
223 answer TEXT,
224 correct enum('0','1') NOT NULL default '0',
225 point DECIMAL(8,2) NOT NULL default '0.00',
226 sort_order int(3) NOT NULL default 0,
227 PRIMARY KEY (ID)
228 ) $collation";
229 $wpdb->query($sql);
230 }
231
232 if($wpdb->get_var("SHOW TABLES LIKE '".WATU_GRADES."'") != WATU_GRADES) {
233 $sql = "CREATE TABLE `".WATU_GRADES."` (
234 `ID` int(11) NOT NULL AUTO_INCREMENT,
235 `exam_id` int(11) NOT NULL DEFAULT 0,
236 `gtitle` varchar (255) NOT NULL DEFAULT '',
237 `gdescription` mediumtext NOT NULL,
238 `gfrom` DECIMAL(8,2) NOT NULL default '0.00',
239 `gto` DECIMAL(8,2) NOT NULL default '0.00',
240 PRIMARY KEY (`ID`)
241 ) $collation";
242 $wpdb->query($sql);
243 }
244
245 if($wpdb->get_var("SHOW TABLES LIKE '".WATU_TAKINGS."'") != WATU_TAKINGS) {
246 $sql = "CREATE TABLE `".WATU_TAKINGS."` (
247 `ID` int(11) NOT NULL AUTO_INCREMENT,
248 `exam_id` int(11) NOT NULL DEFAULT 0,
249 `user_id` int(11) NOT NULL DEFAULT 0,
250 `ip` varchar(20) NOT NULL DEFAULT '',
251 `date` DATE NOT NULL DEFAULT '1900-01-01',
252 `points` INT NOT NULL DEFAULT 0,
253 `grade_id` INT UNSIGNED NOT NULL DEFAULT 0,
254 PRIMARY KEY (`ID`)
255 ) $collation";
256 $wpdb->query($sql);
257 }
258
259 // Question categories
260 $sql = "CREATE TABLE " . WATU_QCATS . " (
261 ID int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
262 name varchar(255) NOT NULL DEFAULT '',
263 PRIMARY KEY (ID)
264 ) $collation";
265 dbDelta( $sql );
266
267 watu_add_db_fields(array(
268 array("name"=>"randomize", "type"=>"TINYINT NOT NULL DEFAULT 0"),
269 array("name"=>"single_page", "type"=>"TINYINT NOT NULL DEFAULT 0"),
270 array("name"=>"show_answers", "type"=>"TINYINT NOT NULL DEFAULT 100"),
271 array("name"=>"require_login", "type"=>"TINYINT NOT NULL DEFAULT 0"),
272 array("name"=>"notify_admin", "type"=>"TINYINT NOT NULL DEFAULT 0"),
273 array("name"=>"randomize_answers", "type"=>"TINYINT NOT NULL DEFAULT 0"),
274 array("name"=>"pull_random", "type"=>"INT UNSIGNED NOT NULL DEFAULT 0"),
275 array("name"=>"dont_store_data", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
276 array("name"=>"show_prev_button", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
277 array("name"=>"dont_display_question_numbers", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
278 array("name"=>"require_text_captcha", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
279 array("name"=>"email_output", "type"=>"TEXT"),
280 array("name"=>"notify_user", "type"=>"TINYINT NOT NULL DEFAULT 0"),
281 array("name"=>"notify_email", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"),
282 array("name"=>"take_again", "type"=>"TINYINT NOT NULL DEFAULT 0"),
283 array("name"=>"times_to_take", "type"=>"TINYINT NOT NULL DEFAULT 0"),
284 array("name"=>"no_ajax", "type"=>"TINYINT NOT NULL DEFAULT 0"), /* don't use Ajax when submitting this quiz */
285 array("name"=>"no_alert_unanswered", "type"=>"TINYINT NOT NULL DEFAULT 0"), /* don't alert users for non-answering optional question */
286 array("name"=>"use_honeypot", "type"=>"TINYINT NOT NULL DEFAULT 0"),
287 array("name"=>"save_source_url", "type"=>"TINYINT NOT NULL DEFAULT 0"),
288 array("name"=>"advanced_settings", "type"=>"TEXT"),
289 array("name"=>"email_subject", "type"=>"TEXT"),
290 array("name"=>"is_scheduled", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
291 array("name"=>"schedule_from", "type"=>"DATETIME"),
292 array("name"=>"schedule_to", "type"=>"DATETIME"),
293 ), WATU_EXAMS);
294
295 watu_add_db_fields(array(
296 array("name"=>"redirect_url", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"),
297 array("name" => 'moola', "type" => "INT NOT NULL DEFAULT 0"), // integration with MoolaMojo
298 ), WATU_GRADES);
299
300 // db updates in 1.8
301 if(empty($version) or $version < 1.8) {
302 // let all existing exams follow the default option
303 $sql = "UPDATE ".WATU_EXAMS." SET single_page = '".get_option('watu_single_page')."'";
304 $wpdb->query($sql);
305 }
306
307 watu_add_db_fields(array(
308 array("name"=>"is_required", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
309 array("name"=>"feedback", "type"=>"TEXT"),
310 array("name"=>"is_inactive", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
311 array("name"=>"is_survey", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
312 array("name" => "num_columns", "type" => "TINYINT NOT NULL DEFAULT 0"), // num columns for the choices 1 to 4
313 array("name" => "cat_id", "type" => "INT NOT NULL DEFAULT 0"),
314 ), WATU_QUESTIONS);
315
316 watu_add_db_fields(array(
317 array("name"=>"result", "type"=>"TEXT"),
318 array("name"=>"snapshot", "type"=>"MEDIUMTEXT"),
319 array("name"=>"start_time", "type"=>"DATETIME"),
320 array("name"=>"email", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"), /* when email is given, let's store it */
321 array("name"=>"percent_correct", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"),
322 array("name"=>"source_url", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"),
323 array("name"=>"num_correct", "type"=>"SMALLINT NOT NULL DEFAULT 0"),
324 array("name"=>"num_wrong", "type"=>"SMALLINT NOT NULL DEFAULT 0"),
325 array("name"=>"num_empty", "type"=>"SMALLINT NOT NULL DEFAULT 0"),
326 ), WATU_TAKINGS);
327
328 // let's change choice and answer fields to TEXT instead of VARCHAR - 2.1.3
329 if(empty($version) or $version < 2.1) {
330 // let all existing exams follow the default option
331 $sql = "ALTER TABLE ".WATU_ANSWERS." CHANGE answer answer TEXT";
332 $wpdb->query($sql);
333 }
334
335 $demo_quiz_created = get_option('watu_demo_quiz_created');
336 if($demo_quiz_created != '1') WatuExam :: create_demo();
337
338 // versions before 2.44 had the following text hard-coded. We need to make sure thta the quizzes which were showing results
339 // now have it in the "final screen"
340 if(!empty($version) and $version < 2.45) {
341 $answers_text = "<p>" . __('All the questions in the quiz along with their answers are shown below. Your answers are bolded. The correct answers have a green background while the incorrect ones have a red background.', 'watu') . "</p> %%ANSWERS%%";
342 $wpdb->query("UPDATE ".WATU_EXAMS." SET final_screen = CONCAT(final_screen, '$answers_text') WHERE show_answers=1");
343 }
344
345 // let all quizzes prior to DB version 2.49 have dont_display_question_numbers = 1 because this is how it was
346 if(!empty($version) and $version < 2.49) {
347 $wpdb->query("UPDATE ".WATU_EXAMS." SET dont_display_question_numbers=1");
348 }
349
350 // let's make all "require_login" quizzes created previously to have take_again=1 to avoid sudden change
351 if(!empty($version) and $version < 2.56) {
352 $wpdb->query("UPDATE ".WATU_EXAMS." SET take_again=1 WHERE require_login=1");
353 }
354
355 // change points in answers & grades to decimals
356 if(!empty($version) and $version < 2.64) {
357 $wpdb->query("ALTER TABLE ".WATU_ANSWERS." CHANGE `point` `point` DECIMAL(8,2) NOT NULL DEFAULT '0.00'");
358 $wpdb->query("ALTER TABLE ".WATU_GRADES." CHANGE `gfrom` `gfrom` DECIMAL(8,2) NOT NULL DEFAULT '0.00',
359 CHANGE `gto` `gto` DECIMAL(8,2) NOT NULL DEFAULT '0.00'");
360 }
361
362 // add indexes
363 if(version_compare($version, '2.88') == -1) {
364 $wpdb->query("ALTER TABLE ".WATU_ANSWERS." ADD INDEX `quesiton_id` (`question_id`);");
365 $wpdb->query("ALTER TABLE ".WATU_GRADES." ADD INDEX `quiz_and_criteria` (`exam_id`, `gfrom`, `gto`);");
366 $wpdb->query("ALTER TABLE ".WATU_EXAMS." ADD INDEX `name` (`name`);");
367 $wpdb->query("ALTER TABLE ".WATU_QUESTIONS." ADD INDEX `exam_id` (`exam_id`);");
368 $wpdb->query("ALTER TABLE ".WATU_QUESTIONS." ADD INDEX `cat_id` (`cat_id`);");
369 $wpdb->query("ALTER TABLE ".WATU_TAKINGS." ADD INDEX `exam_user` (`exam_id`, `user_id`);");
370 }
371
372 update_option( "watu_delete_db", '', false );
373 update_option( "watu_version", '2.88', false );
374
375 update_option('watu_admin_notice', __('<h2>Thank you for activating Watu!</h2> <p>Please go to your <a href="admin.php?page=watu_exams">Quizzes page</a> to get started! If this is the first time you have activated the plugin there will be a small demo quiz automatically created for you. Feel free to explore it to get better idea how things work.</p>', 'watu'));
376 }
377
378 function watu_admin_notice() {
379 $notice = get_option('watu_admin_notice');
380 if(!empty($notice)) {
381 echo "<div class='updated'>".stripslashes($notice)."</div>";
382 }
383 // once shown, cleanup
384 update_option('watu_admin_notice', '', false);
385 }
386
387 function watu_vc_scripts() {
388 wp_enqueue_script('jquery');
389 if(is_admin()) wp_enqueue_script('jquery-ui-sortable');
390
391 wp_enqueue_style(
392 'watu-style',
393 WATU_URL.'style.css',
394 array(),
395 '2.3.8'
396 );
397
398 wp_enqueue_script(
399 'watu-script',
400 WATU_URL.'script.js',
401 array(),
402 '2.4.4'
403 );
404
405 $translation_array = array(
406 'missed_required_question' => __('You have missed to answer a required question', 'watu'),
407 'nothing_selected' => __('You did not select any answer. Are you sure you want to continue?', 'watu'),
408 'show_answer' => __('Show Answer', 'watu'),
409 'complete_text_captcha' => __('You need to answer the verification question', 'watu'),
410 'try_again' => __('Try again', 'watu'),
411 'email_required' => __('Valid email address is required.', 'watu'),
412 'next_q' => __("Next >", 'watu'),
413 'please_wait' => __('Please wait...', 'watu'),
414 'ajax_url' => admin_url('admin-ajax.php'),
415 'watu_nonce' => wp_create_nonce('watu_reorder_questions'),
416 );
417 wp_localize_script( 'watu-script', 'watu_i18n', $translation_array );
418
419 $appid = get_option('watuproshare_facebook_appid');
420 }
421
422 function watu_vc_jquery() {
423 wp_enqueue_script('jquery');
424 }
425
426 // function to conditionally add DB fields
427 function watu_add_db_fields($fields, $table) {
428 global $wpdb;
429
430 // check fields
431 $table_fields = $wpdb->get_results("SHOW COLUMNS FROM `$table`");
432 $table_field_names = array();
433 foreach($table_fields as $f) $table_field_names[] = $f->Field;
434 $fields_to_add=array();
435
436 foreach($fields as $field) {
437 if(!in_array($field['name'], $table_field_names)) {
438 $fields_to_add[] = $field;
439 }
440 }
441
442 // now if there are fields to add, run the query
443 if(!empty($fields_to_add)) {
444 $sql = "ALTER TABLE `$table` ";
445
446 foreach($fields_to_add as $cnt => $field) {
447 if($cnt > 0) $sql .= ", ";
448 $sql .= "ADD $field[name] $field[type]";
449 }
450
451 $wpdb->query($sql);
452 }
453 }
454
455 function watu_help() {
456 include(WATU_PATH. "/views/help.html.php");
457 }
458
459 add_action('init', 'watu_init');
460 add_action('wp_ajax_watu_submit', 'watu_submit');
461 add_action('wp_ajax_nopriv_watu_submit', 'watu_submit');
462 add_action('wp_ajax_watu_taking_details', 'watu_taking_details');
463 add_action('wp_ajax_watu_rated', 'watu_already_rated');
464 add_action('wp_ajax_watu_reorder_questions', 'watu_reorder_questions');
465
466 // hook personal data eraser
467 add_filter('wp_privacy_personal_data_erasers', 'watu_register_eraser', 10);
468