PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.9.1
Tutor LMS – eLearning and online course solution v3.9.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 8 months ago Ajax.php 9 months ago Announcements.php 1 year ago Assets.php 8 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 9 months ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 8 months ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 11 months ago Lesson.php 8 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 8 months ago Upgrader.php 9 months ago User.php 1 year ago Utils.php 8 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
1407 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 INDEX (user_id),
845 INDEX (course_id),
846 INDEX (order_id),
847 INDEX (process_by)
848 ) $charset_collate;";
849
850 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
851 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
852 user_id bigint(20) DEFAULT NULL,
853 amount decimal(16,2) DEFAULT NULL,
854 method_data text DEFAULT NULL,
855 status varchar(50) DEFAULT NULL,
856 updated_at datetime DEFAULT NULL,
857 created_at datetime DEFAULT NULL,
858 PRIMARY KEY (withdraw_id)
859 ) $charset_collate;";
860
861 $orders_table = "CREATE TABLE {$wpdb->prefix}tutor_orders (
862 id BIGINT(20) UNSIGNED AUTO_INCREMENT,
863 parent_id BIGINT(20) UNSIGNED DEFAULT 0, -- for subscription order, store subscription record id
864 transaction_id VARCHAR(255) COMMENT 'Transaction id from payment gateway',
865 user_id BIGINT(20) UNSIGNED NOT NULL,
866 order_type VARCHAR(50) NOT NULL, -- single_order, subscription
867 order_status VARCHAR(50) NOT NULL,
868 payment_status VARCHAR(50) NOT NULL,
869 subtotal_price DECIMAL(13, 2) NOT NULL, -- price calculation based on course sale price
870 pre_tax_price DECIMAL(13, 2) NOT NULL, -- total price before adding tax
871 tax_type VARCHAR(50),
872 tax_rate DECIMAL(13, 2) COMMENT 'Tax percentage',
873 tax_amount DECIMAL(13, 2),
874 total_price DECIMAL(13, 2) NOT NULL, -- final price
875 net_payment DECIMAL(13, 2) NOT NULL, -- calculated price if any refund is done else same as total_price
876 coupon_code VARCHAR(255),
877 coupon_amount DECIMAL(13, 2),
878 discount_type ENUM('percentage', 'flat') DEFAULT NULL,
879 discount_amount DECIMAL(13, 2),
880 discount_reason TEXT,
881 fees DECIMAL(13, 2), -- payment gateway fees
882 earnings DECIMAL(13, 2), -- net earning
883 refund_amount DECIMAL(13, 2), -- Refund amount
884 payment_method VARCHAR(255),
885 payment_payloads LONGTEXT,
886 note TEXT,
887 created_at_gmt DATETIME NOT NULL,
888 created_by BIGINT(20) UNSIGNED NOT NULL,
889 updated_at_gmt DATETIME,
890 updated_by BIGINT(20) UNSIGNED NOT NULL,
891 PRIMARY KEY (id),
892 KEY user_id (user_id),
893 KEY order_type (order_type),
894 KEY payment_status (payment_status),
895 KEY order_status (order_status),
896 KEY transaction_id (transaction_id)
897 ) $charset_collate;";
898
899 $order_meta_table = "CREATE TABLE {$wpdb->prefix}tutor_ordermeta (
900 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
901 order_id BIGINT(20) UNSIGNED NOT NULL,
902 meta_key VARCHAR(255) NOT NULL,
903 meta_value LONGTEXT NOT NULL,
904 created_at_gmt DATETIME NOT NULL,
905 created_by BIGINT(20) UNSIGNED NOT NULL,
906 updated_at_gmt DATETIME,
907 updated_by BIGINT(20) UNSIGNED NOT NULL,
908 PRIMARY KEY (id),
909 KEY order_id (order_id),
910 KEY meta_key (meta_key),
911 CONSTRAINT fk_tutor_ordermeta_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
912 ) $charset_collate;";
913
914 $order_items_table = "CREATE TABLE {$wpdb->prefix}tutor_order_items (
915 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
916 order_id BIGINT(20) UNSIGNED NOT NULL,
917 item_id BIGINT(20) UNSIGNED NOT NULL, -- course id/plan id
918 regular_price DECIMAL(13, 2) NOT NULL, -- course regular price
919 sale_price VARCHAR(13) DEFAULT NULL, -- course sale price
920 discount_price VARCHAR(13) DEFAULT NULL, -- course discount price
921 coupon_code VARCHAR(255) DEFAULT NULL, -- coupon code
922 PRIMARY KEY (id),
923 KEY order_id (order_id),
924 KEY item_id (item_id),
925 CONSTRAINT fk_tutor_order_item_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
926 ) $charset_collate;";
927
928 $coupons_table = "CREATE TABLE {$wpdb->prefix}tutor_coupons (
929 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
930 coupon_status VARCHAR(50),
931 coupon_type VARCHAR(100) DEFAULT 'code', -- coupon type 'code' or 'automatic'
932 coupon_code VARCHAR(50) NOT NULL,
933 coupon_title VARCHAR(255) NOT NULL,
934 coupon_description TEXT,
935 discount_type ENUM('percentage', 'flat') NOT NULL,
936 discount_amount DECIMAL(13, 2) NOT NULL,
937 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'
938 total_usage_limit INT(10) UNSIGNED DEFAULT NULL, -- null for unlimited usage
939 per_user_usage_limit TINYINT(4) UNSIGNED DEFAULT NULL, -- null for unlimited usage
940 purchase_requirement VARCHAR(50) DEFAULT 'no_minimum', -- possible values 'no_minimum', 'minimum_purchase', 'minimum_quantity'
941 purchase_requirement_value DECIMAL(13, 2),
942 start_date_gmt DATETIME NOT NULL,
943 expire_date_gmt DATETIME DEFAULT NULL,
944 created_at_gmt DATETIME NOT NULL,
945 created_by BIGINT(20) UNSIGNED NOT NULL,
946 updated_at_gmt DATETIME,
947 updated_by BIGINT(20) UNSIGNED NOT NULL,
948 PRIMARY KEY (id),
949 UNIQUE KEY coupon_code (coupon_code),
950 KEY start_date_gmt (start_date_gmt),
951 KEY expire_date_gmt (expire_date_gmt)
952 ) $charset_collate;";
953
954 $coupon_applications_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_applications (
955 coupon_code VARCHAR(50) NOT NULL,
956 reference_id BIGINT(20) UNSIGNED NOT NULL,
957 KEY coupon_code (coupon_code),
958 KEY reference_id (reference_id),
959 CONSTRAINT fk_tutor_coupon_application_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE
960 ) $charset_collate;";
961
962 $coupon_usage_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_usages (
963 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
964 coupon_code VARCHAR(50) NOT NULL,
965 user_id BIGINT(20) UNSIGNED NOT NULL,
966 PRIMARY KEY (id),
967 KEY coupon_code (coupon_code),
968 KEY user_id (user_id),
969 CONSTRAINT fk_tutor_coupon_usage_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE,
970 CONSTRAINT fk_tutor_coupon_usage_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
971 ) $charset_collate;";
972
973 $cart_table = "CREATE TABLE {$wpdb->prefix}tutor_carts (
974 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
975 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
976 coupon_code VARCHAR(50) DEFAULT NULL,
977 created_at_gmt DATETIME NOT NULL,
978 updated_at_gmt DATETIME,
979 PRIMARY KEY (id),
980 KEY user_id (user_id),
981 KEY coupon_code (coupon_code),
982 CONSTRAINT fk_tutor_cart_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
983 ) $charset_collate;";
984
985 $cart_items_table = "CREATE TABLE {$wpdb->prefix}tutor_cart_items (
986 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
987 cart_id BIGINT(20) UNSIGNED NOT NULL,
988 course_id BIGINT(20) UNSIGNED NOT NULL,
989 PRIMARY KEY (id),
990 KEY cart_id (cart_id),
991 KEY course_id (course_id),
992 CONSTRAINT fk_tutor_cart_item_cart_id FOREIGN KEY (cart_id) REFERENCES {$wpdb->prefix}tutor_carts(id) ON DELETE CASCADE,
993 CONSTRAINT fk_tutor_cart_item_course_id FOREIGN KEY (course_id) REFERENCES {$wpdb->prefix}posts(ID) ON DELETE CASCADE
994 ) $charset_collate;";
995
996 $customer_table = "CREATE TABLE {$wpdb->prefix}tutor_customers (
997 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
998 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
999 billing_first_name VARCHAR(255) NOT NULL,
1000 billing_last_name VARCHAR(255) NOT NULL,
1001 billing_email VARCHAR(255) NOT NULL,
1002 billing_phone VARCHAR(20) NOT NULL,
1003 billing_zip_code VARCHAR(20) NOT NULL,
1004 billing_address TEXT NOT NULL,
1005 billing_country VARCHAR(100) NOT NULL,
1006 billing_state VARCHAR(100) NOT NULL,
1007 billing_city VARCHAR(100) NOT NULL,
1008 PRIMARY KEY (id),
1009 KEY user_id (user_id),
1010 KEY billing_email (billing_email)
1011 ) $charset_collate;";
1012
1013 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1014 dbDelta( $quiz_attempts_sql );
1015 dbDelta( $quiz_attempt_answers );
1016 dbDelta( $tutor_quiz_questions );
1017 dbDelta( $tutor_quiz_question_answers );
1018 dbDelta( $earning_table );
1019 dbDelta( $withdraw_table );
1020 dbDelta( $orders_table );
1021 dbDelta( $order_meta_table );
1022 dbDelta( $order_items_table );
1023 dbDelta( $coupons_table );
1024 dbDelta( $coupon_applications_table );
1025 dbDelta( $coupon_usage_table );
1026 dbDelta( $cart_table );
1027 dbDelta( $cart_items_table );
1028 dbDelta( $customer_table );
1029 }
1030
1031 /**
1032 * Manage tutor roles & permission
1033 *
1034 * @return void
1035 */
1036 public static function manage_tutor_roles_and_permissions() {
1037 /**
1038 * Add role for instructor
1039 */
1040 $instructor_role = tutor()->instructor_role;
1041
1042 remove_role( $instructor_role );
1043 add_role( $instructor_role, __( 'Tutor Instructor', 'tutor' ), array() );
1044
1045 $custom_post_type_permission = array(
1046 // Manage Instructor.
1047 'manage_tutor_instructor',
1048
1049 // Tutor Posts Type Permission.
1050 'edit_tutor_course',
1051 'read_tutor_course',
1052 'delete_tutor_course',
1053 'delete_tutor_courses',
1054 'edit_tutor_courses',
1055 'edit_others_tutor_courses',
1056 'read_private_tutor_courses',
1057 'edit_tutor_courses',
1058
1059 'edit_tutor_lesson',
1060 'read_tutor_lesson',
1061 'delete_tutor_lesson',
1062 'delete_tutor_lessons',
1063 'edit_tutor_lessons',
1064 'edit_others_tutor_lessons',
1065 'read_private_tutor_lessons',
1066 'edit_tutor_lessons',
1067 'publish_tutor_lessons',
1068
1069 'edit_tutor_quiz',
1070 'read_tutor_quiz',
1071 'delete_tutor_quiz',
1072 'delete_tutor_quizzes',
1073 'edit_tutor_quizzes',
1074 'edit_others_tutor_quizzes',
1075 'read_private_tutor_quizzes',
1076 'edit_tutor_quizzes',
1077 'publish_tutor_quizzes',
1078
1079 'edit_tutor_question',
1080 'read_tutor_question',
1081 'delete_tutor_question',
1082 'delete_tutor_questions',
1083 'edit_tutor_questions',
1084 'edit_others_tutor_questions',
1085 'publish_tutor_questions',
1086 'read_private_tutor_questions',
1087 'edit_tutor_questions',
1088 );
1089
1090 $instructor = get_role( $instructor_role );
1091 if ( $instructor ) {
1092 $instructor_cap = array(
1093 'edit_posts',
1094 'read',
1095 'upload_files',
1096 );
1097
1098 $instructor_cap = array_merge( $instructor_cap, $custom_post_type_permission );
1099
1100 $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
1101 if ( $can_publish_course ) {
1102 $instructor_cap[] = 'publish_tutor_courses';
1103 }
1104
1105 foreach ( $instructor_cap as $cap ) {
1106 $instructor->add_cap( $cap );
1107 }
1108 }
1109
1110 $administrator = get_role( 'administrator' );
1111 if ( $administrator ) {
1112
1113 $administrator_cap = array(
1114 'manage_tutor',
1115 );
1116 $administrator_cap = array_merge( $administrator_cap, $custom_post_type_permission );
1117 $administrator_cap[] = 'publish_tutor_courses';
1118
1119 foreach ( $administrator_cap as $cap ) {
1120 $administrator->add_cap( $cap );
1121 }
1122 }
1123
1124 /**
1125 * Add Instructor role to administrator
1126 */
1127 if ( current_user_can( 'administrator' ) ) {
1128 tutor_utils()->add_instructor_role( get_current_user_id() );
1129 }
1130 }
1131
1132 /**
1133 * On plugin activate save initial data
1134 * Like: generate tutor pages
1135 *
1136 * @since 1.0.0
1137 *
1138 * @return void
1139 */
1140 public static function save_data() {
1141
1142 $student_dashboard_args = array(
1143 'post_title' => __( 'Dashboard', 'tutor' ),
1144 'post_content' => '',
1145 'post_type' => 'page',
1146 'post_status' => 'publish',
1147 );
1148 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
1149 tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id );
1150
1151 $student_registration_args = array(
1152 'post_title' => __( 'Student Registration', 'tutor' ),
1153 'post_content' => '[tutor_student_registration_form]',
1154 'post_type' => 'page',
1155 'post_status' => 'publish',
1156 );
1157 $student_register_page_id = wp_insert_post( $student_registration_args );
1158 tutor_utils()->update_option( 'student_register_page', $student_register_page_id );
1159
1160 $instructor_registration_args = array(
1161 'post_title' => __( 'Instructor Registration', 'tutor' ),
1162 'post_content' => '[tutor_instructor_registration_form]',
1163 'post_type' => 'page',
1164 'post_status' => 'publish',
1165 );
1166 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
1167 tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id );
1168 }
1169
1170 /**
1171 * Default options
1172 *
1173 * @since 1.0.0
1174 *
1175 * @since 3.4.1 Supported video sources added
1176 *
1177 * @return array
1178 */
1179 public static function default_options() {
1180 $options = array(
1181 'pagination_per_page' => '20',
1182 'course_allow_upload_private_files' => '1',
1183 'display_course_instructors' => '1',
1184 'enable_q_and_a_on_course' => '1',
1185 'courses_col_per_row' => '3',
1186 'courses_per_page' => '12',
1187 'course_permalink_base' => 'courses',
1188 'lesson_permalink_base' => 'lessons',
1189 'quiz_when_time_expires' => 'autosubmit',
1190 'quiz_attempts_allowed' => '10',
1191 'quiz_grade_method' => 'highest_grade',
1192 'enable_public_profile' => '1',
1193 'email_to_students' =>
1194 array(
1195 'quiz_completed' => '1',
1196 'completed_course' => '1',
1197 ),
1198 'email_to_instructors' =>
1199 array(
1200 'a_student_enrolled_in_course' => '1',
1201 'a_student_completed_course' => '1',
1202 'a_student_completed_lesson' => '1',
1203 'a_student_placed_question' => '1',
1204 ),
1205 'email_from_name' => get_option( 'blogname' ),
1206 'email_from_address' => get_option( 'admin_email' ),
1207 'email_footer_text' => '',
1208 'earning_admin_commission' => '20',
1209 'earning_instructor_commission' => '80',
1210 'color_preset_type' => 'default',
1211
1212 // Default options for tutor ecommerce.
1213 'monetize_by' => Ecommerce::MONETIZE_BY,
1214 'currency_code' => 'USD',
1215 'currency_position' => 'left',
1216 'thousand_separator' => ',',
1217 'decimal_separator' => '.',
1218 'number_of_decimals' => '2',
1219 'is_coupon_applicable' => 'on',
1220 'supported_video_sources' => array(
1221 'html5',
1222 'external_url',
1223 'youtube',
1224 'vimeo',
1225 'embedded',
1226 'shortcode',
1227 ),
1228 );
1229
1230 return $options;
1231 }
1232
1233
1234 /**
1235 * Create withdraw database
1236 *
1237 * @since 1.2.0
1238 */
1239 public static function create_withdraw_database() {
1240 global $wpdb;
1241
1242 $charset_collate = $wpdb->get_charset_collate();
1243
1244 /**
1245 * Table SQL
1246 *
1247 * {$wpdb->prefix}tutor_earnings
1248 * {$wpdb->prefix}tutor_withdraws
1249 *
1250 * @since 1.2.0
1251 */
1252
1253 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
1254 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
1255 user_id bigint(20) DEFAULT NULL,
1256 course_id bigint(20) DEFAULT NULL,
1257 order_id bigint(20) DEFAULT NULL,
1258 order_status varchar(50) DEFAULT NULL,
1259 course_price_total decimal(16,2) DEFAULT NULL,
1260 course_price_grand_total decimal(16,2) DEFAULT NULL,
1261 instructor_amount decimal(16,2) DEFAULT NULL,
1262 instructor_rate decimal(16,2) DEFAULT NULL,
1263 admin_amount decimal(16,2) DEFAULT NULL,
1264 admin_rate decimal(16,2) DEFAULT NULL,
1265 commission_type varchar(20) DEFAULT NULL,
1266 deduct_fees_amount decimal(16,2) DEFAULT NULL,
1267 deduct_fees_name varchar(250) DEFAULT NULL,
1268 deduct_fees_type varchar(20) DEFAULT NULL,
1269 process_by varchar(20) DEFAULT NULL,
1270 created_at datetime DEFAULT NULL,
1271 PRIMARY KEY (earning_id)
1272 ) $charset_collate;";
1273
1274 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
1275 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
1276 user_id bigint(20) DEFAULT NULL,
1277 amount decimal(16,2) DEFAULT NULL,
1278 method_data text DEFAULT NULL,
1279 status varchar(50) DEFAULT NULL,
1280 updated_at datetime DEFAULT NULL,
1281 created_at datetime DEFAULT NULL,
1282 PRIMARY KEY (withdraw_id)
1283 ) $charset_collate;";
1284
1285 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1286 dbDelta( $earning_table );
1287 dbDelta( $withdraw_table );
1288
1289 /**
1290 * Setting previous dashboard to new dashboard
1291 */
1292 $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' );
1293 tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id );
1294 }
1295
1296 /**
1297 * Filter the wp_doing_ajax from tutor requests to get advanced
1298 * advantages from Tutor
1299 *
1300 * @since 1.3.4
1301 *
1302 * @param bool $bool default value.
1303 *
1304 * @return bool
1305 */
1306 public function wp_doing_ajax( $bool ) {
1307 // Don't use Input::has helper to avoid conflict.
1308 if ( isset( $_REQUEST['tutor_ajax_action'] ) ) {
1309 return true;
1310 }
1311 return $bool;
1312 }
1313
1314 /**
1315 * Handle plugin un-installation
1316 *
1317 * @since 2.6.2
1318 *
1319 * @return void
1320 */
1321 public static function tutor_uninstall() {
1322 self::erase_tutor_data();
1323 }
1324
1325 /**
1326 * Erase tutor data
1327 *
1328 * @since 2.6.2
1329 *
1330 * @return void
1331 */
1332 public static function erase_tutor_data() {
1333 global $wpdb;
1334
1335 $is_erase_data = tutor_utils()->get_option( 'delete_on_uninstall' );
1336 // Deleting Data.
1337
1338 if ( $is_erase_data ) {
1339 /**
1340 * Deleting Post Type, Meta Data, taxonomy
1341 */
1342 $course_post_type = tutor()->course_post_type;
1343 $lesson_post_type = tutor()->lesson_post_type;
1344
1345 $post_types = array(
1346 $course_post_type,
1347 $lesson_post_type,
1348 'tutor_quiz',
1349 'tutor_enrolled',
1350 'topics',
1351 'tutor_enrolled',
1352 'tutor_announcements',
1353 );
1354
1355 $post_type_strings = "'" . implode( "','", $post_types ) . "'";
1356 $tutor_posts = $wpdb->get_col( "SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;" ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1357
1358 if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) {
1359 foreach ( $tutor_posts as $post_id ) {
1360 // Delete categories.
1361 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_CATEGORY );
1362 foreach ( $terms as $term ) {
1363 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_CATEGORY );
1364 }
1365
1366 // Delete tags if available.
1367 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_TAG );
1368 foreach ( $terms as $term ) {
1369 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_TAG );
1370 }
1371
1372 // Delete All Meta.
1373 $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $post_id ) );
1374 $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
1375 }
1376 }
1377
1378 /**
1379 * Deleting Comments (reviews, questions, quiz_answers, etc)
1380 */
1381 $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" );
1382 $comments_ids_strings = "'" . implode( "','", $tutor_comments ) . "'";
1383 if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) {
1384 $wpdb->query( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) " ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1385 }
1386 $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) );
1387
1388 /**
1389 * Delete Options
1390 */
1391
1392 delete_option( 'tutor_option' );
1393 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_student' ) );
1394 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_approved' ) );
1395 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_status' ) );
1396 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_instructor' ) );
1397 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_tutor_completed_lesson_id_%' " );
1398
1399 // Deleting Table.
1400 $prefix = $wpdb->prefix;
1401 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1402 $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 " );
1403
1404 }
1405 }
1406 }
1407