PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.6.4
Tutor LMS – eLearning and online course solution v3.6.4
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 1 year 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 11 months 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
1405 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 do_action( 'tutor_before_load' );
491
492 $this->addons = new Addons();
493 $this->post_types = new Post_types();
494 $this->taxonomies = new Taxonomies();
495 $this->assets = new Assets();
496 $this->admin = new Admin();
497 $this->ajax = new Ajax();
498 $this->options = new Options_V2();
499 $this->shortcode = new Shortcode();
500 $this->course = new Course();
501 $this->lesson = new Lesson();
502 $this->rewrite_rules = new Rewrite_Rules();
503 $this->template = new Template();
504 $this->instructor = new Instructor();
505 $this->student = new Student();
506 $this->q_and_a = new Q_And_A();
507 $this->q_and_a_list = new Question_Answers_List();
508 $this->q_attempt = new Quiz_Attempts_List();
509 $this->quiz = new Quiz();
510 $this->tools = new Tools();
511 $this->user = new User();
512 $this->theme_compatibility = new Theme_Compatibility();
513 $this->gutenberg = new Gutenberg();
514 $this->course_settings_tabs = new Course_Settings_Tabs();
515 $this->withdraw = new Withdraw();
516 $this->upgrader = new Upgrader();
517 $this->dashboard = new Dashboard();
518 $this->form_handler = new FormHandler();
519 $this->frontend = new Frontend();
520 $this->rest_api = new RestAPI();
521 $this->setup = new Tutor_Setup();
522 $this->private_course_access = new Private_Course_Access();
523 $this->course_filter = new Course_Filter();
524 $this->permalink = new Permalink();
525
526 // Integrations.
527 $this->woocommerce = new WooCommerce();
528 $this->edd = new TutorEDD();
529
530 /**
531 * Init obj
532 *
533 * @since 2.0.0
534 */
535 $this->announcements = new Announcements();
536 $this->course_list = new Course_List();
537 $this->reviews = new Reviews();
538 $this->withdraw_list = new Withdraw_Requests_List();
539 $this->student_list = new Students_List();
540 $this->instructor_list = new Instructors_List();
541 $this->course_embed = new Course_Embed();
542 $this->rest_auth = new RestAuth();
543
544 /**
545 * New Course Builder.
546 *
547 * @since 3.0.0
548 */
549 new QuizBuilder();
550
551 /**
552 * Tutor native e-commerce
553 *
554 * @since 3.0.0
555 */
556 new Ecommerce();
557
558 /**
559 * Run Method
560 *
561 * @since v.1.2.0
562 */
563 $this->run();
564
565 do_action( 'tutor_loaded' );
566
567 add_action( 'init', array( $this, 'init_action' ) );
568
569 /**
570 * Check activated plugin
571 *
572 * @since 1.5.7
573 */
574
575 add_action( 'activated_plugin', array( $this, 'activated_tutor' ), 10, 2 );
576
577 /**
578 * Redirect to setup page
579 *
580 * @since 2.8.0
581 */
582 add_action( 'admin_init', array( $this, 'redirect_to_setup_page' ) );
583 }
584
585 /**
586 * Check activated plugin
587 *
588 * @since 1.5.7
589 *
590 * @param mixed $plugin plugin.
591 * @param mixed $network_wide network wide.
592 *
593 * @return void
594 */
595 public function activated_tutor( $plugin, $network_wide = null ) {
596 if ( tutor()->basename === $plugin ) {
597 $this->redirect_to_setup_page();
598 }
599 }
600
601 /**
602 * Redirect to setup page
603 *
604 * @since 2.8.0
605 *
606 * @return void
607 */
608 public function redirect_to_setup_page() {
609 if ( ( ! get_option( 'tutor_wizard' ) ) && version_compare( TUTOR_VERSION, '1.5.6', '>' ) ) {
610 if ( ! wp_doing_ajax() ) {
611 update_option( 'tutor_wizard', 'active' );
612 wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) );
613 exit;
614 }
615 }
616 }
617
618 /**
619 * Include utility functions
620 *
621 * @return void
622 */
623 public function includes() {
624 $tutor_path = plugin_dir_path( TUTOR_FILE );
625
626 include $tutor_path . 'includes/tutor-general-functions.php';
627 include $tutor_path . 'includes/tutor-template-functions.php';
628 include $tutor_path . 'includes/tutor-template-hook.php';
629 include $tutor_path . 'includes/translate-text.php';
630 include $tutor_path . 'includes/country.php';
631 include $tutor_path . 'includes/ecommerce-functions.php';
632
633 if ( ! function_exists( 'is_plugin_active' ) ) {
634 require_once ABSPATH . 'wp-admin/includes/plugin.php';
635 }
636
637 $is_droip_active = \is_plugin_active( 'droip/droip.php' );
638 $tutor_droip_path = $tutor_path . 'includes/droip/droip.php';
639 if ( $is_droip_active && file_exists( $tutor_droip_path ) ) {
640 include $tutor_droip_path;
641 }
642 }
643
644 /**
645 * Providing hooks
646 *
647 * @return void
648 */
649 public function run() {
650 do_action( 'tutor_before_run' );
651 do_action( 'tutor_after_run' );
652 }
653
654 /**
655 * Tutor Action Via do_action
656 *
657 * @since 1.2.14
658 */
659 public function init_action() {
660 $tutor_action = Input::sanitize_request_data( 'tutor_action' );
661 if ( '' !== $tutor_action ) {
662 do_action( 'tutor_action_' . $tutor_action );
663 }
664 }
665
666 /**
667 * Do some task during plugin activation
668 */
669 public static function tutor_activate() {
670 $version = get_option( 'tutor_version' );
671 if ( ! function_exists( 'tutor_time' ) ) {
672 include tutor()->path . 'includes/tutor-general-functions.php';
673 }
674
675 // Create Database.
676 self::create_database();
677
678 // Save Option.
679 if ( ! $version ) {
680
681 $options = self::default_options();
682 update_option( 'tutor_option', $options );
683
684 // Rewrite Flush.
685 Permalink::set_permalink_flag();
686 self::manage_tutor_roles_and_permissions();
687
688 // Save initial Page.
689 self::save_data();
690 update_option( 'tutor_version', TUTOR_VERSION );
691 }
692
693 // Set Schedule.
694 if ( ! wp_next_scheduled( 'tutor_once_in_day_run_schedule' ) ) {
695 wp_schedule_event( tutor_time(), 'twicedaily', 'tutor_once_in_day_run_schedule' );
696 }
697
698 /**
699 * Backward Compatibility for version < 1.2.0
700 */
701 if ( version_compare( get_option( 'tutor_version' ), '1.2.0', '<' ) ) {
702 /**
703 * Creating New Database
704 */
705 self::create_withdraw_database();
706 // Update the tutor version.
707 update_option( 'tutor_version', '1.2.0' );
708 // Rewrite Flush.
709 Permalink::set_permalink_flag();
710 }
711
712 /**
713 * Backward Compatibility to < 1.3.1 for make course plural
714 */
715 if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) {
716 global $wpdb;
717
718 if ( ! get_option( 'is_course_post_type_updated' ) ) {
719 $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) );
720 update_option( 'is_course_post_type_updated', true );
721 update_option( 'tutor_version', '1.3.1' );
722 Permalink::set_permalink_flag();
723 }
724 }
725
726 /**
727 * Save First activation Time
728 */
729 $first_activation_date = get_option( 'tutor_first_activation_time' );
730 if ( ! $first_activation_date ) {
731 update_option( 'tutor_first_activation_time', tutor_time() );
732 }
733 }
734
735 /**
736 * Run task on deactivation
737 *
738 * @since 1.0.0
739 *
740 * @return void
741 */
742 public static function tutor_deactivation() {
743 wp_clear_scheduled_hook( 'tutor_once_in_day_run_schedule' );
744 }
745
746 /**
747 * Create database
748 *
749 * @return void
750 */
751 public static function create_database() {
752 global $wpdb;
753
754 $charset_collate = $wpdb->get_charset_collate();
755
756 /**
757 * Table SQL
758 *
759 * {$wpdb->prefix}tutor_quiz_attempts
760 * {$wpdb->prefix}tutor_quiz_attempt_answers
761 * {$wpdb->prefix}tutor_quiz_questions
762 * {$wpdb->prefix}tutor_quiz_question_answers
763 * {$wpdb->prefix}tutor_earnings
764 * {$wpdb->prefix}tutor_withdraws
765 *
766 * @since 1.0.0
767 */
768 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
769 attempt_id bigint(20) NOT NULL AUTO_INCREMENT,
770 course_id bigint(20) DEFAULT NULL,
771 quiz_id bigint(20) DEFAULT NULL,
772 user_id bigint(20) DEFAULT NULL,
773 total_questions int(11) DEFAULT NULL,
774 total_answered_questions int(11) DEFAULT NULL,
775 total_marks decimal(9,2) DEFAULT NULL,
776 earned_marks decimal(9,2) DEFAULT NULL,
777 attempt_info text,
778 attempt_status varchar(50) DEFAULT NULL,
779 attempt_ip varchar(250) DEFAULT NULL,
780 attempt_started_at datetime DEFAULT NULL,
781 attempt_ended_at datetime DEFAULT NULL,
782 is_manually_reviewed int(1) DEFAULT NULL,
783 manually_reviewed_at datetime DEFAULT NULL,
784 PRIMARY KEY (attempt_id)
785 ) $charset_collate;";
786
787 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
788 attempt_answer_id bigint(20) NOT NULL AUTO_INCREMENT,
789 user_id bigint(20) DEFAULT NULL,
790 quiz_id bigint(20) DEFAULT NULL,
791 question_id bigint(20) DEFAULT NULL,
792 quiz_attempt_id bigint(20) DEFAULT NULL,
793 given_answer longtext,
794 question_mark decimal(8,2) DEFAULT NULL,
795 achieved_mark decimal(8,2) DEFAULT NULL,
796 minus_mark decimal(8,2) DEFAULT NULL,
797 is_correct tinyint(4) DEFAULT NULL,
798 PRIMARY KEY (attempt_answer_id)
799 ) $charset_collate;";
800
801 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
802 question_id bigint(20) NOT NULL AUTO_INCREMENT,
803 quiz_id bigint(20) DEFAULT NULL,
804 question_title text,
805 question_description longtext,
806 answer_explanation longtext DEFAULT '',
807 question_type varchar(50) DEFAULT NULL,
808 question_mark decimal(9,2) DEFAULT NULL,
809 question_settings longtext,
810 question_order int(11) DEFAULT NULL,
811 PRIMARY KEY (question_id)
812 ) $charset_collate;";
813
814 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
815 answer_id bigint(20) NOT NULL AUTO_INCREMENT,
816 belongs_question_id bigint(20) DEFAULT NULL,
817 belongs_question_type varchar(250) DEFAULT NULL,
818 answer_title text,
819 is_correct tinyint(4) DEFAULT NULL,
820 image_id bigint(20) DEFAULT NULL,
821 answer_two_gap_match text,
822 answer_view_format varchar(250) DEFAULT NULL,
823 answer_settings text,
824 answer_order int(11) DEFAULT '0',
825 PRIMARY KEY (answer_id)
826 ) $charset_collate;";
827
828 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
829 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
830 user_id bigint(20) DEFAULT NULL,
831 course_id bigint(20) DEFAULT NULL,
832 order_id bigint(20) DEFAULT NULL,
833 order_status varchar(50) DEFAULT NULL,
834 course_price_total decimal(16,2) DEFAULT NULL,
835 course_price_grand_total decimal(16,2) DEFAULT NULL,
836 instructor_amount decimal(16,2) DEFAULT NULL,
837 instructor_rate decimal(16,2) DEFAULT NULL,
838 admin_amount decimal(16,2) DEFAULT NULL,
839 admin_rate decimal(16,2) DEFAULT NULL,
840 commission_type varchar(20) DEFAULT NULL,
841 deduct_fees_amount decimal(16,2) DEFAULT NULL,
842 deduct_fees_name varchar(250) DEFAULT NULL,
843 deduct_fees_type varchar(20) DEFAULT NULL,
844 process_by varchar(20) DEFAULT NULL,
845 created_at datetime DEFAULT NULL,
846 PRIMARY KEY (earning_id)
847 ) $charset_collate;";
848
849 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
850 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
851 user_id bigint(20) DEFAULT NULL,
852 amount decimal(16,2) DEFAULT NULL,
853 method_data text DEFAULT NULL,
854 status varchar(50) DEFAULT NULL,
855 updated_at datetime DEFAULT NULL,
856 created_at datetime DEFAULT NULL,
857 PRIMARY KEY (withdraw_id)
858 ) $charset_collate;";
859
860 $orders_table = "CREATE TABLE {$wpdb->prefix}tutor_orders (
861 id BIGINT(20) UNSIGNED AUTO_INCREMENT,
862 parent_id BIGINT(20) UNSIGNED DEFAULT 0, -- for subscription order, store subscription record id
863 transaction_id VARCHAR(255) COMMENT 'Transaction id from payment gateway',
864 user_id BIGINT(20) UNSIGNED NOT NULL,
865 order_type VARCHAR(50) NOT NULL, -- single_order, subscription
866 order_status VARCHAR(50) NOT NULL,
867 payment_status VARCHAR(50) NOT NULL,
868 subtotal_price DECIMAL(13, 2) NOT NULL, -- price calculation based on course sale price
869 total_price DECIMAL(13, 2) NOT NULL, -- final price
870 net_payment DECIMAL(13, 2) NOT NULL, -- calculated price if any refund is done else same as total_price
871 coupon_code VARCHAR(255),
872 coupon_amount DECIMAL(13, 2),
873 discount_type ENUM('percentage', 'flat') DEFAULT NULL,
874 discount_amount DECIMAL(13, 2),
875 discount_reason TEXT,
876 tax_rate DECIMAL(13, 2) COMMENT 'Tax percentage',
877 tax_amount DECIMAL(13, 2),
878 fees DECIMAL(13, 2), -- payment gateway fees
879 earnings DECIMAL(13, 2), -- net earning
880 refund_amount DECIMAL(13, 2), -- Refund amount
881 payment_method VARCHAR(255),
882 payment_payloads LONGTEXT,
883 note TEXT,
884 created_at_gmt DATETIME NOT NULL,
885 created_by BIGINT(20) UNSIGNED NOT NULL,
886 updated_at_gmt DATETIME,
887 updated_by BIGINT(20) UNSIGNED NOT NULL,
888 PRIMARY KEY (id),
889 KEY user_id (user_id),
890 KEY order_type (order_type),
891 KEY payment_status (payment_status),
892 KEY order_status (order_status),
893 KEY transaction_id (transaction_id)
894 ) $charset_collate;";
895
896 $order_meta_table = "CREATE TABLE {$wpdb->prefix}tutor_ordermeta (
897 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
898 order_id BIGINT(20) UNSIGNED NOT NULL,
899 meta_key VARCHAR(255) NOT NULL,
900 meta_value LONGTEXT NOT NULL,
901 created_at_gmt DATETIME NOT NULL,
902 created_by BIGINT(20) UNSIGNED NOT NULL,
903 updated_at_gmt DATETIME,
904 updated_by BIGINT(20) UNSIGNED NOT NULL,
905 PRIMARY KEY (id),
906 KEY order_id (order_id),
907 KEY meta_key (meta_key),
908 CONSTRAINT fk_tutor_ordermeta_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
909 ) $charset_collate;";
910
911 $order_items_table = "CREATE TABLE {$wpdb->prefix}tutor_order_items (
912 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
913 order_id BIGINT(20) UNSIGNED NOT NULL,
914 item_id BIGINT(20) UNSIGNED NOT NULL, -- course id/plan id
915 regular_price DECIMAL(13, 2) NOT NULL, -- course regular price
916 sale_price VARCHAR(13) DEFAULT NULL, -- course sale price
917 discount_price VARCHAR(13) DEFAULT NULL, -- course discount price
918 coupon_code VARCHAR(255) DEFAULT NULL, -- coupon code
919 PRIMARY KEY (id),
920 KEY order_id (order_id),
921 KEY item_id (item_id),
922 CONSTRAINT fk_tutor_order_item_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
923 ) $charset_collate;";
924
925 $coupons_table = "CREATE TABLE {$wpdb->prefix}tutor_coupons (
926 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
927 coupon_status VARCHAR(50),
928 coupon_type VARCHAR(100) DEFAULT 'code', -- coupon type 'code' or 'automatic'
929 coupon_code VARCHAR(50) NOT NULL,
930 coupon_title VARCHAR(255) NOT NULL,
931 coupon_description TEXT,
932 discount_type ENUM('percentage', 'flat') NOT NULL,
933 discount_amount DECIMAL(13, 2) NOT NULL,
934 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'
935 total_usage_limit INT(10) UNSIGNED DEFAULT NULL, -- null for unlimited usage
936 per_user_usage_limit TINYINT(4) UNSIGNED DEFAULT NULL, -- null for unlimited usage
937 purchase_requirement VARCHAR(50) DEFAULT 'no_minimum', -- possible values 'no_minimum', 'minimum_purchase', 'minimum_quantity'
938 purchase_requirement_value DECIMAL(13, 2),
939 start_date_gmt DATETIME NOT NULL,
940 expire_date_gmt DATETIME DEFAULT NULL,
941 created_at_gmt DATETIME NOT NULL,
942 created_by BIGINT(20) UNSIGNED NOT NULL,
943 updated_at_gmt DATETIME,
944 updated_by BIGINT(20) UNSIGNED NOT NULL,
945 PRIMARY KEY (id),
946 UNIQUE KEY coupon_code (coupon_code),
947 KEY start_date_gmt (start_date_gmt),
948 KEY expire_date_gmt (expire_date_gmt)
949 ) $charset_collate;";
950
951 $coupon_applications_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_applications (
952 coupon_code VARCHAR(50) NOT NULL,
953 reference_id BIGINT(20) UNSIGNED NOT NULL,
954 KEY coupon_code (coupon_code),
955 KEY reference_id (reference_id),
956 CONSTRAINT fk_tutor_coupon_application_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE
957 ) $charset_collate;";
958
959 $coupon_usage_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_usages (
960 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
961 coupon_code VARCHAR(50) NOT NULL,
962 user_id BIGINT(20) UNSIGNED NOT NULL,
963 PRIMARY KEY (id),
964 KEY coupon_code (coupon_code),
965 KEY user_id (user_id),
966 CONSTRAINT fk_tutor_coupon_usage_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE,
967 CONSTRAINT fk_tutor_coupon_usage_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
968 ) $charset_collate;";
969
970 $cart_table = "CREATE TABLE {$wpdb->prefix}tutor_carts (
971 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
972 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
973 coupon_code VARCHAR(50) DEFAULT NULL,
974 created_at_gmt DATETIME NOT NULL,
975 updated_at_gmt DATETIME,
976 PRIMARY KEY (id),
977 KEY user_id (user_id),
978 KEY coupon_code (coupon_code),
979 CONSTRAINT fk_tutor_cart_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
980 ) $charset_collate;";
981
982 $cart_items_table = "CREATE TABLE {$wpdb->prefix}tutor_cart_items (
983 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
984 cart_id BIGINT(20) UNSIGNED NOT NULL,
985 course_id BIGINT(20) UNSIGNED NOT NULL,
986 PRIMARY KEY (id),
987 KEY cart_id (cart_id),
988 KEY course_id (course_id),
989 CONSTRAINT fk_tutor_cart_item_cart_id FOREIGN KEY (cart_id) REFERENCES {$wpdb->prefix}tutor_carts(id) ON DELETE CASCADE,
990 CONSTRAINT fk_tutor_cart_item_course_id FOREIGN KEY (course_id) REFERENCES {$wpdb->prefix}posts(ID) ON DELETE CASCADE
991 ) $charset_collate;";
992
993 $customer_table = "CREATE TABLE {$wpdb->prefix}tutor_customers (
994 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
995 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
996 billing_first_name VARCHAR(255) NOT NULL,
997 billing_last_name VARCHAR(255) NOT NULL,
998 billing_email VARCHAR(255) NOT NULL,
999 billing_phone VARCHAR(20) NOT NULL,
1000 billing_zip_code VARCHAR(20) NOT NULL,
1001 billing_address TEXT NOT NULL,
1002 billing_country VARCHAR(100) NOT NULL,
1003 billing_state VARCHAR(100) NOT NULL,
1004 billing_city VARCHAR(100) NOT NULL,
1005 PRIMARY KEY (id),
1006 KEY user_id (user_id),
1007 KEY billing_email (billing_email)
1008 ) $charset_collate;";
1009
1010 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1011 dbDelta( $quiz_attempts_sql );
1012 dbDelta( $quiz_attempt_answers );
1013 dbDelta( $tutor_quiz_questions );
1014 dbDelta( $tutor_quiz_question_answers );
1015 dbDelta( $earning_table );
1016 dbDelta( $withdraw_table );
1017 dbDelta( $orders_table );
1018 dbDelta( $order_meta_table );
1019 dbDelta( $order_items_table );
1020 dbDelta( $coupons_table );
1021 dbDelta( $coupon_applications_table );
1022 dbDelta( $coupon_usage_table );
1023 dbDelta( $cart_table );
1024 dbDelta( $cart_items_table );
1025 dbDelta( $customer_table );
1026 }
1027
1028 /**
1029 * Manage tutor roles & permission
1030 *
1031 * @return void
1032 */
1033 public static function manage_tutor_roles_and_permissions() {
1034 /**
1035 * Add role for instructor
1036 */
1037 $instructor_role = tutor()->instructor_role;
1038
1039 remove_role( $instructor_role );
1040 add_role( $instructor_role, __( 'Tutor Instructor', 'tutor' ), array() );
1041
1042 $custom_post_type_permission = array(
1043 // Manage Instructor.
1044 'manage_tutor_instructor',
1045
1046 // Tutor Posts Type Permission.
1047 'edit_tutor_course',
1048 'read_tutor_course',
1049 'delete_tutor_course',
1050 'delete_tutor_courses',
1051 'edit_tutor_courses',
1052 'edit_others_tutor_courses',
1053 'read_private_tutor_courses',
1054 'edit_tutor_courses',
1055
1056 'edit_tutor_lesson',
1057 'read_tutor_lesson',
1058 'delete_tutor_lesson',
1059 'delete_tutor_lessons',
1060 'edit_tutor_lessons',
1061 'edit_others_tutor_lessons',
1062 'read_private_tutor_lessons',
1063 'edit_tutor_lessons',
1064 'publish_tutor_lessons',
1065
1066 'edit_tutor_quiz',
1067 'read_tutor_quiz',
1068 'delete_tutor_quiz',
1069 'delete_tutor_quizzes',
1070 'edit_tutor_quizzes',
1071 'edit_others_tutor_quizzes',
1072 'read_private_tutor_quizzes',
1073 'edit_tutor_quizzes',
1074 'publish_tutor_quizzes',
1075
1076 'edit_tutor_question',
1077 'read_tutor_question',
1078 'delete_tutor_question',
1079 'delete_tutor_questions',
1080 'edit_tutor_questions',
1081 'edit_others_tutor_questions',
1082 'publish_tutor_questions',
1083 'read_private_tutor_questions',
1084 'edit_tutor_questions',
1085 );
1086
1087 $instructor = get_role( $instructor_role );
1088 if ( $instructor ) {
1089 $instructor_cap = array(
1090 'edit_posts',
1091 'read',
1092 'upload_files',
1093 );
1094
1095 $instructor_cap = array_merge( $instructor_cap, $custom_post_type_permission );
1096
1097 $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
1098 if ( $can_publish_course ) {
1099 $instructor_cap[] = 'publish_tutor_courses';
1100 }
1101
1102 foreach ( $instructor_cap as $cap ) {
1103 $instructor->add_cap( $cap );
1104 }
1105 }
1106
1107 $administrator = get_role( 'administrator' );
1108 if ( $administrator ) {
1109
1110 $administrator_cap = array(
1111 'manage_tutor',
1112 );
1113 $administrator_cap = array_merge( $administrator_cap, $custom_post_type_permission );
1114 $administrator_cap[] = 'publish_tutor_courses';
1115
1116 foreach ( $administrator_cap as $cap ) {
1117 $administrator->add_cap( $cap );
1118 }
1119 }
1120
1121 /**
1122 * Add Instructor role to administrator
1123 */
1124 if ( current_user_can( 'administrator' ) ) {
1125 tutor_utils()->add_instructor_role( get_current_user_id() );
1126 }
1127 }
1128
1129 /**
1130 * On plugin activate save initial data
1131 * Like: generate tutor pages
1132 *
1133 * @since 1.0.0
1134 *
1135 * @return void
1136 */
1137 public static function save_data() {
1138
1139 $student_dashboard_args = array(
1140 'post_title' => __( 'Dashboard', 'tutor' ),
1141 'post_content' => '',
1142 'post_type' => 'page',
1143 'post_status' => 'publish',
1144 );
1145 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
1146 tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id );
1147
1148 $student_registration_args = array(
1149 'post_title' => __( 'Student Registration', 'tutor' ),
1150 'post_content' => '[tutor_student_registration_form]',
1151 'post_type' => 'page',
1152 'post_status' => 'publish',
1153 );
1154 $student_register_page_id = wp_insert_post( $student_registration_args );
1155 tutor_utils()->update_option( 'student_register_page', $student_register_page_id );
1156
1157 $instructor_registration_args = array(
1158 'post_title' => __( 'Instructor Registration', 'tutor' ),
1159 'post_content' => '[tutor_instructor_registration_form]',
1160 'post_type' => 'page',
1161 'post_status' => 'publish',
1162 );
1163 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
1164 tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id );
1165 }
1166
1167 /**
1168 * Default options
1169 *
1170 * @since 1.0.0
1171 *
1172 * @since 3.4.1 Supported video sources added
1173 *
1174 * @return array
1175 */
1176 public static function default_options() {
1177 $options = array(
1178 'pagination_per_page' => '20',
1179 'course_allow_upload_private_files' => '1',
1180 'display_course_instructors' => '1',
1181 'enable_q_and_a_on_course' => '1',
1182 'courses_col_per_row' => '3',
1183 'courses_per_page' => '12',
1184 'course_permalink_base' => 'courses',
1185 'lesson_permalink_base' => 'lessons',
1186 'quiz_when_time_expires' => 'autosubmit',
1187 'quiz_attempts_allowed' => '10',
1188 'quiz_grade_method' => 'highest_grade',
1189 'enable_public_profile' => '1',
1190 'email_to_students' =>
1191 array(
1192 'quiz_completed' => '1',
1193 'completed_course' => '1',
1194 ),
1195 'email_to_instructors' =>
1196 array(
1197 'a_student_enrolled_in_course' => '1',
1198 'a_student_completed_course' => '1',
1199 'a_student_completed_lesson' => '1',
1200 'a_student_placed_question' => '1',
1201 ),
1202 'email_from_name' => get_option( 'blogname' ),
1203 'email_from_address' => get_option( 'admin_email' ),
1204 'email_footer_text' => '',
1205 'earning_admin_commission' => '20',
1206 'earning_admin_commission' => '20',
1207 'earning_instructor_commission' => '80',
1208 'color_preset_type' => 'default',
1209
1210 // Default options for tutor ecommerce.
1211 'monetize_by' => Ecommerce::MONETIZE_BY,
1212 'currency_code' => 'USD',
1213 'currency_position' => 'left',
1214 'thousand_separator' => ',',
1215 'decimal_separator' => '.',
1216 'number_of_decimals' => '2',
1217 'is_coupon_applicable' => 'on',
1218 'supported_video_sources' => array(
1219 'html5',
1220 'external_url',
1221 'youtube',
1222 'vimeo',
1223 'embedded',
1224 'shortcode',
1225 ),
1226 );
1227
1228 return $options;
1229 }
1230
1231
1232 /**
1233 * Create withdraw database
1234 *
1235 * @since 1.2.0
1236 */
1237 public static function create_withdraw_database() {
1238 global $wpdb;
1239
1240 $charset_collate = $wpdb->get_charset_collate();
1241
1242 /**
1243 * Table SQL
1244 *
1245 * {$wpdb->prefix}tutor_earnings
1246 * {$wpdb->prefix}tutor_withdraws
1247 *
1248 * @since 1.2.0
1249 */
1250
1251 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
1252 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
1253 user_id bigint(20) DEFAULT NULL,
1254 course_id bigint(20) DEFAULT NULL,
1255 order_id bigint(20) DEFAULT NULL,
1256 order_status varchar(50) DEFAULT NULL,
1257 course_price_total decimal(16,2) DEFAULT NULL,
1258 course_price_grand_total decimal(16,2) DEFAULT NULL,
1259 instructor_amount decimal(16,2) DEFAULT NULL,
1260 instructor_rate decimal(16,2) DEFAULT NULL,
1261 admin_amount decimal(16,2) DEFAULT NULL,
1262 admin_rate decimal(16,2) DEFAULT NULL,
1263 commission_type varchar(20) DEFAULT NULL,
1264 deduct_fees_amount decimal(16,2) DEFAULT NULL,
1265 deduct_fees_name varchar(250) DEFAULT NULL,
1266 deduct_fees_type varchar(20) DEFAULT NULL,
1267 process_by varchar(20) DEFAULT NULL,
1268 created_at datetime DEFAULT NULL,
1269 PRIMARY KEY (earning_id)
1270 ) $charset_collate;";
1271
1272 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
1273 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
1274 user_id bigint(20) DEFAULT NULL,
1275 amount decimal(16,2) DEFAULT NULL,
1276 method_data text DEFAULT NULL,
1277 status varchar(50) DEFAULT NULL,
1278 updated_at datetime DEFAULT NULL,
1279 created_at datetime DEFAULT NULL,
1280 PRIMARY KEY (withdraw_id)
1281 ) $charset_collate;";
1282
1283 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1284 dbDelta( $earning_table );
1285 dbDelta( $withdraw_table );
1286
1287 /**
1288 * Setting previous dashboard to new dashboard
1289 */
1290 $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' );
1291 tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id );
1292 }
1293
1294 /**
1295 * Filter the wp_doing_ajax from tutor requests to get advanced
1296 * advantages from Tutor
1297 *
1298 * @since 1.3.4
1299 *
1300 * @param bool $bool default value.
1301 *
1302 * @return bool
1303 */
1304 public function wp_doing_ajax( $bool ) {
1305 // Don't use Input::has helper to avoid conflict.
1306 if ( isset( $_REQUEST['tutor_ajax_action'] ) ) {
1307 return true;
1308 }
1309 return $bool;
1310 }
1311
1312 /**
1313 * Handle plugin un-installation
1314 *
1315 * @since 2.6.2
1316 *
1317 * @return void
1318 */
1319 public static function tutor_uninstall() {
1320 self::erase_tutor_data();
1321 }
1322
1323 /**
1324 * Erase tutor data
1325 *
1326 * @since 2.6.2
1327 *
1328 * @return void
1329 */
1330 public static function erase_tutor_data() {
1331 global $wpdb;
1332
1333 $is_erase_data = tutor_utils()->get_option( 'delete_on_uninstall' );
1334 // Deleting Data.
1335
1336 if ( $is_erase_data ) {
1337 /**
1338 * Deleting Post Type, Meta Data, taxonomy
1339 */
1340 $course_post_type = tutor()->course_post_type;
1341 $lesson_post_type = tutor()->lesson_post_type;
1342
1343 $post_types = array(
1344 $course_post_type,
1345 $lesson_post_type,
1346 'tutor_quiz',
1347 'tutor_enrolled',
1348 'topics',
1349 'tutor_enrolled',
1350 'tutor_announcements',
1351 );
1352
1353 $post_type_strings = "'" . implode( "','", $post_types ) . "'";
1354 $tutor_posts = $wpdb->get_col( "SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;" ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1355
1356 if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) {
1357 foreach ( $tutor_posts as $post_id ) {
1358 // Delete categories.
1359 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_CATEGORY );
1360 foreach ( $terms as $term ) {
1361 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_CATEGORY );
1362 }
1363
1364 // Delete tags if available.
1365 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_TAG );
1366 foreach ( $terms as $term ) {
1367 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_TAG );
1368 }
1369
1370 // Delete All Meta.
1371 $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $post_id ) );
1372 $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
1373 }
1374 }
1375
1376 /**
1377 * Deleting Comments (reviews, questions, quiz_answers, etc)
1378 */
1379 $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" );
1380 $comments_ids_strings = "'" . implode( "','", $tutor_comments ) . "'";
1381 if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) {
1382 $wpdb->query( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) " ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1383 }
1384 $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) );
1385
1386 /**
1387 * Delete Options
1388 */
1389
1390 delete_option( 'tutor_option' );
1391 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_student' ) );
1392 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_approved' ) );
1393 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_status' ) );
1394 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_instructor' ) );
1395 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_tutor_completed_lesson_id_%' " );
1396
1397 // Deleting Table.
1398 $prefix = $wpdb->prefix;
1399 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1400 $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 " );
1401
1402 }
1403 }
1404 }
1405