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