PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.2.1
Tutor LMS – eLearning and online course solution v2.2.1
3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Tutor.php
tutor / classes Last commit date
Addons.php 3 years ago Admin.php 3 years ago Ajax.php 3 years ago Announcements.php 3 years ago Assets.php 3 years ago Backend_Page_Trait.php 3 years ago Course.php 3 years ago Course_Embed.php 3 years ago Course_Filter.php 3 years ago Course_List.php 3 years 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 3 years ago Frontend.php 3 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 3 years ago Instructors_List.php 3 years ago Lesson.php 3 years ago Options_V2.php 3 years ago Post_types.php 3 years ago Private_Course_Access.php 3 years ago Q_and_A.php 3 years ago Question_Answers_List.php 3 years ago Quiz.php 3 years ago Quiz_Attempts_List.php 3 years ago RestAPI.php 3 years ago Reviews.php 3 years ago Rewrite_Rules.php 3 years ago Shortcode.php 3 years ago Student.php 3 years ago Students_List.php 3 years ago Taxonomies.php 3 years ago Template.php 3 years ago Theme_Compatibility.php 3 years ago Tools.php 3 years ago Tools_V2.php 3 years ago Tutor.php 3 years ago TutorEDD.php 3 years ago Tutor_Base.php 3 years ago Tutor_Setup.php 3 years ago Upgrader.php 3 years ago User.php 3 years ago Utils.php 3 years ago Video_Stream.php 3 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 3 years ago
Tutor.php
1095 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 private $Course_List;
400
401 /**
402 * Course Embed
403 *
404 * @var $course_embed
405 *
406 * @since 2.1.0
407 */
408 private $course_embed;
409
410 /**
411 * Rest Authentication
412 *
413 * @var $rest_auth
414 *
415 * @since 2.1.0
416 */
417 private $rest_auth;
418
419 /**
420 * Run the TUTOR
421 *
422 * @since 1.2.0
423 *
424 * @return null|Tutor
425 */
426 public static function instance() {
427 if ( is_null( self::$_instance ) ) {
428 self::$_instance = new self();
429 }
430 return self::$_instance;
431 }
432
433 /**
434 * Initialize props & other dependencies
435 *
436 * @since 1.0.0
437 */
438 public function __construct() {
439
440 $this->path = plugin_dir_path( TUTOR_FILE );
441 $this->url = plugin_dir_url( TUTOR_FILE );
442 $this->basename = plugin_basename( TUTOR_FILE );
443
444 /**
445 * Adding Tutor Database table to $wpdb;
446 *
447 * @since 1.4.2
448 */
449 global $wpdb;
450 $wpdb->tutor_earnings = $wpdb->prefix . 'tutor_earnings';
451 $wpdb->tutor_gradebooks = $wpdb->prefix . 'tutor_gradebooks';
452 $wpdb->tutor_gradebooks_results = $wpdb->prefix . 'tutor_gradebooks_results';
453 $wpdb->tutor_quiz_attempts = $wpdb->prefix . 'tutor_quiz_attempts';
454 $wpdb->tutor_quiz_attempt_answers = $wpdb->prefix . 'tutor_quiz_attempt_answers';
455 $wpdb->tutor_quiz_questions = $wpdb->prefix . 'tutor_quiz_questions';
456 $wpdb->tutor_quiz_question_answers = $wpdb->prefix . 'tutor_quiz_question_answers';
457 $wpdb->tutor_withdraws = $wpdb->prefix . 'tutor_withdraws';
458 $wpdb->tutor_email_queue = $wpdb->prefix . 'tutor_email_queue';
459
460 /**
461 * Changing default wp doing ajax return based on tutor ajax action
462 */
463 add_filter( 'wp_doing_ajax', array( $this, 'wp_doing_ajax' ) );
464
465 /**
466 * Include Files
467 */
468 $this->includes();
469
470 /**
471 * Loading Auto loader
472 */
473 spl_autoload_register( array( $this, 'loader' ) );
474
475 do_action( 'tutor_before_load' );
476
477 $this->addons = new Addons();
478 $this->post_types = new Post_types();
479 $this->taxonomies = new Taxonomies();
480 $this->assets = new Assets();
481 $this->admin = new Admin();
482 $this->ajax = new Ajax();
483 $this->options = new Options_V2();
484 $this->shortcode = new Shortcode();
485 $this->course = new Course();
486 $this->lesson = new Lesson();
487 $this->rewrite_rules = new Rewrite_Rules();
488 $this->template = new Template();
489 $this->instructor = new Instructor();
490 $this->student = new Student();
491 $this->q_and_a = new Q_and_A();
492 $this->q_and_a_list = new Question_Answers_List();
493 $this->q_attempt = new Quiz_Attempts_List();
494 $this->quiz = new Quiz();
495 $this->tools = new Tools();
496 $this->user = new User();
497 $this->theme_compatibility = new Theme_Compatibility();
498 $this->gutenberg = new Gutenberg();
499 $this->course_settings_tabs = new Course_Settings_Tabs();
500 $this->withdraw = new Withdraw();
501 $this->course_widget = new Course_Widget();
502 $this->upgrader = new Upgrader();
503 $this->dashboard = new Dashboard();
504 $this->form_handler = new FormHandler();
505 $this->frontend = new Frontend();
506 $this->rest_api = new RestAPI();
507 $this->setup = new Tutor_Setup();
508 $this->private_course_access = new Private_Course_Access();
509 $this->course_filter = new Course_Filter();
510
511 // Integrations.
512 $this->woocommerce = new WooCommerce();
513 $this->edd = new TutorEDD();
514
515 /**
516 * Init obj
517 *
518 * @since 2.0.0
519 */
520 $this->announcements = new Announcements();
521 $this->course_list = new Course_List();
522 $this->reviews = new Reviews();
523 $this->withdraw_list = new Withdraw_Requests_List();
524 $this->student_list = new Students_List();
525 $this->instructor_list = new Instructors_List();
526 $this->course_embed = new Course_Embed();
527 $this->rest_auth = new RestAuth();
528
529 /**
530 * Run Method
531 *
532 * @since v.1.2.0
533 */
534 $this->run();
535
536 do_action( 'tutor_loaded' );
537
538 add_action( 'init', array( $this, 'init_action' ) );
539
540 /**
541 * Redirect to the wizard page
542 *
543 * @since 1.5.7
544 */
545
546 add_action( 'activated_plugin', array( $this, 'activated_tutor' ), 10, 2 );
547 }
548
549 /**
550 * Redirect to the wizard page
551 *
552 * @since 1.5.7
553 *
554 * @param mixed $plugin plugin.
555 * @param mixed $network_wide network wide.
556 *
557 * @return void
558 */
559 public function activated_tutor( $plugin, $network_wide = null ) {
560 if ( $plugin == tutor()->basename ) {
561 if ( ( ! get_option( 'tutor_wizard' ) ) && version_compare( TUTOR_VERSION, '1.5.6', '>' ) ) {
562 update_option( 'tutor_wizard', 'active' );
563 wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) );
564 exit;
565 }
566 }
567 }
568
569 /**
570 * Auto Load class and the files
571 *
572 * @since 1.0.0
573 *
574 * @param string $className class name to load.
575 *
576 * @return void
577 */
578 private function loader( $className ) {
579 if ( ! class_exists( $className ) ) {
580 $className = preg_replace(
581 array( '/([a-z])([A-Z])/', '/\\\/' ),
582 array( '$1$2', DIRECTORY_SEPARATOR ),
583 $className
584 );
585
586 $className = str_replace( 'TUTOR' . DIRECTORY_SEPARATOR, 'classes' . DIRECTORY_SEPARATOR, $className );
587 $file_name = $this->path . $className . '.php';
588
589 if ( file_exists( $file_name ) ) {
590 require_once $file_name;
591 }
592 }
593 }
594
595 /**
596 * Include utility functions
597 *
598 * @return void
599 */
600 public function includes() {
601 include tutor()->path . 'includes/tutor-general-functions.php';
602 include tutor()->path . 'includes/tutor-template-functions.php';
603 include tutor()->path . 'includes/tutor-template-hook.php';
604 include tutor()->path . 'includes/translate-text.php';
605 }
606
607 /**
608 * Providing hooks
609 *
610 * @return void
611 */
612 public function run() {
613 do_action( 'tutor_before_run' );
614 do_action( 'tutor_after_run' );
615 }
616
617 /**
618 * Tutor Action Via do_action
619 *
620 * @since 1.2.14
621 */
622 public function init_action() {
623 $tutor_action = Input::sanitize_request_data( 'tutor_action' );
624 if ( '' !== $tutor_action ) {
625 do_action( 'tutor_action_' . $tutor_action );
626 }
627 }
628
629 /**
630 * Do some task during plugin activation
631 */
632 public static function tutor_activate() {
633 $version = get_option( 'tutor_version' );
634 if ( ! function_exists( 'tutor_time' ) ) {
635 include tutor()->path . 'includes/tutor-general-functions.php';
636 }
637
638 // Create Database.
639 self::create_database();
640
641 // Save Option.
642 if ( ! $version ) {
643
644 $options = self::default_options();
645 update_option( 'tutor_option', $options );
646
647 // Rewrite Flush.
648 update_option( 'required_rewrite_flush', tutor_time() );
649 self::manage_tutor_roles_and_permissions();
650
651 // Save initial Page.
652 self::save_data();
653 update_option( 'tutor_version', TUTOR_VERSION );
654 }
655
656 // Set Schedule.
657 if ( ! wp_next_scheduled( 'tutor_once_in_day_run_schedule' ) ) {
658 wp_schedule_event( tutor_time(), 'twicedaily', 'tutor_once_in_day_run_schedule' );
659 }
660
661 /**
662 * Backward Compatibility for version < 1.2.0
663 */
664 if ( version_compare( get_option( 'tutor_version' ), '1.2.0', '<' ) ) {
665 /**
666 * Creating New Database
667 */
668 self::create_withdraw_database();
669 // Update the tutor version.
670 update_option( 'tutor_version', '1.2.0' );
671 // Rewrite Flush.
672 update_option( 'required_rewrite_flush', tutor_time() );
673 }
674
675 /**
676 * Backward Compatibility to < 1.3.1 for make course plural
677 */
678 if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) {
679 global $wpdb;
680
681 if ( ! get_option( 'is_course_post_type_updated' ) ) {
682 $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) );
683 update_option( 'is_course_post_type_updated', true );
684 update_option( 'tutor_version', '1.3.1' );
685 flush_rewrite_rules();
686 }
687 }
688
689 /**
690 * Save First activation Time
691 */
692 $first_activation_date = get_option( 'tutor_first_activation_time' );
693 if ( ! $first_activation_date ) {
694 update_option( 'tutor_first_activation_time', tutor_time() );
695 }
696 }
697
698 /**
699 * Run task on deactivation
700 *
701 * @since 1.0.0
702 *
703 * @return void
704 */
705 public static function tutor_deactivation() {
706 wp_clear_scheduled_hook( 'tutor_once_in_day_run_schedule' );
707 }
708
709 /**
710 * Create database
711 *
712 * @return void
713 */
714 public static function create_database() {
715 global $wpdb;
716
717 $charset_collate = $wpdb->get_charset_collate();
718
719 /**
720 * Table SQL
721 *
722 * {$wpdb->prefix}tutor_quiz_attempts
723 * {$wpdb->prefix}tutor_quiz_attempt_answers
724 * {$wpdb->prefix}tutor_quiz_questions
725 * {$wpdb->prefix}tutor_quiz_question_answers
726 * {$wpdb->prefix}tutor_earnings
727 * {$wpdb->prefix}tutor_withdraws
728 *
729 * @since 1.0.0
730 */
731 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
732 attempt_id bigint(20) NOT NULL AUTO_INCREMENT,
733 course_id bigint(20) DEFAULT NULL,
734 quiz_id bigint(20) DEFAULT NULL,
735 user_id bigint(20) DEFAULT NULL,
736 total_questions int(11) DEFAULT NULL,
737 total_answered_questions int(11) DEFAULT NULL,
738 total_marks decimal(9,2) DEFAULT NULL,
739 earned_marks decimal(9,2) DEFAULT NULL,
740 attempt_info text,
741 attempt_status varchar(50) DEFAULT NULL,
742 attempt_ip varchar(250) DEFAULT NULL,
743 attempt_started_at datetime DEFAULT NULL,
744 attempt_ended_at datetime DEFAULT NULL,
745 is_manually_reviewed int(1) DEFAULT NULL,
746 manually_reviewed_at datetime DEFAULT NULL,
747 PRIMARY KEY (attempt_id)
748 ) $charset_collate;";
749
750 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
751 attempt_answer_id bigint(20) NOT NULL AUTO_INCREMENT,
752 user_id bigint(20) DEFAULT NULL,
753 quiz_id bigint(20) DEFAULT NULL,
754 question_id bigint(20) DEFAULT NULL,
755 quiz_attempt_id bigint(20) DEFAULT NULL,
756 given_answer longtext,
757 question_mark decimal(8,2) DEFAULT NULL,
758 achieved_mark decimal(8,2) DEFAULT NULL,
759 minus_mark decimal(8,2) DEFAULT NULL,
760 is_correct tinyint(4) DEFAULT NULL,
761 PRIMARY KEY (attempt_answer_id)
762 ) $charset_collate;";
763
764 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
765 question_id bigint(20) NOT NULL AUTO_INCREMENT,
766 quiz_id bigint(20) DEFAULT NULL,
767 question_title text,
768 question_description longtext,
769 question_type varchar(50) DEFAULT NULL,
770 question_mark decimal(9,2) DEFAULT NULL,
771 question_settings longtext,
772 question_order int(11) DEFAULT NULL,
773 PRIMARY KEY (question_id)
774 ) $charset_collate;";
775
776 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
777 answer_id bigint(20) NOT NULL AUTO_INCREMENT,
778 belongs_question_id bigint(20) DEFAULT NULL,
779 belongs_question_type varchar(250) DEFAULT NULL,
780 answer_title text,
781 is_correct tinyint(4) DEFAULT NULL,
782 image_id bigint(20) DEFAULT NULL,
783 answer_two_gap_match text,
784 answer_view_format varchar(250) DEFAULT NULL,
785 answer_settings text,
786 answer_order int(11) DEFAULT '0',
787 PRIMARY KEY (answer_id)
788 ) $charset_collate;";
789
790 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
791 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
792 user_id bigint(20) DEFAULT NULL,
793 course_id bigint(20) DEFAULT NULL,
794 order_id bigint(20) DEFAULT NULL,
795 order_status varchar(50) DEFAULT NULL,
796 course_price_total decimal(16,2) DEFAULT NULL,
797 course_price_grand_total decimal(16,2) DEFAULT NULL,
798 instructor_amount decimal(16,2) DEFAULT NULL,
799 instructor_rate decimal(16,2) DEFAULT NULL,
800 admin_amount decimal(16,2) DEFAULT NULL,
801 admin_rate decimal(16,2) DEFAULT NULL,
802 commission_type varchar(20) DEFAULT NULL,
803 deduct_fees_amount decimal(16,2) DEFAULT NULL,
804 deduct_fees_name varchar(250) DEFAULT NULL,
805 deduct_fees_type varchar(20) DEFAULT NULL,
806 process_by varchar(20) DEFAULT NULL,
807 created_at datetime DEFAULT NULL,
808 PRIMARY KEY (earning_id)
809 ) $charset_collate;";
810
811 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
812 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
813 user_id bigint(20) DEFAULT NULL,
814 amount decimal(16,2) DEFAULT NULL,
815 method_data text DEFAULT NULL,
816 status varchar(50) DEFAULT NULL,
817 updated_at datetime DEFAULT NULL,
818 created_at datetime DEFAULT NULL,
819 PRIMARY KEY (withdraw_id)
820 ) $charset_collate;";
821
822 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
823 dbDelta( $quiz_attempts_sql );
824 dbDelta( $quiz_attempt_answers );
825 dbDelta( $tutor_quiz_questions );
826 dbDelta( $tutor_quiz_question_answers );
827 dbDelta( $earning_table );
828 dbDelta( $withdraw_table );
829 }
830
831 /**
832 * Manage tutor roles & permission
833 *
834 * @return void
835 */
836 public static function manage_tutor_roles_and_permissions() {
837 /**
838 * Add role for instructor
839 */
840 $instructor_role = tutor()->instructor_role;
841
842 remove_role( $instructor_role );
843 add_role( $instructor_role, __( 'Tutor Instructor', 'tutor' ), array() );
844
845 $custom_post_type_permission = array(
846 // Manage Instructor.
847 'manage_tutor_instructor',
848
849 // Tutor Posts Type Permission.
850 'edit_tutor_course',
851 'read_tutor_course',
852 'delete_tutor_course',
853 'delete_tutor_courses',
854 'edit_tutor_courses',
855 'edit_others_tutor_courses',
856 'read_private_tutor_courses',
857 'edit_tutor_courses',
858
859 'edit_tutor_lesson',
860 'read_tutor_lesson',
861 'delete_tutor_lesson',
862 'delete_tutor_lessons',
863 'edit_tutor_lessons',
864 'edit_others_tutor_lessons',
865 'read_private_tutor_lessons',
866 'edit_tutor_lessons',
867 'publish_tutor_lessons',
868
869 'edit_tutor_quiz',
870 'read_tutor_quiz',
871 'delete_tutor_quiz',
872 'delete_tutor_quizzes',
873 'edit_tutor_quizzes',
874 'edit_others_tutor_quizzes',
875 'read_private_tutor_quizzes',
876 'edit_tutor_quizzes',
877 'publish_tutor_quizzes',
878
879 'edit_tutor_question',
880 'read_tutor_question',
881 'delete_tutor_question',
882 'delete_tutor_questions',
883 'edit_tutor_questions',
884 'edit_others_tutor_questions',
885 'publish_tutor_questions',
886 'read_private_tutor_questions',
887 'edit_tutor_questions',
888 );
889
890 $instructor = get_role( $instructor_role );
891 if ( $instructor ) {
892 $instructor_cap = array(
893 'edit_posts',
894 'read',
895 'upload_files',
896 );
897
898 $instructor_cap = array_merge( $instructor_cap, $custom_post_type_permission );
899
900 $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
901 if ( $can_publish_course ) {
902 $instructor_cap[] = 'publish_tutor_courses';
903 }
904
905 foreach ( $instructor_cap as $cap ) {
906 $instructor->add_cap( $cap );
907 }
908 }
909
910 $administrator = get_role( 'administrator' );
911 if ( $administrator ) {
912
913 $administrator_cap = array(
914 'manage_tutor',
915 );
916 $administrator_cap = array_merge( $administrator_cap, $custom_post_type_permission );
917 $administrator_cap[] = 'publish_tutor_courses';
918
919 foreach ( $administrator_cap as $cap ) {
920 $administrator->add_cap( $cap );
921 }
922 }
923
924 /**
925 * Add Instructor role to administrator
926 */
927 if ( current_user_can( 'administrator' ) ) {
928 tutor_utils()->add_instructor_role( get_current_user_id() );
929 }
930
931 }
932
933 /**
934 * On plugin activate save initial data
935 * Like: generate tutor pages
936 *
937 * @since 1.0.0
938 *
939 * @return void
940 */
941 public static function save_data() {
942
943 $student_dashboard_args = array(
944 'post_title' => __( 'Dashboard', 'tutor' ),
945 'post_content' => '',
946 'post_type' => 'page',
947 'post_status' => 'publish',
948 );
949 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
950 tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id );
951
952 $student_registration_args = array(
953 'post_title' => __( 'Student Registration', 'tutor' ),
954 'post_content' => '[tutor_student_registration_form]',
955 'post_type' => 'page',
956 'post_status' => 'publish',
957 );
958 $student_register_page_id = wp_insert_post( $student_registration_args );
959 tutor_utils()->update_option( 'student_register_page', $student_register_page_id );
960
961 $instructor_registration_args = array(
962 'post_title' => __( 'Instructor Registration', 'tutor' ),
963 'post_content' => '[tutor_instructor_registration_form]',
964 'post_type' => 'page',
965 'post_status' => 'publish',
966 );
967 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
968 tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id );
969 }
970
971 /**
972 * Default options
973 *
974 * @since 1.0.0
975 *
976 * @return array
977 */
978 public static function default_options() {
979 $options = array(
980 'pagination_per_page' => '20',
981 'course_allow_upload_private_files' => '1',
982 'display_course_instructors' => '1',
983 'enable_q_and_a_on_course' => '1',
984 'courses_col_per_row' => '3',
985 'courses_per_page' => '12',
986 'lesson_permalink_base' => 'lesson',
987 'quiz_when_time_expires' => 'autosubmit',
988 'quiz_attempts_allowed' => '10',
989 'quiz_grade_method' => 'highest_grade',
990 'enable_public_profile' => '1',
991 'email_to_students' =>
992 array(
993 'quiz_completed' => '1',
994 'completed_course' => '1',
995 ),
996 'email_to_instructors' =>
997 array(
998 'a_student_enrolled_in_course' => '1',
999 'a_student_completed_course' => '1',
1000 'a_student_completed_lesson' => '1',
1001 'a_student_placed_question' => '1',
1002 ),
1003 'email_from_name' => get_option( 'blogname' ),
1004 'email_from_address' => get_option( 'admin_email' ),
1005 'email_footer_text' => '',
1006 'earning_admin_commission' => '20',
1007 'earning_admin_commission' => '20',
1008 'earning_instructor_commission' => '80',
1009 'color_preset_type' => 'default',
1010 );
1011 return $options;
1012 }
1013
1014
1015 /**
1016 * Create withdraw database
1017 *
1018 * @since 1.2.0
1019 */
1020 public static function create_withdraw_database() {
1021 global $wpdb;
1022
1023 $charset_collate = $wpdb->get_charset_collate();
1024
1025 /**
1026 * Table SQL
1027 *
1028 * {$wpdb->prefix}tutor_earnings
1029 * {$wpdb->prefix}tutor_withdraws
1030 *
1031 * @since 1.2.0
1032 */
1033
1034 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
1035 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
1036 user_id bigint(20) DEFAULT NULL,
1037 course_id bigint(20) DEFAULT NULL,
1038 order_id bigint(20) DEFAULT NULL,
1039 order_status varchar(50) DEFAULT NULL,
1040 course_price_total decimal(16,2) DEFAULT NULL,
1041 course_price_grand_total decimal(16,2) DEFAULT NULL,
1042 instructor_amount decimal(16,2) DEFAULT NULL,
1043 instructor_rate decimal(16,2) DEFAULT NULL,
1044 admin_amount decimal(16,2) DEFAULT NULL,
1045 admin_rate decimal(16,2) DEFAULT NULL,
1046 commission_type varchar(20) DEFAULT NULL,
1047 deduct_fees_amount decimal(16,2) DEFAULT NULL,
1048 deduct_fees_name varchar(250) DEFAULT NULL,
1049 deduct_fees_type varchar(20) DEFAULT NULL,
1050 process_by varchar(20) DEFAULT NULL,
1051 created_at datetime DEFAULT NULL,
1052 PRIMARY KEY (earning_id)
1053 ) $charset_collate;";
1054
1055 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
1056 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
1057 user_id bigint(20) DEFAULT NULL,
1058 amount decimal(16,2) DEFAULT NULL,
1059 method_data text DEFAULT NULL,
1060 status varchar(50) DEFAULT NULL,
1061 updated_at datetime DEFAULT NULL,
1062 created_at datetime DEFAULT NULL,
1063 PRIMARY KEY (withdraw_id)
1064 ) $charset_collate;";
1065
1066 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1067 dbDelta( $earning_table );
1068 dbDelta( $withdraw_table );
1069
1070 /**
1071 * Setting previous dashboard to new dashboard
1072 */
1073 $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' );
1074 tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id );
1075 }
1076
1077 /**
1078 * Filter the wp_doing_ajax from tutor requests to get advanced
1079 * advantages from Tutor
1080 *
1081 * @since 1.3.4
1082 *
1083 * @param bool $bool default value.
1084 *
1085 * @return bool
1086 */
1087 public function wp_doing_ajax( $bool ) {
1088 // Don't use Input::has helper to avoid conflict.
1089 if ( isset( $_REQUEST['tutor_ajax_action'] ) ) {
1090 return true;
1091 }
1092 return $bool;
1093 }
1094 }
1095