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