PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.9.9
Tutor LMS – eLearning and online course solution v3.9.9
3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Tutor.php
tutor / classes Last commit date
Addons.php 11 months ago Admin.php 2 months ago Ajax.php 9 months ago Announcements.php 1 year ago Assets.php 7 months ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 11 months ago Container.php 11 months ago Course.php 2 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 5 months ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 9 months ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 8 months ago Input.php 1 year ago Instructor.php 2 months ago Instructors_List.php 2 months ago Lesson.php 8 months ago Options_V2.php 7 months ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 10 months ago Question_Answers_List.php 11 months ago Quiz.php 5 months ago QuizBuilder.php 3 months ago Quiz_Attempts_List.php 9 months ago RestAPI.php 2 years ago Reviews.php 9 months ago Rewrite_Rules.php 2 years ago Shortcode.php 9 months ago Singleton.php 1 year ago Student.php 2 months ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 9 months ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 year ago Tutor.php 3 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 8 months ago Upgrader.php 9 months ago User.php 4 months ago Utils.php 5 months ago Video_Stream.php 3 years ago WhatsNew.php 9 months ago Withdraw.php 1 year ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 7 months ago
Tutor.php
1415 lines
1 <?php
2 /**
3 * Initialize all the dependency classes
4 *
5 * @package Tutor
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 namespace TUTOR;
12
13 use Tutor\Models\CourseModel;
14 use Tutor\Ecommerce\Ecommerce;
15 use Tutor\Helpers\QueryHelper;
16 use Tutor\Migrations\Migration;
17 use Tutor\TemplateImport\TemplateImportInit;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Tutor final class
25 *
26 * @since 1.0.0
27 */
28 final class Tutor extends Singleton {
29 /**
30 * Tutor version
31 *
32 * @since 1.0.0
33 *
34 * @var string
35 */
36 public $version = TUTOR_VERSION;
37
38 /**
39 * Plugin dir path
40 *
41 * @since 1.0.0
42 *
43 * @var string
44 */
45 public $path;
46
47 /**
48 * Plugin dir path
49 *
50 * @since 1.0.0
51 *
52 * @var string
53 */
54 public $url;
55
56 /**
57 * Plugin dir name
58 *
59 * @since 1.0.0
60 *
61 * @var string
62 */
63 public $basename;
64
65 /**
66 * Utils class object
67 *
68 * @since 1.1.0
69 *
70 * @var object
71 */
72 public $utils;
73
74 /**
75 * Admin class object
76 *
77 * @since 1.1.0
78 *
79 * @var object
80 */
81 public $admin;
82
83 /**
84 * Ajax class object
85 *
86 * @since 1.1.0
87 *
88 * @var object
89 */
90 public $ajax;
91
92 /**
93 * Options class object
94 *
95 * @since 1.1.0
96 *
97 * @var object
98 */
99 public $options;
100
101 /**
102 * Short code class object
103 *
104 * @since 1.1.0
105 *
106 * @var object
107 */
108 public $shortcode;
109
110 /**
111 * Addons class object
112 *
113 * @since 1.1.0
114 *
115 * @var object
116 */
117 private $addons;
118
119 /**
120 * PostType class object
121 *
122 * @since 1.1.0
123 *
124 * @var object
125 */
126 private $post_types;
127
128 /**
129 * Taxonomies class object
130 *
131 * @since 1.1.0
132 *
133 * @var object
134 */
135 private $taxonomies;
136
137 /**
138 * Assets class object
139 *
140 * @since 1.1.0
141 *
142 * @var object
143 */
144 private $assets;
145
146 /**
147 * Course class object
148 *
149 * @since 1.1.0
150 *
151 * @var object
152 */
153 private $course;
154
155 /**
156 * Lesson class object
157 *
158 * @since 1.1.0
159 *
160 * @var object
161 */
162 public $lesson;
163
164 /**
165 * Rewrite_Rules class object
166 *
167 * @since 1.1.0
168 *
169 * @var object
170 */
171 private $rewrite_rules;
172
173 /**
174 * Template class object
175 *
176 * @since 1.1.0
177 *
178 * @var object
179 */
180 private $template;
181
182 /**
183 * Instructor class object
184 *
185 * @since 1.1.0
186 *
187 * @var object
188 */
189 private $instructor;
190
191 /**
192 * Student class object
193 *
194 * @since 1.1.0
195 *
196 * @var object
197 */
198 private $student;
199
200 /**
201 * Q_And_A class object
202 *
203 * @since 1.1.0
204 *
205 * @var object
206 */
207 private $q_and_a;
208
209 /**
210 * Quiz class object
211 *
212 * @since 1.1.0
213 *
214 * @var object
215 */
216 private $quiz;
217
218 /**
219 * Tools class object
220 *
221 * @since 1.1.0
222 *
223 * @var object
224 */
225 private $tools;
226
227 /**
228 * User class object
229 *
230 * @since 1.1.0
231 *
232 * @var object
233 */
234 private $user;
235
236 /**
237 * Theme_Compatibility class object
238 *
239 * @since 1.1.0
240 *
241 * @var object
242 */
243 private $theme_compatibility;
244
245 /**
246 * Gutenberg class object
247 *
248 * @since 1.1.0
249 *
250 * @var object
251 */
252 private $gutenberg;
253
254 /**
255 * Course_Settings_Tabs class object
256 *
257 * @since 1.1.0
258 *
259 * @var object
260 */
261 private $course_settings_tabs;
262
263 /**
264 * Withdraw class object
265 *
266 * @since 1.1.0
267 *
268 * @var object
269 */
270 private $withdraw;
271
272 /**
273 * Course_Widget class object
274 *
275 * @since 1.1.0
276 *
277 * @var object
278 */
279 private $course_widget;
280
281 /**
282 * Upgrader class object
283 *
284 * @since 1.1.0
285 *
286 * @var object
287 */
288 private $upgrader;
289
290 /**
291 * Dashboard class object
292 *
293 * @since 1.1.0
294 *
295 * @var object
296 */
297 private $dashboard;
298
299 /**
300 * FormHandler class object
301 *
302 * @since 1.1.0
303 *
304 * @var object
305 */
306 private $form_handler;
307
308 /**
309 * Frontend class object
310 *
311 * @since 1.1.0
312 *
313 * @var object
314 */
315 private $frontend;
316
317 /**
318 * Email property
319 *
320 * @since 1.1.0
321 *
322 * @var object
323 */
324 private $email;
325
326 /**
327 * WooCommerce integration class object
328 *
329 * @since 1.1.0
330 *
331 * @var object
332 */
333 private $woocommerce;
334
335 /**
336 * Tutor_EDD class object
337 *
338 * @since 1.1.0
339 *
340 * @var object
341 */
342 private $edd;
343
344 /**
345 * Announcement
346 *
347 * @since 2.0.0
348 *
349 * @var object
350 */
351 public $announcements;
352
353 /**
354 * Reviews class object
355 *
356 * @since 1.1.0
357 *
358 * @var object
359 */
360 private $reviews;
361
362 /**
363 * Withdraw_List class object
364 *
365 * @since 1.1.0
366 *
367 * @var object
368 */
369 public $withdraw_list;
370
371 /**
372 * Student_List class object
373 *
374 * @since 1.1.0
375 *
376 * @var object
377 */
378 public $student_list;
379
380 /**
381 * Instructor_List class object
382 *
383 * @since 1.1.0
384 *
385 * @var object
386 */
387 public $instructor_list;
388
389 /**
390 * Course List
391 *
392 * @var Course_List
393 *
394 * @since 2.0.0
395 */
396 public $course_list;
397
398 //phpcs:disable
399 public $q_and_a_list;
400 public $q_attempt;
401 public $rest_api;
402 public $setup;
403 public $private_course_access;
404 public $course_filter;
405 //phpcs:enable
406
407 /**
408 * Course Embed
409 *
410 * @var $course_embed
411 *
412 * @since 2.1.0
413 */
414 private $course_embed;
415
416 /**
417 * Rest Authentication
418 *
419 * @var $rest_auth
420 *
421 * @since 2.1.0
422 */
423 private $rest_auth;
424
425 /**
426 * Permalink
427 *
428 * @var Permalink
429 */
430 private $permalink;
431
432 /**
433 * Initialize props & other dependencies
434 *
435 * @since 1.0.0
436 */
437 public function __construct() {
438
439 $this->path = plugin_dir_path( TUTOR_FILE );
440 $this->url = plugin_dir_url( TUTOR_FILE );
441 $this->basename = plugin_basename( TUTOR_FILE );
442
443 /**
444 * Adding Tutor Database table to $wpdb;
445 *
446 * @since 1.4.2
447 */
448 global $wpdb;
449 $wpdb->tutor_earnings = $wpdb->prefix . 'tutor_earnings';
450 $wpdb->tutor_gradebooks = $wpdb->prefix . 'tutor_gradebooks';
451 $wpdb->tutor_gradebooks_results = $wpdb->prefix . 'tutor_gradebooks_results';
452 $wpdb->tutor_quiz_attempts = $wpdb->prefix . 'tutor_quiz_attempts';
453 $wpdb->tutor_quiz_attempt_answers = $wpdb->prefix . 'tutor_quiz_attempt_answers';
454 $wpdb->tutor_quiz_questions = $wpdb->prefix . 'tutor_quiz_questions';
455 $wpdb->tutor_quiz_question_answers = $wpdb->prefix . 'tutor_quiz_question_answers';
456 $wpdb->tutor_withdraws = $wpdb->prefix . 'tutor_withdraws';
457 $wpdb->tutor_email_queue = $wpdb->prefix . 'tutor_email_queue';
458 $wpdb->tutor_order_items = $wpdb->prefix . 'tutor_order_items';
459 $wpdb->tutor_orders = $wpdb->prefix . 'tutor_orders';
460 $wpdb->tutor_ordermeta = $wpdb->prefix . 'tutor_ordermeta';
461 $wpdb->tutor_subscription_plan_items = $wpdb->prefix . 'tutor_subscription_plan_items';
462 $wpdb->tutor_subscription_plans = $wpdb->prefix . 'tutor_subscription_plans';
463 $wpdb->tutor_subscriptions = $wpdb->prefix . 'tutor_subscriptions';
464 $wpdb->tutor_subscriptionmeta = $wpdb->prefix . 'tutor_subscriptionmeta';
465 $wpdb->tutor_order_itemmeta = $wpdb->prefix . 'tutor_order_itemmeta';
466
467 /**
468 * Changing default wp doing ajax return based on tutor ajax action
469 */
470 add_filter( 'wp_doing_ajax', array( $this, 'wp_doing_ajax' ) );
471
472 /**
473 * Include Files
474 */
475 $this->includes();
476
477 do_action( 'tutor_before_load' );
478
479 $this->addons = new Addons();
480 $this->post_types = new Post_types();
481 $this->taxonomies = new Taxonomies();
482 $this->assets = new Assets();
483 $this->admin = new Admin();
484 $this->ajax = new Ajax();
485 $this->options = new Options_V2();
486 $this->shortcode = new Shortcode();
487 $this->course = new Course();
488 $this->lesson = new Lesson();
489 $this->rewrite_rules = new Rewrite_Rules();
490 $this->template = new Template();
491 $this->instructor = new Instructor();
492 $this->student = new Student();
493 $this->q_and_a = new Q_And_A();
494 $this->q_and_a_list = new Question_Answers_List();
495 $this->q_attempt = new Quiz_Attempts_List();
496 $this->quiz = new Quiz();
497 $this->tools = new Tools();
498 $this->user = new User();
499 $this->theme_compatibility = new Theme_Compatibility();
500 $this->gutenberg = new Gutenberg();
501 $this->course_settings_tabs = new Course_Settings_Tabs();
502 $this->withdraw = new Withdraw();
503 $this->upgrader = new Upgrader();
504 $this->dashboard = new Dashboard();
505 $this->form_handler = new FormHandler();
506 $this->frontend = new Frontend();
507 $this->rest_api = new RestAPI();
508 $this->setup = new Tutor_Setup();
509 $this->private_course_access = new Private_Course_Access();
510 $this->course_filter = new Course_Filter();
511 $this->permalink = new Permalink();
512
513 // Template import.
514 new TemplateImportInit();
515
516 // Integrations.
517 $this->woocommerce = new WooCommerce();
518 $this->edd = new TutorEDD();
519
520 /**
521 * Init obj
522 *
523 * @since 2.0.0
524 */
525 $this->announcements = new Announcements();
526 $this->course_list = new Course_List();
527 $this->reviews = new Reviews();
528 $this->withdraw_list = new Withdraw_Requests_List();
529 $this->student_list = new Students_List();
530 $this->instructor_list = new Instructors_List();
531 $this->course_embed = new Course_Embed();
532 $this->rest_auth = new RestAuth();
533
534 /**
535 * New Course Builder.
536 *
537 * @since 3.0.0
538 */
539 new QuizBuilder();
540
541 /**
542 * Tutor native e-commerce
543 *
544 * @since 3.0.0
545 */
546 new Ecommerce();
547
548 /**
549 * Data migrations
550 *
551 * @since 3.8.0
552 */
553 new Migration();
554
555 /**
556 * Run Method
557 *
558 * @since 1.2.0
559 */
560 $this->run();
561
562 do_action( 'tutor_loaded' );
563
564 add_action( 'init', array( $this, 'init_action' ) );
565
566 /**
567 * Check activated plugin
568 *
569 * @since 1.5.7
570 */
571
572 add_action( 'activated_plugin', array( $this, 'activated_tutor' ), 10, 2 );
573
574 /**
575 * Redirect to setup page
576 *
577 * @since 2.8.0
578 */
579 add_action( 'admin_init', array( $this, 'redirect_to_setup_page' ) );
580 }
581
582 /**
583 * Check activated plugin
584 *
585 * @since 1.5.7
586 *
587 * @param mixed $plugin plugin.
588 * @param mixed $network_wide network wide.
589 *
590 * @return void
591 */
592 public function activated_tutor( $plugin, $network_wide = null ) {
593 if ( tutor()->basename === $plugin ) {
594 $this->redirect_to_setup_page();
595 }
596 }
597
598 /**
599 * Redirect to setup page
600 *
601 * @since 2.8.0
602 *
603 * @return void
604 */
605 public function redirect_to_setup_page() {
606 if ( ( ! get_option( 'tutor_wizard' ) ) && version_compare( TUTOR_VERSION, '1.5.6', '>' ) ) {
607 if ( ! wp_doing_ajax() ) {
608 update_option( 'tutor_wizard', 'active' );
609 $is_wp_cli = defined( 'WP_CLI' ) && WP_CLI;
610 if ( ! $is_wp_cli ) {
611 wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) );
612 }
613 exit;
614 }
615 }
616 }
617
618 /**
619 * Include utility functions
620 *
621 * @return void
622 */
623 public function includes() {
624 $tutor_path = plugin_dir_path( TUTOR_FILE );
625
626 include $tutor_path . 'includes/tutor-general-functions.php';
627 include $tutor_path . 'includes/tutor-template-functions.php';
628 include $tutor_path . 'includes/tutor-template-hook.php';
629 include $tutor_path . 'includes/translate-text.php';
630 include $tutor_path . 'includes/country.php';
631 include $tutor_path . 'includes/ecommerce-functions.php';
632
633 if ( ! function_exists( 'is_plugin_active' ) ) {
634 require_once ABSPATH . 'wp-admin/includes/plugin.php';
635 }
636
637 $is_droip_active = \is_plugin_active( 'droip/droip.php' );
638 $tutor_droip_path = $tutor_path . 'includes/droip/droip.php';
639 if ( $is_droip_active && file_exists( $tutor_droip_path ) ) {
640 include $tutor_droip_path;
641 }
642 }
643
644 /**
645 * Providing hooks
646 *
647 * @return void
648 */
649 public function run() {
650 do_action( 'tutor_before_run' );
651 do_action( 'tutor_after_run' );
652 }
653
654 /**
655 * Tutor Action Via do_action
656 *
657 * @since 1.2.14
658 */
659 public function init_action() {
660 $tutor_action = Input::sanitize_request_data( 'tutor_action' );
661 if ( '' !== $tutor_action ) {
662 do_action( 'tutor_action_' . $tutor_action );
663 }
664 }
665
666 /**
667 * Do some task during plugin activation
668 */
669 public static function tutor_activate() {
670 $version = get_option( 'tutor_version' );
671 if ( ! function_exists( 'tutor_time' ) ) {
672 include tutor()->path . 'includes/tutor-general-functions.php';
673 }
674
675 // Create Database.
676 self::create_database();
677
678 // Save Option.
679 if ( ! $version ) {
680
681 $options = self::default_options();
682 update_option( 'tutor_option', $options );
683
684 // Rewrite Flush.
685 Permalink::set_permalink_flag();
686 self::manage_tutor_roles_and_permissions();
687
688 // Save initial Page.
689 self::save_data();
690 update_option( 'tutor_version', TUTOR_VERSION );
691 }
692
693 // Set Schedule.
694 if ( ! wp_next_scheduled( 'tutor_once_in_day_run_schedule' ) ) {
695 wp_schedule_event( tutor_time(), 'twicedaily', 'tutor_once_in_day_run_schedule' );
696 }
697
698 /**
699 * Backward Compatibility for version < 1.2.0
700 */
701 if ( version_compare( get_option( 'tutor_version' ), '1.2.0', '<' ) ) {
702 /**
703 * Creating New Database
704 */
705 self::create_withdraw_database();
706 // Update the tutor version.
707 update_option( 'tutor_version', '1.2.0' );
708 // Rewrite Flush.
709 Permalink::set_permalink_flag();
710 }
711
712 /**
713 * Backward Compatibility to < 1.3.1 for make course plural
714 */
715 if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) {
716 global $wpdb;
717
718 if ( ! get_option( 'is_course_post_type_updated' ) ) {
719 $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) );
720 update_option( 'is_course_post_type_updated', true );
721 update_option( 'tutor_version', '1.3.1' );
722 Permalink::set_permalink_flag();
723 }
724 }
725
726 /**
727 * Save First activation Time
728 */
729 $first_activation_date = get_option( 'tutor_first_activation_time' );
730 if ( ! $first_activation_date ) {
731 update_option( 'tutor_first_activation_time', tutor_time() );
732 }
733 }
734
735 /**
736 * Run task on deactivation
737 *
738 * @since 1.0.0
739 *
740 * @return void
741 */
742 public static function tutor_deactivation() {
743 wp_clear_scheduled_hook( 'tutor_once_in_day_run_schedule' );
744 }
745
746 /**
747 * Create database
748 *
749 * @return void
750 */
751 public static function create_database() {
752 global $wpdb;
753
754 $charset_collate = $wpdb->get_charset_collate();
755
756 /**
757 * Table SQL
758 *
759 * {$wpdb->prefix}tutor_quiz_attempts
760 * {$wpdb->prefix}tutor_quiz_attempt_answers
761 * {$wpdb->prefix}tutor_quiz_questions
762 * {$wpdb->prefix}tutor_quiz_question_answers
763 * {$wpdb->prefix}tutor_earnings
764 * {$wpdb->prefix}tutor_withdraws
765 *
766 * @since 1.0.0
767 */
768 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
769 attempt_id bigint(20) NOT NULL AUTO_INCREMENT,
770 course_id bigint(20) DEFAULT NULL,
771 quiz_id bigint(20) DEFAULT NULL,
772 user_id bigint(20) DEFAULT NULL,
773 total_questions int(11) DEFAULT NULL,
774 total_answered_questions int(11) DEFAULT NULL,
775 total_marks decimal(9,2) DEFAULT NULL,
776 earned_marks decimal(9,2) DEFAULT NULL,
777 attempt_info text,
778 attempt_status varchar(50) DEFAULT NULL,
779 attempt_ip varchar(250) DEFAULT NULL,
780 attempt_started_at datetime DEFAULT NULL,
781 attempt_ended_at datetime DEFAULT NULL,
782 is_manually_reviewed int(1) DEFAULT NULL,
783 manually_reviewed_at datetime DEFAULT NULL,
784 result varchar(10) DEFAULT NULL,
785 PRIMARY KEY (attempt_id),
786 INDEX (course_id),
787 INDEX (quiz_id),
788 INDEX (user_id),
789 INDEX (result)
790 ) $charset_collate;";
791
792 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
793 attempt_answer_id bigint(20) NOT NULL AUTO_INCREMENT,
794 user_id bigint(20) DEFAULT NULL,
795 quiz_id bigint(20) DEFAULT NULL,
796 question_id bigint(20) DEFAULT NULL,
797 quiz_attempt_id bigint(20) DEFAULT NULL,
798 given_answer longtext,
799 question_mark decimal(8,2) DEFAULT NULL,
800 achieved_mark decimal(8,2) DEFAULT NULL,
801 minus_mark decimal(8,2) DEFAULT NULL,
802 is_correct tinyint(4) DEFAULT NULL,
803 PRIMARY KEY (attempt_answer_id)
804 ) $charset_collate;";
805
806 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
807 question_id bigint(20) NOT NULL AUTO_INCREMENT,
808 quiz_id bigint(20) DEFAULT NULL,
809 question_title text,
810 question_description longtext,
811 answer_explanation longtext DEFAULT '',
812 question_type varchar(50) DEFAULT NULL,
813 question_mark decimal(9,2) DEFAULT NULL,
814 question_settings longtext,
815 question_order int(11) DEFAULT NULL,
816 PRIMARY KEY (question_id)
817 ) $charset_collate;";
818
819 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
820 answer_id bigint(20) NOT NULL AUTO_INCREMENT,
821 belongs_question_id bigint(20) DEFAULT NULL,
822 belongs_question_type varchar(250) DEFAULT NULL,
823 answer_title text,
824 is_correct tinyint(4) DEFAULT NULL,
825 image_id bigint(20) DEFAULT NULL,
826 answer_two_gap_match text,
827 answer_view_format varchar(250) DEFAULT NULL,
828 answer_settings text,
829 answer_order int(11) DEFAULT '0',
830 PRIMARY KEY (answer_id)
831 ) $charset_collate;";
832
833 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
834 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
835 user_id bigint(20) DEFAULT NULL,
836 course_id bigint(20) DEFAULT NULL,
837 order_id bigint(20) DEFAULT NULL,
838 order_status varchar(50) DEFAULT NULL,
839 course_price_total decimal(16,2) DEFAULT NULL,
840 course_price_grand_total decimal(16,2) DEFAULT NULL,
841 instructor_amount decimal(16,2) DEFAULT NULL,
842 instructor_rate decimal(16,2) DEFAULT NULL,
843 admin_amount decimal(16,2) DEFAULT NULL,
844 admin_rate decimal(16,2) DEFAULT NULL,
845 commission_type varchar(20) DEFAULT NULL,
846 deduct_fees_amount decimal(16,2) DEFAULT NULL,
847 deduct_fees_name varchar(250) DEFAULT NULL,
848 deduct_fees_type varchar(20) DEFAULT NULL,
849 process_by varchar(20) DEFAULT NULL,
850 created_at datetime DEFAULT NULL,
851 PRIMARY KEY (earning_id),
852 INDEX (user_id),
853 INDEX (course_id),
854 INDEX (order_id),
855 INDEX (process_by)
856 ) $charset_collate;";
857
858 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
859 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
860 user_id bigint(20) DEFAULT NULL,
861 amount decimal(16,2) DEFAULT NULL,
862 method_data text DEFAULT NULL,
863 status varchar(50) DEFAULT NULL,
864 updated_at datetime DEFAULT NULL,
865 created_at datetime DEFAULT NULL,
866 PRIMARY KEY (withdraw_id)
867 ) $charset_collate;";
868
869 $orders_table = "CREATE TABLE {$wpdb->prefix}tutor_orders (
870 id BIGINT(20) UNSIGNED AUTO_INCREMENT,
871 parent_id BIGINT(20) UNSIGNED DEFAULT 0, -- for subscription order, store subscription record id
872 transaction_id VARCHAR(255) COMMENT 'Transaction id from payment gateway',
873 user_id BIGINT(20) UNSIGNED NOT NULL,
874 order_type VARCHAR(50) NOT NULL, -- single_order, subscription
875 order_status VARCHAR(50) NOT NULL,
876 payment_status VARCHAR(50) NOT NULL,
877 subtotal_price DECIMAL(13, 2) NOT NULL, -- price calculation based on course sale price
878 pre_tax_price DECIMAL(13, 2) NOT NULL, -- total price before adding tax
879 tax_type VARCHAR(50),
880 tax_rate DECIMAL(13, 2) COMMENT 'Tax percentage',
881 tax_amount DECIMAL(13, 2),
882 total_price DECIMAL(13, 2) NOT NULL, -- final price
883 net_payment DECIMAL(13, 2) NOT NULL, -- calculated price if any refund is done else same as total_price
884 coupon_code VARCHAR(255),
885 coupon_amount DECIMAL(13, 2),
886 discount_type ENUM('percentage', 'flat') DEFAULT NULL,
887 discount_amount DECIMAL(13, 2),
888 discount_reason TEXT,
889 fees DECIMAL(13, 2), -- payment gateway fees
890 earnings DECIMAL(13, 2), -- net earning
891 refund_amount DECIMAL(13, 2), -- Refund amount
892 payment_method VARCHAR(255),
893 payment_payloads LONGTEXT,
894 note TEXT,
895 created_at_gmt DATETIME NOT NULL,
896 created_by BIGINT(20) UNSIGNED NOT NULL,
897 updated_at_gmt DATETIME,
898 updated_by BIGINT(20) UNSIGNED NOT NULL,
899 PRIMARY KEY (id),
900 KEY user_id (user_id),
901 KEY order_type (order_type),
902 KEY payment_status (payment_status),
903 KEY order_status (order_status),
904 KEY transaction_id (transaction_id)
905 ) $charset_collate;";
906
907 $order_meta_table = "CREATE TABLE {$wpdb->prefix}tutor_ordermeta (
908 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
909 order_id BIGINT(20) UNSIGNED NOT NULL,
910 meta_key VARCHAR(255) NOT NULL,
911 meta_value LONGTEXT NOT NULL,
912 created_at_gmt DATETIME NOT NULL,
913 created_by BIGINT(20) UNSIGNED NOT NULL,
914 updated_at_gmt DATETIME,
915 updated_by BIGINT(20) UNSIGNED NOT NULL,
916 PRIMARY KEY (id),
917 KEY order_id (order_id),
918 KEY meta_key (meta_key),
919 CONSTRAINT fk_tutor_ordermeta_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
920 ) $charset_collate;";
921
922 $order_items_table = "CREATE TABLE {$wpdb->prefix}tutor_order_items (
923 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
924 order_id BIGINT(20) UNSIGNED NOT NULL,
925 item_id BIGINT(20) UNSIGNED NOT NULL, -- course id/plan id
926 regular_price DECIMAL(13, 2) NOT NULL, -- course regular price
927 sale_price VARCHAR(13) DEFAULT NULL, -- course sale price
928 discount_price VARCHAR(13) DEFAULT NULL, -- course discount price
929 coupon_code VARCHAR(255) DEFAULT NULL, -- coupon code
930 PRIMARY KEY (id),
931 KEY order_id (order_id),
932 KEY item_id (item_id),
933 CONSTRAINT fk_tutor_order_item_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
934 ) $charset_collate;";
935
936 $coupons_table = "CREATE TABLE {$wpdb->prefix}tutor_coupons (
937 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
938 coupon_status VARCHAR(50),
939 coupon_type VARCHAR(100) DEFAULT 'code', -- coupon type 'code' or 'automatic'
940 coupon_code VARCHAR(50) NOT NULL,
941 coupon_title VARCHAR(255) NOT NULL,
942 coupon_description TEXT,
943 discount_type ENUM('percentage', 'flat') NOT NULL,
944 discount_amount DECIMAL(13, 2) NOT NULL,
945 applies_to VARCHAR(100) DEFAULT 'all_courses_and_bundles', -- possible values 'all_courses_and_bundles', 'all_courses', 'all_bundles', 'specific_courses', 'specific_bundles', 'specific_category'
946 total_usage_limit INT(10) UNSIGNED DEFAULT NULL, -- null for unlimited usage
947 per_user_usage_limit TINYINT(4) UNSIGNED DEFAULT NULL, -- null for unlimited usage
948 purchase_requirement VARCHAR(50) DEFAULT 'no_minimum', -- possible values 'no_minimum', 'minimum_purchase', 'minimum_quantity'
949 purchase_requirement_value DECIMAL(13, 2),
950 start_date_gmt DATETIME NOT NULL,
951 expire_date_gmt DATETIME DEFAULT NULL,
952 created_at_gmt DATETIME NOT NULL,
953 created_by BIGINT(20) UNSIGNED NOT NULL,
954 updated_at_gmt DATETIME,
955 updated_by BIGINT(20) UNSIGNED NOT NULL,
956 PRIMARY KEY (id),
957 UNIQUE KEY coupon_code (coupon_code),
958 KEY start_date_gmt (start_date_gmt),
959 KEY expire_date_gmt (expire_date_gmt)
960 ) $charset_collate;";
961
962 $coupon_applications_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_applications (
963 coupon_code VARCHAR(50) NOT NULL,
964 reference_id BIGINT(20) UNSIGNED NOT NULL,
965 KEY coupon_code (coupon_code),
966 KEY reference_id (reference_id),
967 CONSTRAINT fk_tutor_coupon_application_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE
968 ) $charset_collate;";
969
970 $coupon_usage_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_usages (
971 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
972 coupon_code VARCHAR(50) NOT NULL,
973 user_id BIGINT(20) UNSIGNED NOT NULL,
974 PRIMARY KEY (id),
975 KEY coupon_code (coupon_code),
976 KEY user_id (user_id),
977 CONSTRAINT fk_tutor_coupon_usage_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE,
978 CONSTRAINT fk_tutor_coupon_usage_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
979 ) $charset_collate;";
980
981 $cart_table = "CREATE TABLE {$wpdb->prefix}tutor_carts (
982 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
983 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
984 coupon_code VARCHAR(50) DEFAULT NULL,
985 created_at_gmt DATETIME NOT NULL,
986 updated_at_gmt DATETIME,
987 PRIMARY KEY (id),
988 KEY user_id (user_id),
989 KEY coupon_code (coupon_code),
990 CONSTRAINT fk_tutor_cart_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
991 ) $charset_collate;";
992
993 $cart_items_table = "CREATE TABLE {$wpdb->prefix}tutor_cart_items (
994 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
995 cart_id BIGINT(20) UNSIGNED NOT NULL,
996 course_id BIGINT(20) UNSIGNED NOT NULL,
997 PRIMARY KEY (id),
998 KEY cart_id (cart_id),
999 KEY course_id (course_id),
1000 CONSTRAINT fk_tutor_cart_item_cart_id FOREIGN KEY (cart_id) REFERENCES {$wpdb->prefix}tutor_carts(id) ON DELETE CASCADE,
1001 CONSTRAINT fk_tutor_cart_item_course_id FOREIGN KEY (course_id) REFERENCES {$wpdb->prefix}posts(ID) ON DELETE CASCADE
1002 ) $charset_collate;";
1003
1004 $customer_table = "CREATE TABLE {$wpdb->prefix}tutor_customers (
1005 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
1006 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
1007 billing_first_name VARCHAR(255) NOT NULL,
1008 billing_last_name VARCHAR(255) NOT NULL,
1009 billing_email VARCHAR(255) NOT NULL,
1010 billing_phone VARCHAR(20) NOT NULL,
1011 billing_zip_code VARCHAR(20) NOT NULL,
1012 billing_address TEXT NOT NULL,
1013 billing_country VARCHAR(100) NOT NULL,
1014 billing_state VARCHAR(100) NOT NULL,
1015 billing_city VARCHAR(100) NOT NULL,
1016 PRIMARY KEY (id),
1017 KEY user_id (user_id),
1018 KEY billing_email (billing_email)
1019 ) $charset_collate;";
1020
1021 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1022 dbDelta( $quiz_attempts_sql );
1023 dbDelta( $quiz_attempt_answers );
1024 dbDelta( $tutor_quiz_questions );
1025 dbDelta( $tutor_quiz_question_answers );
1026 dbDelta( $earning_table );
1027 dbDelta( $withdraw_table );
1028 dbDelta( $orders_table );
1029 dbDelta( $order_meta_table );
1030 dbDelta( $order_items_table );
1031 dbDelta( $coupons_table );
1032 dbDelta( $coupon_applications_table );
1033 dbDelta( $coupon_usage_table );
1034 dbDelta( $cart_table );
1035 dbDelta( $cart_items_table );
1036 dbDelta( $customer_table );
1037 }
1038
1039 /**
1040 * Manage tutor roles & permission
1041 *
1042 * @return void
1043 */
1044 public static function manage_tutor_roles_and_permissions() {
1045 /**
1046 * Add role for instructor
1047 */
1048 $instructor_role = tutor()->instructor_role;
1049
1050 remove_role( $instructor_role );
1051 add_role( $instructor_role, __( 'Tutor Instructor', 'tutor' ), array() );
1052
1053 $custom_post_type_permission = array(
1054 // Manage Instructor.
1055 'manage_tutor_instructor',
1056
1057 // Tutor Posts Type Permission.
1058 'edit_tutor_course',
1059 'read_tutor_course',
1060 'delete_tutor_course',
1061 'delete_tutor_courses',
1062 'edit_tutor_courses',
1063 'edit_others_tutor_courses',
1064 'read_private_tutor_courses',
1065 'edit_tutor_courses',
1066
1067 'edit_tutor_lesson',
1068 'read_tutor_lesson',
1069 'delete_tutor_lesson',
1070 'delete_tutor_lessons',
1071 'edit_tutor_lessons',
1072 'edit_others_tutor_lessons',
1073 'read_private_tutor_lessons',
1074 'edit_tutor_lessons',
1075 'publish_tutor_lessons',
1076
1077 'edit_tutor_quiz',
1078 'read_tutor_quiz',
1079 'delete_tutor_quiz',
1080 'delete_tutor_quizzes',
1081 'edit_tutor_quizzes',
1082 'edit_others_tutor_quizzes',
1083 'read_private_tutor_quizzes',
1084 'edit_tutor_quizzes',
1085 'publish_tutor_quizzes',
1086
1087 'edit_tutor_question',
1088 'read_tutor_question',
1089 'delete_tutor_question',
1090 'delete_tutor_questions',
1091 'edit_tutor_questions',
1092 'edit_others_tutor_questions',
1093 'publish_tutor_questions',
1094 'read_private_tutor_questions',
1095 'edit_tutor_questions',
1096 );
1097
1098 $instructor = get_role( $instructor_role );
1099 if ( $instructor ) {
1100 $instructor_cap = array(
1101 'edit_posts',
1102 'read',
1103 'upload_files',
1104 );
1105
1106 $instructor_cap = array_merge( $instructor_cap, $custom_post_type_permission );
1107
1108 $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
1109 if ( $can_publish_course ) {
1110 $instructor_cap[] = 'publish_tutor_courses';
1111 }
1112
1113 foreach ( $instructor_cap as $cap ) {
1114 $instructor->add_cap( $cap );
1115 }
1116 }
1117
1118 $administrator = get_role( 'administrator' );
1119 if ( $administrator ) {
1120
1121 $administrator_cap = array(
1122 'manage_tutor',
1123 );
1124 $administrator_cap = array_merge( $administrator_cap, $custom_post_type_permission );
1125 $administrator_cap[] = 'publish_tutor_courses';
1126
1127 foreach ( $administrator_cap as $cap ) {
1128 $administrator->add_cap( $cap );
1129 }
1130 }
1131
1132 /**
1133 * Add Instructor role to administrator
1134 */
1135 if ( current_user_can( 'administrator' ) ) {
1136 tutor_utils()->add_instructor_role( get_current_user_id() );
1137 }
1138 }
1139
1140 /**
1141 * On plugin activate save initial data
1142 * Like: generate tutor pages
1143 *
1144 * @since 1.0.0
1145 *
1146 * @return void
1147 */
1148 public static function save_data() {
1149
1150 $student_dashboard_args = array(
1151 'post_title' => __( 'Dashboard', 'tutor' ),
1152 'post_content' => '',
1153 'post_type' => 'page',
1154 'post_status' => 'publish',
1155 );
1156 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
1157 tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id );
1158
1159 $student_registration_args = array(
1160 'post_title' => __( 'Student Registration', 'tutor' ),
1161 'post_content' => '[tutor_student_registration_form]',
1162 'post_type' => 'page',
1163 'post_status' => 'publish',
1164 );
1165 $student_register_page_id = wp_insert_post( $student_registration_args );
1166 tutor_utils()->update_option( 'student_register_page', $student_register_page_id );
1167
1168 $instructor_registration_args = array(
1169 'post_title' => __( 'Instructor Registration', 'tutor' ),
1170 'post_content' => '[tutor_instructor_registration_form]',
1171 'post_type' => 'page',
1172 'post_status' => 'publish',
1173 );
1174 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
1175 tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id );
1176 }
1177
1178 /**
1179 * Default options
1180 *
1181 * @since 1.0.0
1182 *
1183 * @since 3.4.1 Supported video sources added
1184 *
1185 * @return array
1186 */
1187 public static function default_options() {
1188 $options = array(
1189 'pagination_per_page' => '20',
1190 'course_allow_upload_private_files' => '1',
1191 'display_course_instructors' => '1',
1192 'enable_q_and_a_on_course' => '1',
1193 'courses_col_per_row' => '3',
1194 'courses_per_page' => '12',
1195 'course_permalink_base' => 'courses',
1196 'lesson_permalink_base' => 'lessons',
1197 'quiz_when_time_expires' => 'autosubmit',
1198 'quiz_attempts_allowed' => '10',
1199 'quiz_grade_method' => 'highest_grade',
1200 'enable_public_profile' => '1',
1201 'email_to_students' =>
1202 array(
1203 'quiz_completed' => '1',
1204 'completed_course' => '1',
1205 ),
1206 'email_to_instructors' =>
1207 array(
1208 'a_student_enrolled_in_course' => '1',
1209 'a_student_completed_course' => '1',
1210 'a_student_completed_lesson' => '1',
1211 'a_student_placed_question' => '1',
1212 ),
1213 'email_from_name' => get_option( 'blogname' ),
1214 'email_from_address' => get_option( 'admin_email' ),
1215 'email_footer_text' => '',
1216 'earning_admin_commission' => '20',
1217 'earning_instructor_commission' => '80',
1218 'color_preset_type' => 'default',
1219
1220 // Default options for tutor ecommerce.
1221 'monetize_by' => Ecommerce::MONETIZE_BY,
1222 'currency_code' => 'USD',
1223 'currency_position' => 'left',
1224 'thousand_separator' => ',',
1225 'decimal_separator' => '.',
1226 'number_of_decimals' => '2',
1227 'is_coupon_applicable' => 'on',
1228 'supported_video_sources' => array(
1229 'html5',
1230 'external_url',
1231 'youtube',
1232 'vimeo',
1233 'embedded',
1234 'shortcode',
1235 ),
1236 );
1237
1238 return $options;
1239 }
1240
1241
1242 /**
1243 * Create withdraw database
1244 *
1245 * @since 1.2.0
1246 */
1247 public static function create_withdraw_database() {
1248 global $wpdb;
1249
1250 $charset_collate = $wpdb->get_charset_collate();
1251
1252 /**
1253 * Table SQL
1254 *
1255 * {$wpdb->prefix}tutor_earnings
1256 * {$wpdb->prefix}tutor_withdraws
1257 *
1258 * @since 1.2.0
1259 */
1260
1261 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
1262 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
1263 user_id bigint(20) DEFAULT NULL,
1264 course_id bigint(20) DEFAULT NULL,
1265 order_id bigint(20) DEFAULT NULL,
1266 order_status varchar(50) DEFAULT NULL,
1267 course_price_total decimal(16,2) DEFAULT NULL,
1268 course_price_grand_total decimal(16,2) DEFAULT NULL,
1269 instructor_amount decimal(16,2) DEFAULT NULL,
1270 instructor_rate decimal(16,2) DEFAULT NULL,
1271 admin_amount decimal(16,2) DEFAULT NULL,
1272 admin_rate decimal(16,2) DEFAULT NULL,
1273 commission_type varchar(20) DEFAULT NULL,
1274 deduct_fees_amount decimal(16,2) DEFAULT NULL,
1275 deduct_fees_name varchar(250) DEFAULT NULL,
1276 deduct_fees_type varchar(20) DEFAULT NULL,
1277 process_by varchar(20) DEFAULT NULL,
1278 created_at datetime DEFAULT NULL,
1279 PRIMARY KEY (earning_id)
1280 ) $charset_collate;";
1281
1282 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
1283 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
1284 user_id bigint(20) DEFAULT NULL,
1285 amount decimal(16,2) DEFAULT NULL,
1286 method_data text DEFAULT NULL,
1287 status varchar(50) DEFAULT NULL,
1288 updated_at datetime DEFAULT NULL,
1289 created_at datetime DEFAULT NULL,
1290 PRIMARY KEY (withdraw_id)
1291 ) $charset_collate;";
1292
1293 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1294 dbDelta( $earning_table );
1295 dbDelta( $withdraw_table );
1296
1297 /**
1298 * Setting previous dashboard to new dashboard
1299 */
1300 $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' );
1301 tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id );
1302 }
1303
1304 /**
1305 * Filter the wp_doing_ajax from tutor requests to get advanced
1306 * advantages from Tutor
1307 *
1308 * @since 1.3.4
1309 *
1310 * @param bool $bool default value.
1311 *
1312 * @return bool
1313 */
1314 public function wp_doing_ajax( $bool ) {
1315 // Don't use Input::has helper to avoid conflict.
1316 if ( isset( $_REQUEST['tutor_ajax_action'] ) ) {
1317 return true;
1318 }
1319 return $bool;
1320 }
1321
1322 /**
1323 * Handle plugin un-installation
1324 *
1325 * @since 2.6.2
1326 *
1327 * @return void
1328 */
1329 public static function tutor_uninstall() {
1330 self::erase_tutor_data();
1331 }
1332
1333 /**
1334 * Erase tutor data
1335 *
1336 * @since 2.6.2
1337 *
1338 * @return void
1339 */
1340 public static function erase_tutor_data() {
1341 global $wpdb;
1342
1343 $is_erase_data = tutor_utils()->get_option( 'delete_on_uninstall' );
1344 // Deleting Data.
1345
1346 if ( $is_erase_data ) {
1347 /**
1348 * Deleting Post Type, Meta Data, taxonomy
1349 */
1350 $course_post_type = tutor()->course_post_type;
1351 $lesson_post_type = tutor()->lesson_post_type;
1352
1353 $post_types = array(
1354 $course_post_type,
1355 $lesson_post_type,
1356 'tutor_quiz',
1357 'tutor_enrolled',
1358 'topics',
1359 'tutor_enrolled',
1360 'tutor_announcements',
1361 );
1362
1363 $in_clause = QueryHelper::prepare_in_clause( $post_types );
1364 $tutor_posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID from {$wpdb->posts} WHERE post_type IN({$in_clause}) ;" ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1365
1366 if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) {
1367 foreach ( $tutor_posts as $post_id ) {
1368 // Delete categories.
1369 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_CATEGORY );
1370 foreach ( $terms as $term ) {
1371 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_CATEGORY );
1372 }
1373
1374 // Delete tags if available.
1375 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_TAG );
1376 foreach ( $terms as $term ) {
1377 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_TAG );
1378 }
1379
1380 // Delete All Meta.
1381 $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $post_id ) );
1382 $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
1383 }
1384 }
1385
1386 /**
1387 * Deleting Comments (reviews, questions, quiz_answers, etc)
1388 */
1389 $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" );
1390 if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) {
1391 $in_clause = QueryHelper::prepare_in_clause( $tutor_comments );
1392 $wpdb->query( $wpdb->prepare( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$in_clause}) " ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1393 }
1394 $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) );
1395
1396 /**
1397 * Delete Options
1398 */
1399
1400 delete_option( 'tutor_option' );
1401 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_student' ) );
1402 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_approved' ) );
1403 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_status' ) );
1404 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_instructor' ) );
1405 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_tutor_completed_lesson_id_%' " );
1406
1407 // Deleting Table.
1408 $prefix = $wpdb->prefix;
1409 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1410 $wpdb->query( "DROP TABLE IF EXISTS {$prefix}tutor_quiz_attempts, {$prefix}tutor_quiz_attempt_answers, {$prefix}tutor_quiz_questions, {$prefix}tutor_quiz_question_answers, {$prefix}tutor_earnings, {$prefix}tutor_withdraws " );
1411
1412 }
1413 }
1414 }
1415