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