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