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