PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.6.1
Tutor LMS – eLearning and online course solution v2.6.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 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 2 years ago Course_Embed.php 3 years ago Course_Filter.php 2 years ago Course_List.php 2 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 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 2 years ago Lesson.php 2 years ago Options_V2.php 2 years ago Permalink.php 2 years ago Post_types.php 2 years ago Private_Course_Access.php 3 years ago Q_and_A.php 2 years 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 2 years 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 3 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 2 years 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
1113 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 * Redirect to the wizard page
559 *
560 * @since 1.5.7
561 */
562
563 add_action( 'activated_plugin', array( $this, 'activated_tutor' ), 10, 2 );
564 }
565
566 /**
567 * Redirect to the wizard page
568 *
569 * @since 1.5.7
570 *
571 * @param mixed $plugin plugin.
572 * @param mixed $network_wide network wide.
573 *
574 * @return void
575 */
576 public function activated_tutor( $plugin, $network_wide = null ) {
577 if ( tutor()->basename === $plugin ) {
578 if ( ( ! get_option( 'tutor_wizard' ) ) && version_compare( TUTOR_VERSION, '1.5.6', '>' ) ) {
579 update_option( 'tutor_wizard', 'active' );
580 wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) );
581 exit;
582 }
583 }
584 }
585
586 /**
587 * Auto Load class and the files
588 *
589 * @since 1.0.0
590 *
591 * @param string $class_name class name to load.
592 *
593 * @return void
594 */
595 private function loader( $class_name ) {
596 if ( ! class_exists( $class_name ) ) {
597 $class_name = preg_replace(
598 array( '/([a-z])([A-Z])/', '/\\\/' ),
599 array( '$1$2', DIRECTORY_SEPARATOR ),
600 $class_name
601 );
602
603 $class_name = str_replace( 'TUTOR' . DIRECTORY_SEPARATOR, 'classes' . DIRECTORY_SEPARATOR, $class_name );
604 $file_name = $this->path . $class_name . '.php';
605
606 if ( file_exists( $file_name ) ) {
607 require_once $file_name;
608 }
609 }
610 }
611
612 /**
613 * Include utility functions
614 *
615 * @return void
616 */
617 public function includes() {
618 include tutor()->path . 'includes/tutor-general-functions.php';
619 include tutor()->path . 'includes/tutor-template-functions.php';
620 include tutor()->path . 'includes/tutor-template-hook.php';
621 include tutor()->path . 'includes/translate-text.php';
622 }
623
624 /**
625 * Providing hooks
626 *
627 * @return void
628 */
629 public function run() {
630 do_action( 'tutor_before_run' );
631 do_action( 'tutor_after_run' );
632 }
633
634 /**
635 * Tutor Action Via do_action
636 *
637 * @since 1.2.14
638 */
639 public function init_action() {
640 $tutor_action = Input::sanitize_request_data( 'tutor_action' );
641 if ( '' !== $tutor_action ) {
642 do_action( 'tutor_action_' . $tutor_action );
643 }
644 }
645
646 /**
647 * Do some task during plugin activation
648 */
649 public static function tutor_activate() {
650 $version = get_option( 'tutor_version' );
651 if ( ! function_exists( 'tutor_time' ) ) {
652 include tutor()->path . 'includes/tutor-general-functions.php';
653 }
654
655 // Create Database.
656 self::create_database();
657
658 // Save Option.
659 if ( ! $version ) {
660
661 $options = self::default_options();
662 update_option( 'tutor_option', $options );
663
664 // Rewrite Flush.
665 Permalink::set_permalink_flag();
666 self::manage_tutor_roles_and_permissions();
667
668 // Save initial Page.
669 self::save_data();
670 update_option( 'tutor_version', TUTOR_VERSION );
671 }
672
673 // Set Schedule.
674 if ( ! wp_next_scheduled( 'tutor_once_in_day_run_schedule' ) ) {
675 wp_schedule_event( tutor_time(), 'twicedaily', 'tutor_once_in_day_run_schedule' );
676 }
677
678 /**
679 * Backward Compatibility for version < 1.2.0
680 */
681 if ( version_compare( get_option( 'tutor_version' ), '1.2.0', '<' ) ) {
682 /**
683 * Creating New Database
684 */
685 self::create_withdraw_database();
686 // Update the tutor version.
687 update_option( 'tutor_version', '1.2.0' );
688 // Rewrite Flush.
689 Permalink::set_permalink_flag();
690 }
691
692 /**
693 * Backward Compatibility to < 1.3.1 for make course plural
694 */
695 if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) {
696 global $wpdb;
697
698 if ( ! get_option( 'is_course_post_type_updated' ) ) {
699 $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) );
700 update_option( 'is_course_post_type_updated', true );
701 update_option( 'tutor_version', '1.3.1' );
702 Permalink::set_permalink_flag();
703 }
704 }
705
706 /**
707 * Save First activation Time
708 */
709 $first_activation_date = get_option( 'tutor_first_activation_time' );
710 if ( ! $first_activation_date ) {
711 update_option( 'tutor_first_activation_time', tutor_time() );
712 }
713 }
714
715 /**
716 * Run task on deactivation
717 *
718 * @since 1.0.0
719 *
720 * @return void
721 */
722 public static function tutor_deactivation() {
723 wp_clear_scheduled_hook( 'tutor_once_in_day_run_schedule' );
724 }
725
726 /**
727 * Create database
728 *
729 * @return void
730 */
731 public static function create_database() {
732 global $wpdb;
733
734 $charset_collate = $wpdb->get_charset_collate();
735
736 /**
737 * Table SQL
738 *
739 * {$wpdb->prefix}tutor_quiz_attempts
740 * {$wpdb->prefix}tutor_quiz_attempt_answers
741 * {$wpdb->prefix}tutor_quiz_questions
742 * {$wpdb->prefix}tutor_quiz_question_answers
743 * {$wpdb->prefix}tutor_earnings
744 * {$wpdb->prefix}tutor_withdraws
745 *
746 * @since 1.0.0
747 */
748 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
749 attempt_id bigint(20) NOT NULL AUTO_INCREMENT,
750 course_id bigint(20) DEFAULT NULL,
751 quiz_id bigint(20) DEFAULT NULL,
752 user_id bigint(20) DEFAULT NULL,
753 total_questions int(11) DEFAULT NULL,
754 total_answered_questions int(11) DEFAULT NULL,
755 total_marks decimal(9,2) DEFAULT NULL,
756 earned_marks decimal(9,2) DEFAULT NULL,
757 attempt_info text,
758 attempt_status varchar(50) DEFAULT NULL,
759 attempt_ip varchar(250) DEFAULT NULL,
760 attempt_started_at datetime DEFAULT NULL,
761 attempt_ended_at datetime DEFAULT NULL,
762 is_manually_reviewed int(1) DEFAULT NULL,
763 manually_reviewed_at datetime DEFAULT NULL,
764 PRIMARY KEY (attempt_id)
765 ) $charset_collate;";
766
767 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
768 attempt_answer_id bigint(20) NOT NULL AUTO_INCREMENT,
769 user_id bigint(20) DEFAULT NULL,
770 quiz_id bigint(20) DEFAULT NULL,
771 question_id bigint(20) DEFAULT NULL,
772 quiz_attempt_id bigint(20) DEFAULT NULL,
773 given_answer longtext,
774 question_mark decimal(8,2) DEFAULT NULL,
775 achieved_mark decimal(8,2) DEFAULT NULL,
776 minus_mark decimal(8,2) DEFAULT NULL,
777 is_correct tinyint(4) DEFAULT NULL,
778 PRIMARY KEY (attempt_answer_id)
779 ) $charset_collate;";
780
781 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
782 question_id bigint(20) NOT NULL AUTO_INCREMENT,
783 quiz_id bigint(20) DEFAULT NULL,
784 question_title text,
785 question_description longtext,
786 answer_explanation longtext DEFAULT '',
787 question_type varchar(50) DEFAULT NULL,
788 question_mark decimal(9,2) DEFAULT NULL,
789 question_settings longtext,
790 question_order int(11) DEFAULT NULL,
791 PRIMARY KEY (question_id)
792 ) $charset_collate;";
793
794 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
795 answer_id bigint(20) NOT NULL AUTO_INCREMENT,
796 belongs_question_id bigint(20) DEFAULT NULL,
797 belongs_question_type varchar(250) DEFAULT NULL,
798 answer_title text,
799 is_correct tinyint(4) DEFAULT NULL,
800 image_id bigint(20) DEFAULT NULL,
801 answer_two_gap_match text,
802 answer_view_format varchar(250) DEFAULT NULL,
803 answer_settings text,
804 answer_order int(11) DEFAULT '0',
805 PRIMARY KEY (answer_id)
806 ) $charset_collate;";
807
808 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
809 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
810 user_id bigint(20) DEFAULT NULL,
811 course_id bigint(20) DEFAULT NULL,
812 order_id bigint(20) DEFAULT NULL,
813 order_status varchar(50) DEFAULT NULL,
814 course_price_total decimal(16,2) DEFAULT NULL,
815 course_price_grand_total decimal(16,2) DEFAULT NULL,
816 instructor_amount decimal(16,2) DEFAULT NULL,
817 instructor_rate decimal(16,2) DEFAULT NULL,
818 admin_amount decimal(16,2) DEFAULT NULL,
819 admin_rate decimal(16,2) DEFAULT NULL,
820 commission_type varchar(20) DEFAULT NULL,
821 deduct_fees_amount decimal(16,2) DEFAULT NULL,
822 deduct_fees_name varchar(250) DEFAULT NULL,
823 deduct_fees_type varchar(20) DEFAULT NULL,
824 process_by varchar(20) DEFAULT NULL,
825 created_at datetime DEFAULT NULL,
826 PRIMARY KEY (earning_id)
827 ) $charset_collate;";
828
829 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
830 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
831 user_id bigint(20) DEFAULT NULL,
832 amount decimal(16,2) DEFAULT NULL,
833 method_data text DEFAULT NULL,
834 status varchar(50) DEFAULT NULL,
835 updated_at datetime DEFAULT NULL,
836 created_at datetime DEFAULT NULL,
837 PRIMARY KEY (withdraw_id)
838 ) $charset_collate;";
839
840 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
841 dbDelta( $quiz_attempts_sql );
842 dbDelta( $quiz_attempt_answers );
843 dbDelta( $tutor_quiz_questions );
844 dbDelta( $tutor_quiz_question_answers );
845 dbDelta( $earning_table );
846 dbDelta( $withdraw_table );
847 }
848
849 /**
850 * Manage tutor roles & permission
851 *
852 * @return void
853 */
854 public static function manage_tutor_roles_and_permissions() {
855 /**
856 * Add role for instructor
857 */
858 $instructor_role = tutor()->instructor_role;
859
860 remove_role( $instructor_role );
861 add_role( $instructor_role, __( 'Tutor Instructor', 'tutor' ), array() );
862
863 $custom_post_type_permission = array(
864 // Manage Instructor.
865 'manage_tutor_instructor',
866
867 // Tutor Posts Type Permission.
868 'edit_tutor_course',
869 'read_tutor_course',
870 'delete_tutor_course',
871 'delete_tutor_courses',
872 'edit_tutor_courses',
873 'edit_others_tutor_courses',
874 'read_private_tutor_courses',
875 'edit_tutor_courses',
876
877 'edit_tutor_lesson',
878 'read_tutor_lesson',
879 'delete_tutor_lesson',
880 'delete_tutor_lessons',
881 'edit_tutor_lessons',
882 'edit_others_tutor_lessons',
883 'read_private_tutor_lessons',
884 'edit_tutor_lessons',
885 'publish_tutor_lessons',
886
887 'edit_tutor_quiz',
888 'read_tutor_quiz',
889 'delete_tutor_quiz',
890 'delete_tutor_quizzes',
891 'edit_tutor_quizzes',
892 'edit_others_tutor_quizzes',
893 'read_private_tutor_quizzes',
894 'edit_tutor_quizzes',
895 'publish_tutor_quizzes',
896
897 'edit_tutor_question',
898 'read_tutor_question',
899 'delete_tutor_question',
900 'delete_tutor_questions',
901 'edit_tutor_questions',
902 'edit_others_tutor_questions',
903 'publish_tutor_questions',
904 'read_private_tutor_questions',
905 'edit_tutor_questions',
906 );
907
908 $instructor = get_role( $instructor_role );
909 if ( $instructor ) {
910 $instructor_cap = array(
911 'edit_posts',
912 'read',
913 'upload_files',
914 );
915
916 $instructor_cap = array_merge( $instructor_cap, $custom_post_type_permission );
917
918 $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' );
919 if ( $can_publish_course ) {
920 $instructor_cap[] = 'publish_tutor_courses';
921 }
922
923 foreach ( $instructor_cap as $cap ) {
924 $instructor->add_cap( $cap );
925 }
926 }
927
928 $administrator = get_role( 'administrator' );
929 if ( $administrator ) {
930
931 $administrator_cap = array(
932 'manage_tutor',
933 );
934 $administrator_cap = array_merge( $administrator_cap, $custom_post_type_permission );
935 $administrator_cap[] = 'publish_tutor_courses';
936
937 foreach ( $administrator_cap as $cap ) {
938 $administrator->add_cap( $cap );
939 }
940 }
941
942 /**
943 * Add Instructor role to administrator
944 */
945 if ( current_user_can( 'administrator' ) ) {
946 tutor_utils()->add_instructor_role( get_current_user_id() );
947 }
948
949 }
950
951 /**
952 * On plugin activate save initial data
953 * Like: generate tutor pages
954 *
955 * @since 1.0.0
956 *
957 * @return void
958 */
959 public static function save_data() {
960
961 $student_dashboard_args = array(
962 'post_title' => __( 'Dashboard', 'tutor' ),
963 'post_content' => '',
964 'post_type' => 'page',
965 'post_status' => 'publish',
966 );
967 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
968 tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id );
969
970 $student_registration_args = array(
971 'post_title' => __( 'Student Registration', 'tutor' ),
972 'post_content' => '[tutor_student_registration_form]',
973 'post_type' => 'page',
974 'post_status' => 'publish',
975 );
976 $student_register_page_id = wp_insert_post( $student_registration_args );
977 tutor_utils()->update_option( 'student_register_page', $student_register_page_id );
978
979 $instructor_registration_args = array(
980 'post_title' => __( 'Instructor Registration', 'tutor' ),
981 'post_content' => '[tutor_instructor_registration_form]',
982 'post_type' => 'page',
983 'post_status' => 'publish',
984 );
985 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
986 tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id );
987 }
988
989 /**
990 * Default options
991 *
992 * @since 1.0.0
993 *
994 * @return array
995 */
996 public static function default_options() {
997 $options = array(
998 'pagination_per_page' => '20',
999 'course_allow_upload_private_files' => '1',
1000 'display_course_instructors' => '1',
1001 'enable_q_and_a_on_course' => '1',
1002 'courses_col_per_row' => '3',
1003 'courses_per_page' => '12',
1004 'lesson_permalink_base' => 'lesson',
1005 'quiz_when_time_expires' => 'autosubmit',
1006 'quiz_attempts_allowed' => '10',
1007 'quiz_grade_method' => 'highest_grade',
1008 'enable_public_profile' => '1',
1009 'email_to_students' =>
1010 array(
1011 'quiz_completed' => '1',
1012 'completed_course' => '1',
1013 ),
1014 'email_to_instructors' =>
1015 array(
1016 'a_student_enrolled_in_course' => '1',
1017 'a_student_completed_course' => '1',
1018 'a_student_completed_lesson' => '1',
1019 'a_student_placed_question' => '1',
1020 ),
1021 'email_from_name' => get_option( 'blogname' ),
1022 'email_from_address' => get_option( 'admin_email' ),
1023 'email_footer_text' => '',
1024 'earning_admin_commission' => '20',
1025 'earning_admin_commission' => '20',
1026 'earning_instructor_commission' => '80',
1027 'color_preset_type' => 'default',
1028 );
1029 return $options;
1030 }
1031
1032
1033 /**
1034 * Create withdraw database
1035 *
1036 * @since 1.2.0
1037 */
1038 public static function create_withdraw_database() {
1039 global $wpdb;
1040
1041 $charset_collate = $wpdb->get_charset_collate();
1042
1043 /**
1044 * Table SQL
1045 *
1046 * {$wpdb->prefix}tutor_earnings
1047 * {$wpdb->prefix}tutor_withdraws
1048 *
1049 * @since 1.2.0
1050 */
1051
1052 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
1053 earning_id bigint(20) NOT NULL AUTO_INCREMENT,
1054 user_id bigint(20) DEFAULT NULL,
1055 course_id bigint(20) DEFAULT NULL,
1056 order_id bigint(20) DEFAULT NULL,
1057 order_status varchar(50) DEFAULT NULL,
1058 course_price_total decimal(16,2) DEFAULT NULL,
1059 course_price_grand_total decimal(16,2) DEFAULT NULL,
1060 instructor_amount decimal(16,2) DEFAULT NULL,
1061 instructor_rate decimal(16,2) DEFAULT NULL,
1062 admin_amount decimal(16,2) DEFAULT NULL,
1063 admin_rate decimal(16,2) DEFAULT NULL,
1064 commission_type varchar(20) DEFAULT NULL,
1065 deduct_fees_amount decimal(16,2) DEFAULT NULL,
1066 deduct_fees_name varchar(250) DEFAULT NULL,
1067 deduct_fees_type varchar(20) DEFAULT NULL,
1068 process_by varchar(20) DEFAULT NULL,
1069 created_at datetime DEFAULT NULL,
1070 PRIMARY KEY (earning_id)
1071 ) $charset_collate;";
1072
1073 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
1074 withdraw_id bigint(20) NOT NULL AUTO_INCREMENT,
1075 user_id bigint(20) DEFAULT NULL,
1076 amount decimal(16,2) DEFAULT NULL,
1077 method_data text DEFAULT NULL,
1078 status varchar(50) DEFAULT NULL,
1079 updated_at datetime DEFAULT NULL,
1080 created_at datetime DEFAULT NULL,
1081 PRIMARY KEY (withdraw_id)
1082 ) $charset_collate;";
1083
1084 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1085 dbDelta( $earning_table );
1086 dbDelta( $withdraw_table );
1087
1088 /**
1089 * Setting previous dashboard to new dashboard
1090 */
1091 $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' );
1092 tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id );
1093 }
1094
1095 /**
1096 * Filter the wp_doing_ajax from tutor requests to get advanced
1097 * advantages from Tutor
1098 *
1099 * @since 1.3.4
1100 *
1101 * @param bool $bool default value.
1102 *
1103 * @return bool
1104 */
1105 public function wp_doing_ajax( $bool ) {
1106 // Don't use Input::has helper to avoid conflict.
1107 if ( isset( $_REQUEST['tutor_ajax_action'] ) ) {
1108 return true;
1109 }
1110 return $bool;
1111 }
1112 }
1113