PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.7.0
Tutor LMS – eLearning and online course solution v3.7.0
3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Tutor.php
tutor / classes Last commit date
Addons.php 11 months ago Admin.php 11 months ago Ajax.php 1 year ago Announcements.php 1 year ago Assets.php 11 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 11 months 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 Icon.php 11 months ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 11 months ago Lesson.php 11 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 11 months ago Question_Answers_List.php 11 months ago Quiz.php 11 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 11 months 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 11 months ago WooCommerce.php 1 year ago
Tutor.php
1381 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 PRIMARY KEY (attempt_id)
761 ) $charset_collate;";
762
763 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
764 attempt_answer_id bigint(20) NOT NULL AUTO_INCREMENT,
765 user_id bigint(20) DEFAULT NULL,
766 quiz_id bigint(20) DEFAULT NULL,
767 question_id bigint(20) DEFAULT NULL,
768 quiz_attempt_id bigint(20) DEFAULT NULL,
769 given_answer longtext,
770 question_mark decimal(8,2) DEFAULT NULL,
771 achieved_mark decimal(8,2) DEFAULT NULL,
772 minus_mark decimal(8,2) DEFAULT NULL,
773 is_correct tinyint(4) DEFAULT NULL,
774 PRIMARY KEY (attempt_answer_id)
775 ) $charset_collate;";
776
777 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
778 question_id bigint(20) NOT NULL AUTO_INCREMENT,
779 quiz_id bigint(20) DEFAULT NULL,
780 question_title text,
781 question_description longtext,
782 answer_explanation longtext DEFAULT '',
783 question_type varchar(50) DEFAULT NULL,
784 question_mark decimal(9,2) DEFAULT NULL,
785 question_settings longtext,
786 question_order int(11) DEFAULT NULL,
787 PRIMARY KEY (question_id)
788 ) $charset_collate;";
789
790 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
791 answer_id bigint(20) NOT NULL AUTO_INCREMENT,
792 belongs_question_id bigint(20) DEFAULT NULL,
793 belongs_question_type varchar(250) DEFAULT NULL,
794 answer_title text,
795 is_correct tinyint(4) DEFAULT NULL,
796 image_id bigint(20) DEFAULT NULL,
797 answer_two_gap_match text,
798 answer_view_format varchar(250) DEFAULT NULL,
799 answer_settings text,
800 answer_order int(11) DEFAULT '0',
801 PRIMARY KEY (answer_id)
802 ) $charset_collate;";
803
804 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
805 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
806 user_id bigint(20) DEFAULT NULL,
807 course_id bigint(20) DEFAULT NULL,
808 order_id bigint(20) DEFAULT NULL,
809 order_status varchar(50) DEFAULT NULL,
810 course_price_total decimal(16,2) DEFAULT NULL,
811 course_price_grand_total decimal(16,2) DEFAULT NULL,
812 instructor_amount decimal(16,2) DEFAULT NULL,
813 instructor_rate decimal(16,2) DEFAULT NULL,
814 admin_amount decimal(16,2) DEFAULT NULL,
815 admin_rate decimal(16,2) DEFAULT NULL,
816 commission_type varchar(20) DEFAULT NULL,
817 deduct_fees_amount decimal(16,2) DEFAULT NULL,
818 deduct_fees_name varchar(250) DEFAULT NULL,
819 deduct_fees_type varchar(20) DEFAULT NULL,
820 process_by varchar(20) DEFAULT NULL,
821 created_at datetime DEFAULT NULL,
822 PRIMARY KEY (earning_id)
823 ) $charset_collate;";
824
825 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
826 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
827 user_id bigint(20) DEFAULT NULL,
828 amount decimal(16,2) DEFAULT NULL,
829 method_data text DEFAULT NULL,
830 status varchar(50) DEFAULT NULL,
831 updated_at datetime DEFAULT NULL,
832 created_at datetime DEFAULT NULL,
833 PRIMARY KEY (withdraw_id)
834 ) $charset_collate;";
835
836 $orders_table = "CREATE TABLE {$wpdb->prefix}tutor_orders (
837 id BIGINT(20) UNSIGNED AUTO_INCREMENT,
838 parent_id BIGINT(20) UNSIGNED DEFAULT 0, -- for subscription order, store subscription record id
839 transaction_id VARCHAR(255) COMMENT 'Transaction id from payment gateway',
840 user_id BIGINT(20) UNSIGNED NOT NULL,
841 order_type VARCHAR(50) NOT NULL, -- single_order, subscription
842 order_status VARCHAR(50) NOT NULL,
843 payment_status VARCHAR(50) NOT NULL,
844 subtotal_price DECIMAL(13, 2) NOT NULL, -- price calculation based on course sale price
845 total_price DECIMAL(13, 2) NOT NULL, -- final price
846 net_payment DECIMAL(13, 2) NOT NULL, -- calculated price if any refund is done else same as total_price
847 coupon_code VARCHAR(255),
848 coupon_amount DECIMAL(13, 2),
849 discount_type ENUM('percentage', 'flat') DEFAULT NULL,
850 discount_amount DECIMAL(13, 2),
851 discount_reason TEXT,
852 tax_rate DECIMAL(13, 2) COMMENT 'Tax percentage',
853 tax_amount DECIMAL(13, 2),
854 fees DECIMAL(13, 2), -- payment gateway fees
855 earnings DECIMAL(13, 2), -- net earning
856 refund_amount DECIMAL(13, 2), -- Refund amount
857 payment_method VARCHAR(255),
858 payment_payloads LONGTEXT,
859 note TEXT,
860 created_at_gmt DATETIME NOT NULL,
861 created_by BIGINT(20) UNSIGNED NOT NULL,
862 updated_at_gmt DATETIME,
863 updated_by BIGINT(20) UNSIGNED NOT NULL,
864 PRIMARY KEY (id),
865 KEY user_id (user_id),
866 KEY order_type (order_type),
867 KEY payment_status (payment_status),
868 KEY order_status (order_status),
869 KEY transaction_id (transaction_id)
870 ) $charset_collate;";
871
872 $order_meta_table = "CREATE TABLE {$wpdb->prefix}tutor_ordermeta (
873 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
874 order_id BIGINT(20) UNSIGNED NOT NULL,
875 meta_key VARCHAR(255) NOT NULL,
876 meta_value LONGTEXT NOT NULL,
877 created_at_gmt DATETIME NOT NULL,
878 created_by BIGINT(20) UNSIGNED NOT NULL,
879 updated_at_gmt DATETIME,
880 updated_by BIGINT(20) UNSIGNED NOT NULL,
881 PRIMARY KEY (id),
882 KEY order_id (order_id),
883 KEY meta_key (meta_key),
884 CONSTRAINT fk_tutor_ordermeta_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
885 ) $charset_collate;";
886
887 $order_items_table = "CREATE TABLE {$wpdb->prefix}tutor_order_items (
888 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
889 order_id BIGINT(20) UNSIGNED NOT NULL,
890 item_id BIGINT(20) UNSIGNED NOT NULL, -- course id/plan id
891 regular_price DECIMAL(13, 2) NOT NULL, -- course regular price
892 sale_price VARCHAR(13) DEFAULT NULL, -- course sale price
893 discount_price VARCHAR(13) DEFAULT NULL, -- course discount price
894 coupon_code VARCHAR(255) DEFAULT NULL, -- coupon code
895 PRIMARY KEY (id),
896 KEY order_id (order_id),
897 KEY item_id (item_id),
898 CONSTRAINT fk_tutor_order_item_order_id FOREIGN KEY (order_id) REFERENCES {$wpdb->prefix}tutor_orders(id) ON DELETE CASCADE
899 ) $charset_collate;";
900
901 $coupons_table = "CREATE TABLE {$wpdb->prefix}tutor_coupons (
902 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
903 coupon_status VARCHAR(50),
904 coupon_type VARCHAR(100) DEFAULT 'code', -- coupon type 'code' or 'automatic'
905 coupon_code VARCHAR(50) NOT NULL,
906 coupon_title VARCHAR(255) NOT NULL,
907 coupon_description TEXT,
908 discount_type ENUM('percentage', 'flat') NOT NULL,
909 discount_amount DECIMAL(13, 2) NOT NULL,
910 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'
911 total_usage_limit INT(10) UNSIGNED DEFAULT NULL, -- null for unlimited usage
912 per_user_usage_limit TINYINT(4) UNSIGNED DEFAULT NULL, -- null for unlimited usage
913 purchase_requirement VARCHAR(50) DEFAULT 'no_minimum', -- possible values 'no_minimum', 'minimum_purchase', 'minimum_quantity'
914 purchase_requirement_value DECIMAL(13, 2),
915 start_date_gmt DATETIME NOT NULL,
916 expire_date_gmt DATETIME DEFAULT NULL,
917 created_at_gmt DATETIME NOT NULL,
918 created_by BIGINT(20) UNSIGNED NOT NULL,
919 updated_at_gmt DATETIME,
920 updated_by BIGINT(20) UNSIGNED NOT NULL,
921 PRIMARY KEY (id),
922 UNIQUE KEY coupon_code (coupon_code),
923 KEY start_date_gmt (start_date_gmt),
924 KEY expire_date_gmt (expire_date_gmt)
925 ) $charset_collate;";
926
927 $coupon_applications_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_applications (
928 coupon_code VARCHAR(50) NOT NULL,
929 reference_id BIGINT(20) UNSIGNED NOT NULL,
930 KEY coupon_code (coupon_code),
931 KEY reference_id (reference_id),
932 CONSTRAINT fk_tutor_coupon_application_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE
933 ) $charset_collate;";
934
935 $coupon_usage_table = "CREATE TABLE {$wpdb->prefix}tutor_coupon_usages (
936 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
937 coupon_code VARCHAR(50) NOT NULL,
938 user_id BIGINT(20) UNSIGNED NOT NULL,
939 PRIMARY KEY (id),
940 KEY coupon_code (coupon_code),
941 KEY user_id (user_id),
942 CONSTRAINT fk_tutor_coupon_usage_coupon_code FOREIGN KEY (coupon_code) REFERENCES {$wpdb->prefix}tutor_coupons(coupon_code) ON DELETE CASCADE,
943 CONSTRAINT fk_tutor_coupon_usage_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
944 ) $charset_collate;";
945
946 $cart_table = "CREATE TABLE {$wpdb->prefix}tutor_carts (
947 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
948 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
949 coupon_code VARCHAR(50) DEFAULT NULL,
950 created_at_gmt DATETIME NOT NULL,
951 updated_at_gmt DATETIME,
952 PRIMARY KEY (id),
953 KEY user_id (user_id),
954 KEY coupon_code (coupon_code),
955 CONSTRAINT fk_tutor_cart_user_id FOREIGN KEY (user_id) REFERENCES {$wpdb->prefix}users(ID) ON DELETE CASCADE
956 ) $charset_collate;";
957
958 $cart_items_table = "CREATE TABLE {$wpdb->prefix}tutor_cart_items (
959 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
960 cart_id BIGINT(20) UNSIGNED NOT NULL,
961 course_id BIGINT(20) UNSIGNED NOT NULL,
962 PRIMARY KEY (id),
963 KEY cart_id (cart_id),
964 KEY course_id (course_id),
965 CONSTRAINT fk_tutor_cart_item_cart_id FOREIGN KEY (cart_id) REFERENCES {$wpdb->prefix}tutor_carts(id) ON DELETE CASCADE,
966 CONSTRAINT fk_tutor_cart_item_course_id FOREIGN KEY (course_id) REFERENCES {$wpdb->prefix}posts(ID) ON DELETE CASCADE
967 ) $charset_collate;";
968
969 $customer_table = "CREATE TABLE {$wpdb->prefix}tutor_customers (
970 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
971 user_id BIGINT(20) UNSIGNED DEFAULT NULL,
972 billing_first_name VARCHAR(255) NOT NULL,
973 billing_last_name VARCHAR(255) NOT NULL,
974 billing_email VARCHAR(255) NOT NULL,
975 billing_phone VARCHAR(20) NOT NULL,
976 billing_zip_code VARCHAR(20) NOT NULL,
977 billing_address TEXT NOT NULL,
978 billing_country VARCHAR(100) NOT NULL,
979 billing_state VARCHAR(100) NOT NULL,
980 billing_city VARCHAR(100) NOT NULL,
981 PRIMARY KEY (id),
982 KEY user_id (user_id),
983 KEY billing_email (billing_email)
984 ) $charset_collate;";
985
986 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
987 dbDelta( $quiz_attempts_sql );
988 dbDelta( $quiz_attempt_answers );
989 dbDelta( $tutor_quiz_questions );
990 dbDelta( $tutor_quiz_question_answers );
991 dbDelta( $earning_table );
992 dbDelta( $withdraw_table );
993 dbDelta( $orders_table );
994 dbDelta( $order_meta_table );
995 dbDelta( $order_items_table );
996 dbDelta( $coupons_table );
997 dbDelta( $coupon_applications_table );
998 dbDelta( $coupon_usage_table );
999 dbDelta( $cart_table );
1000 dbDelta( $cart_items_table );
1001 dbDelta( $customer_table );
1002 }
1003
1004 /**
1005 * Manage tutor roles & permission
1006 *
1007 * @return void
1008 */
1009 public static function manage_tutor_roles_and_permissions() {
1010 /**
1011 * Add role for instructor
1012 */
1013 $instructor_role = tutor()->instructor_role;
1014
1015 remove_role( $instructor_role );
1016 add_role( $instructor_role, __( 'Tutor Instructor', 'tutor' ), array() );
1017
1018 $custom_post_type_permission = array(
1019 // Manage Instructor.
1020 'manage_tutor_instructor',
1021
1022 // Tutor Posts Type Permission.
1023 'edit_tutor_course',
1024 'read_tutor_course',
1025 'delete_tutor_course',
1026 'delete_tutor_courses',
1027 'edit_tutor_courses',
1028 'edit_others_tutor_courses',
1029 'read_private_tutor_courses',
1030 'edit_tutor_courses',
1031
1032 'edit_tutor_lesson',
1033 'read_tutor_lesson',
1034 'delete_tutor_lesson',
1035 'delete_tutor_lessons',
1036 'edit_tutor_lessons',
1037 'edit_others_tutor_lessons',
1038 'read_private_tutor_lessons',
1039 'edit_tutor_lessons',
1040 'publish_tutor_lessons',
1041
1042 'edit_tutor_quiz',
1043 'read_tutor_quiz',
1044 'delete_tutor_quiz',
1045 'delete_tutor_quizzes',
1046 'edit_tutor_quizzes',
1047 'edit_others_tutor_quizzes',
1048 'read_private_tutor_quizzes',
1049 'edit_tutor_quizzes',
1050 'publish_tutor_quizzes',
1051
1052 'edit_tutor_question',
1053 'read_tutor_question',
1054 'delete_tutor_question',
1055 'delete_tutor_questions',
1056 'edit_tutor_questions',
1057 'edit_others_tutor_questions',
1058 'publish_tutor_questions',
1059 'read_private_tutor_questions',
1060 'edit_tutor_questions',
1061 );
1062
1063 $instructor = get_role( $instructor_role );
1064 if ( $instructor ) {
1065 $instructor_cap = array(
1066 'edit_posts',
1067 'read',
1068 'upload_files',
1069 );
1070
1071 $instructor_cap = array_merge( $instructor_cap, $custom_post_type_permission );
1072
1073 $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
1074 if ( $can_publish_course ) {
1075 $instructor_cap[] = 'publish_tutor_courses';
1076 }
1077
1078 foreach ( $instructor_cap as $cap ) {
1079 $instructor->add_cap( $cap );
1080 }
1081 }
1082
1083 $administrator = get_role( 'administrator' );
1084 if ( $administrator ) {
1085
1086 $administrator_cap = array(
1087 'manage_tutor',
1088 );
1089 $administrator_cap = array_merge( $administrator_cap, $custom_post_type_permission );
1090 $administrator_cap[] = 'publish_tutor_courses';
1091
1092 foreach ( $administrator_cap as $cap ) {
1093 $administrator->add_cap( $cap );
1094 }
1095 }
1096
1097 /**
1098 * Add Instructor role to administrator
1099 */
1100 if ( current_user_can( 'administrator' ) ) {
1101 tutor_utils()->add_instructor_role( get_current_user_id() );
1102 }
1103 }
1104
1105 /**
1106 * On plugin activate save initial data
1107 * Like: generate tutor pages
1108 *
1109 * @since 1.0.0
1110 *
1111 * @return void
1112 */
1113 public static function save_data() {
1114
1115 $student_dashboard_args = array(
1116 'post_title' => __( 'Dashboard', 'tutor' ),
1117 'post_content' => '',
1118 'post_type' => 'page',
1119 'post_status' => 'publish',
1120 );
1121 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
1122 tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id );
1123
1124 $student_registration_args = array(
1125 'post_title' => __( 'Student Registration', 'tutor' ),
1126 'post_content' => '[tutor_student_registration_form]',
1127 'post_type' => 'page',
1128 'post_status' => 'publish',
1129 );
1130 $student_register_page_id = wp_insert_post( $student_registration_args );
1131 tutor_utils()->update_option( 'student_register_page', $student_register_page_id );
1132
1133 $instructor_registration_args = array(
1134 'post_title' => __( 'Instructor Registration', 'tutor' ),
1135 'post_content' => '[tutor_instructor_registration_form]',
1136 'post_type' => 'page',
1137 'post_status' => 'publish',
1138 );
1139 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
1140 tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id );
1141 }
1142
1143 /**
1144 * Default options
1145 *
1146 * @since 1.0.0
1147 *
1148 * @since 3.4.1 Supported video sources added
1149 *
1150 * @return array
1151 */
1152 public static function default_options() {
1153 $options = array(
1154 'pagination_per_page' => '20',
1155 'course_allow_upload_private_files' => '1',
1156 'display_course_instructors' => '1',
1157 'enable_q_and_a_on_course' => '1',
1158 'courses_col_per_row' => '3',
1159 'courses_per_page' => '12',
1160 'course_permalink_base' => 'courses',
1161 'lesson_permalink_base' => 'lessons',
1162 'quiz_when_time_expires' => 'autosubmit',
1163 'quiz_attempts_allowed' => '10',
1164 'quiz_grade_method' => 'highest_grade',
1165 'enable_public_profile' => '1',
1166 'email_to_students' =>
1167 array(
1168 'quiz_completed' => '1',
1169 'completed_course' => '1',
1170 ),
1171 'email_to_instructors' =>
1172 array(
1173 'a_student_enrolled_in_course' => '1',
1174 'a_student_completed_course' => '1',
1175 'a_student_completed_lesson' => '1',
1176 'a_student_placed_question' => '1',
1177 ),
1178 'email_from_name' => get_option( 'blogname' ),
1179 'email_from_address' => get_option( 'admin_email' ),
1180 'email_footer_text' => '',
1181 'earning_admin_commission' => '20',
1182 'earning_admin_commission' => '20',
1183 'earning_instructor_commission' => '80',
1184 'color_preset_type' => 'default',
1185
1186 // Default options for tutor ecommerce.
1187 'monetize_by' => Ecommerce::MONETIZE_BY,
1188 'currency_code' => 'USD',
1189 'currency_position' => 'left',
1190 'thousand_separator' => ',',
1191 'decimal_separator' => '.',
1192 'number_of_decimals' => '2',
1193 'is_coupon_applicable' => 'on',
1194 'supported_video_sources' => array(
1195 'html5',
1196 'external_url',
1197 'youtube',
1198 'vimeo',
1199 'embedded',
1200 'shortcode',
1201 ),
1202 );
1203
1204 return $options;
1205 }
1206
1207
1208 /**
1209 * Create withdraw database
1210 *
1211 * @since 1.2.0
1212 */
1213 public static function create_withdraw_database() {
1214 global $wpdb;
1215
1216 $charset_collate = $wpdb->get_charset_collate();
1217
1218 /**
1219 * Table SQL
1220 *
1221 * {$wpdb->prefix}tutor_earnings
1222 * {$wpdb->prefix}tutor_withdraws
1223 *
1224 * @since 1.2.0
1225 */
1226
1227 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
1228 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
1229 user_id bigint(20) DEFAULT NULL,
1230 course_id bigint(20) DEFAULT NULL,
1231 order_id bigint(20) DEFAULT NULL,
1232 order_status varchar(50) DEFAULT NULL,
1233 course_price_total decimal(16,2) DEFAULT NULL,
1234 course_price_grand_total decimal(16,2) DEFAULT NULL,
1235 instructor_amount decimal(16,2) DEFAULT NULL,
1236 instructor_rate decimal(16,2) DEFAULT NULL,
1237 admin_amount decimal(16,2) DEFAULT NULL,
1238 admin_rate decimal(16,2) DEFAULT NULL,
1239 commission_type varchar(20) DEFAULT NULL,
1240 deduct_fees_amount decimal(16,2) DEFAULT NULL,
1241 deduct_fees_name varchar(250) DEFAULT NULL,
1242 deduct_fees_type varchar(20) DEFAULT NULL,
1243 process_by varchar(20) DEFAULT NULL,
1244 created_at datetime DEFAULT NULL,
1245 PRIMARY KEY (earning_id)
1246 ) $charset_collate;";
1247
1248 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
1249 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
1250 user_id bigint(20) DEFAULT NULL,
1251 amount decimal(16,2) DEFAULT NULL,
1252 method_data text DEFAULT NULL,
1253 status varchar(50) DEFAULT NULL,
1254 updated_at datetime DEFAULT NULL,
1255 created_at datetime DEFAULT NULL,
1256 PRIMARY KEY (withdraw_id)
1257 ) $charset_collate;";
1258
1259 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1260 dbDelta( $earning_table );
1261 dbDelta( $withdraw_table );
1262
1263 /**
1264 * Setting previous dashboard to new dashboard
1265 */
1266 $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' );
1267 tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id );
1268 }
1269
1270 /**
1271 * Filter the wp_doing_ajax from tutor requests to get advanced
1272 * advantages from Tutor
1273 *
1274 * @since 1.3.4
1275 *
1276 * @param bool $bool default value.
1277 *
1278 * @return bool
1279 */
1280 public function wp_doing_ajax( $bool ) {
1281 // Don't use Input::has helper to avoid conflict.
1282 if ( isset( $_REQUEST['tutor_ajax_action'] ) ) {
1283 return true;
1284 }
1285 return $bool;
1286 }
1287
1288 /**
1289 * Handle plugin un-installation
1290 *
1291 * @since 2.6.2
1292 *
1293 * @return void
1294 */
1295 public static function tutor_uninstall() {
1296 self::erase_tutor_data();
1297 }
1298
1299 /**
1300 * Erase tutor data
1301 *
1302 * @since 2.6.2
1303 *
1304 * @return void
1305 */
1306 public static function erase_tutor_data() {
1307 global $wpdb;
1308
1309 $is_erase_data = tutor_utils()->get_option( 'delete_on_uninstall' );
1310 // Deleting Data.
1311
1312 if ( $is_erase_data ) {
1313 /**
1314 * Deleting Post Type, Meta Data, taxonomy
1315 */
1316 $course_post_type = tutor()->course_post_type;
1317 $lesson_post_type = tutor()->lesson_post_type;
1318
1319 $post_types = array(
1320 $course_post_type,
1321 $lesson_post_type,
1322 'tutor_quiz',
1323 'tutor_enrolled',
1324 'topics',
1325 'tutor_enrolled',
1326 'tutor_announcements',
1327 );
1328
1329 $post_type_strings = "'" . implode( "','", $post_types ) . "'";
1330 $tutor_posts = $wpdb->get_col( "SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;" ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1331
1332 if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) {
1333 foreach ( $tutor_posts as $post_id ) {
1334 // Delete categories.
1335 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_CATEGORY );
1336 foreach ( $terms as $term ) {
1337 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_CATEGORY );
1338 }
1339
1340 // Delete tags if available.
1341 $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_TAG );
1342 foreach ( $terms as $term ) {
1343 wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_TAG );
1344 }
1345
1346 // Delete All Meta.
1347 $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $post_id ) );
1348 $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
1349 }
1350 }
1351
1352 /**
1353 * Deleting Comments (reviews, questions, quiz_answers, etc)
1354 */
1355 $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" );
1356 $comments_ids_strings = "'" . implode( "','", $tutor_comments ) . "'";
1357 if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) {
1358 $wpdb->query( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) " ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1359 }
1360 $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) );
1361
1362 /**
1363 * Delete Options
1364 */
1365
1366 delete_option( 'tutor_option' );
1367 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_student' ) );
1368 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_approved' ) );
1369 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_status' ) );
1370 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_instructor' ) );
1371 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_tutor_completed_lesson_id_%' " );
1372
1373 // Deleting Table.
1374 $prefix = $wpdb->prefix;
1375 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1376 $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 " );
1377
1378 }
1379 }
1380 }
1381