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