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