PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.9.12
Tutor LMS – eLearning and online course solution v1.9.12
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 4 years ago Admin.php 4 years ago Ajax.php 4 years ago Assets.php 4 years ago Course.php 4 years ago Course_Filter.php 4 years ago Course_Settings_Tabs.php 5 years ago Course_Widget.php 5 years ago Custom_Validation.php 5 years ago Dashboard.php 4 years ago Email.php 5 years ago FormHandler.php 5 years ago Frontend.php 5 years ago Gutenberg.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options.php 4 years ago Post_types.php 4 years ago Private_Course_Access.php 5 years ago Q_and_A.php 5 years ago Question_Answers_List.php 4 years ago Quiz.php 4 years ago Quiz_Attempts_List.php 4 years ago RestAPI.php 4 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 5 years ago Template.php 4 years ago Theme_Compatibility.php 5 years ago Tools.php 4 years ago Tutor.php 4 years ago TutorEDD.php 5 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 4 years ago Tutor_Setup.php 4 years ago Upgrader.php 5 years ago User.php 4 years ago Utils.php 4 years ago Video_Stream.php 5 years ago Withdraw.php 5 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 4 years ago
Tutor.php
666 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) )
5 exit;
6
7 final class Tutor{
8 public $version = TUTOR_VERSION;
9 public $path;
10 public $url;
11 public $basename;
12
13 /**
14 * The single instance of the class.
15 *
16 * @since v.1.2.0
17 */
18 protected static $_instance = null;
19
20 //Components
21 public $utils;
22 public $admin;
23 public $ajax;
24 public $options;
25 public $shortcode;
26
27 private $addons;
28 private $post_types;
29 private $taxonomies;
30 private $assets;
31 private $course;
32 private $lesson;
33 private $rewrite_rules;
34 private $template;
35 private $instructor;
36 private $student;
37 private $q_and_a;
38 private $quiz;
39 private $tools;
40 private $user;
41 private $theme_compatibility;
42 private $gutenberg;
43 private $course_settings_tabs;
44 private $withdraw;
45
46 private $course_widget;
47 private $upgrader;
48 private $dashboard;
49 private $form_handler;
50 private $frontend;
51 private $email;
52
53 //Integrations
54 private $woocommerce;
55 private $edd;
56
57 /**
58 * @return null|Tutor
59 *
60 * Run the TUTOR
61 *
62 * @since 1.2.0
63 */
64 public static function instance() {
65 if ( is_null( self::$_instance ) ) {
66 self::$_instance = new self();
67 }
68 return self::$_instance;
69 }
70
71 function __construct() {
72
73 $this->path = plugin_dir_path(TUTOR_FILE);
74 $this->url = plugin_dir_url(TUTOR_FILE);
75 $this->basename = plugin_basename(TUTOR_FILE);
76
77 /**
78 * Adding Tutor Database table to $wpdb;
79 * @since v.1.4.2
80 */
81 global $wpdb;
82 $wpdb->tutor_earnings = $wpdb->prefix.'tutor_earnings';
83 $wpdb->tutor_gradebooks = $wpdb->prefix.'tutor_gradebooks';
84 $wpdb->tutor_gradebooks_results = $wpdb->prefix.'tutor_gradebooks_results';
85 $wpdb->tutor_quiz_attempts = $wpdb->prefix.'tutor_quiz_attempts';
86 $wpdb->tutor_quiz_attempt_answers = $wpdb->prefix.'tutor_quiz_attempt_answers';
87 $wpdb->tutor_quiz_questions = $wpdb->prefix.'tutor_quiz_questions';
88 $wpdb->tutor_quiz_question_answers = $wpdb->prefix.'tutor_quiz_question_answers';
89 $wpdb->tutor_withdraws = $wpdb->prefix.'tutor_withdraws';
90 $wpdb->tutor_email_queue = $wpdb->prefix.'tutor_email_queue';
91
92 /**
93 * Changing default wp doing ajax return based on tutor ajax action
94 */
95 add_filter('wp_doing_ajax', array($this, 'wp_doing_ajax'));
96
97 /**
98 * Include Files
99 */
100 //add_action( 'init', array( $this, 'includes' ), 11 );
101 $this->includes();
102
103 /**
104 * Loading Autoloader
105 */
106 spl_autoload_register(array($this, 'loader'));
107
108 do_action('tutor_before_load');
109
110 $this->addons = new Addons();
111 $this->post_types = new Post_types();
112 $this->taxonomies = new Taxonomies();
113 $this->assets = new Assets();
114 $this->admin = new Admin();
115 $this->ajax = new Ajax();
116 $this->options = new Options();
117 $this->shortcode = new Shortcode();
118 $this->course = new Course();
119 $this->lesson = new Lesson();
120 $this->rewrite_rules = new Rewrite_Rules();
121 $this->template = new Template();
122 $this->instructor = new Instructor();
123 $this->student = new Student();
124 $this->q_and_a = new Q_and_A();
125 $this->quiz = new Quiz();
126 $this->tools = new Tools();
127 $this->user = new User();
128 $this->theme_compatibility = new Theme_Compatibility();
129 $this->gutenberg = new Gutenberg();
130 $this->course_settings_tabs = new Course_Settings_Tabs();
131 $this->withdraw = new Withdraw();
132 $this->course_widget = new Course_Widget();
133 $this->upgrader = new Upgrader();
134 $this->dashboard = new Dashboard();
135 $this->form_handler = new FormHandler();
136 $this->frontend = new Frontend();
137 $this->email = new Email();
138 $this->rest_api = new RestAPI();
139 $this->setup = new Tutor_Setup();
140 $this->private_course_access = new Private_Course_Access();
141 $this->course_filter = new Course_Filter();
142
143 //Integrations
144 $this->woocommerce = new WooCommerce();
145 $this->edd = new TutorEDD();
146
147 /**
148 * Run Method
149 * @since v.1.2.0
150 */
151 $this->run();
152
153 do_action('tutor_loaded');
154
155 add_action( 'init', array( $this, 'init_action' ) );
156
157 /**
158 * redirect to the wizard page
159 * @since v.1.5.7
160 *
161 */
162
163 add_action( 'activated_plugin', array( $this, 'activated_tutor' ), 10, 2 );
164 }
165
166 /**
167 * @param $plugin
168 *
169 * redirect to the wizard page
170 * @since v.1.5.7
171 *
172 */
173 public function activated_tutor( $plugin, $network_wide = null ) {
174 if( $plugin == tutor()->basename ) {
175 if( (! get_option('tutor_wizard') ) && version_compare(TUTOR_VERSION, '1.5.6', '>') ) {
176 update_option('tutor_wizard', 'active');
177 exit(wp_redirect(admin_url('admin.php?page=tutor-setup')));
178 }
179 }
180 }
181
182 /**
183 * @param $className
184 *
185 * Auto Load class and the files
186 */
187 private function loader($className) {
188 if ( ! class_exists($className)){
189 $className = preg_replace(
190 array('/([a-z])([A-Z])/', '/\\\/'),
191 array('$1$2', DIRECTORY_SEPARATOR),
192 $className
193 );
194
195 $className = str_replace('TUTOR'.DIRECTORY_SEPARATOR, 'classes'.DIRECTORY_SEPARATOR, $className);
196 $file_name = $this->path.$className.'.php';
197
198 if (file_exists($file_name) ) {
199 require_once $file_name;
200 }
201 }
202 }
203
204 public function includes(){
205 include tutor()->path.'includes/tutor-general-functions.php';
206 include tutor()->path.'includes/tutor-template-functions.php';
207 include tutor()->path.'includes/tutor-template-hook.php';
208 }
209
210 //Run the TUTOR right now
211 public function run(){
212 do_action('tutor_before_run');
213
214 do_action('tutor_after_run');
215 }
216
217 /**
218 * Tutor Action Via do_action
219 * @since 1.2.14
220 */
221 public function init_action(){
222 if (isset($_REQUEST['tutor_action'])){
223 do_action('tutor_action_'.$_REQUEST['tutor_action']);
224 }
225 }
226
227 /**
228 * Do some task during plugin activation
229 */
230 public static function tutor_activate() {
231 $version = get_option( 'tutor_version' );
232 if ( ! function_exists( 'tutor_time' ) ) {
233 include tutor()->path . 'includes/tutor-general-functions.php';
234 }
235
236 // Create Database
237 self::create_database();
238
239 //Save Option
240 if ( ! $version ) {
241
242 $options = self::default_options();
243 update_option('tutor_option', $options);
244
245 //Rewrite Flush
246 update_option('required_rewrite_flush', tutor_time());
247 self::manage_tutor_roles_and_permissions();
248
249 self::save_data();//Save initial Page
250 update_option('tutor_version', TUTOR_VERSION);
251 }
252
253 //Set Schedule
254 if ( ! wp_next_scheduled ( 'tutor_once_in_day_run_schedule' ) ) {
255 wp_schedule_event( tutor_time(), 'twicedaily', 'tutor_once_in_day_run_schedule' );
256 }
257
258 /**
259 * Backward Compatibility for version < 1.2.0
260 */
261 if ( version_compare( get_option( 'tutor_version' ), '1.2.0', '<' ) ) {
262 /**
263 * Creating New Database
264 */
265 self::create_withdraw_database();
266 //Update the tutor version
267 update_option( 'tutor_version', '1.2.0' );
268 //Rewrite Flush
269 update_option( 'required_rewrite_flush', tutor_time() );
270 }
271
272 /**
273 * Backward Compatibility to < 1.3.1 for make course plural
274 */
275 if (version_compare(get_option('tutor_version'), '1.3.1', '<')){
276 global $wpdb;
277
278 if ( ! get_option('is_course_post_type_updated')){
279 $wpdb->update($wpdb->posts, array('post_type' => 'courses'), array('post_type' => 'course'));
280 update_option('is_course_post_type_updated', true);
281 update_option('tutor_version', '1.3.1');
282 flush_rewrite_rules();
283 }
284 }
285
286 /**
287 * Save First activation Time
288 */
289 $first_activation_date = get_option('tutor_first_activation_time');
290 if ( ! $first_activation_date){
291 update_option('tutor_first_activation_time', tutor_time());
292 }
293 }
294
295 //Run task on deactivation
296 public static function tutor_deactivation() {
297 wp_clear_scheduled_hook('tutor_once_in_day_run_schedule');
298 }
299
300 public static function create_database(){
301 global $wpdb;
302
303 $charset_collate = $wpdb->get_charset_collate();
304
305 /**
306 * Table SQL
307 *
308 * {$wpdb->prefix}tutor_quiz_attempts
309 * {$wpdb->prefix}tutor_quiz_attempt_answers
310 * {$wpdb->prefix}tutor_quiz_questions
311 * {$wpdb->prefix}tutor_quiz_question_answers
312 * {$wpdb->prefix}tutor_earnings
313 * {$wpdb->prefix}tutor_withdraws
314 *
315 * @since v.1.0.0
316 */
317 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
318 attempt_id int(11) NOT NULL AUTO_INCREMENT,
319 course_id int(11) DEFAULT NULL,
320 quiz_id int(11) DEFAULT NULL,
321 user_id int(11) DEFAULT NULL,
322 total_questions int(11) DEFAULT NULL,
323 total_answered_questions int(11) DEFAULT NULL,
324 total_marks decimal(9,2) DEFAULT NULL,
325 earned_marks decimal(9,2) DEFAULT NULL,
326 attempt_info text,
327 attempt_status varchar(50) DEFAULT NULL,
328 attempt_ip varchar(250) DEFAULT NULL,
329 attempt_started_at datetime DEFAULT NULL,
330 attempt_ended_at datetime DEFAULT NULL,
331 is_manually_reviewed int(1) DEFAULT NULL,
332 manually_reviewed_at datetime DEFAULT NULL,
333 PRIMARY KEY (attempt_id)
334 ) $charset_collate;";
335
336 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
337 attempt_answer_id int(11) NOT NULL AUTO_INCREMENT,
338 user_id int(11) DEFAULT NULL,
339 quiz_id int(11) DEFAULT NULL,
340 question_id int(11) DEFAULT NULL,
341 quiz_attempt_id int(11) DEFAULT NULL,
342 given_answer longtext,
343 question_mark decimal(8,2) DEFAULT NULL,
344 achieved_mark decimal(8,2) DEFAULT NULL,
345 minus_mark decimal(8,2) DEFAULT NULL,
346 is_correct tinyint(4) DEFAULT NULL,
347 PRIMARY KEY (attempt_answer_id)
348 ) $charset_collate;";
349
350 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
351 question_id int(11) NOT NULL AUTO_INCREMENT,
352 quiz_id int(11) DEFAULT NULL,
353 question_title text,
354 question_description longtext,
355 question_type varchar(50) DEFAULT NULL,
356 question_mark decimal(9,2) DEFAULT NULL,
357 question_settings longtext,
358 question_order int(11) DEFAULT NULL,
359 PRIMARY KEY (question_id)
360 ) $charset_collate;";
361
362 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
363 answer_id int(11) NOT NULL AUTO_INCREMENT,
364 belongs_question_id int(11) DEFAULT NULL,
365 belongs_question_type varchar(250) DEFAULT NULL,
366 answer_title text,
367 is_correct tinyint(4) DEFAULT NULL,
368 image_id int(11) DEFAULT NULL,
369 answer_two_gap_match text,
370 answer_view_format varchar(250) DEFAULT NULL,
371 answer_settings text,
372 answer_order int(11) DEFAULT '0',
373 PRIMARY KEY (answer_id)
374 ) $charset_collate;";
375
376 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
377 earning_id int(11) NOT NULL AUTO_INCREMENT,
378 user_id int(11) DEFAULT NULL,
379 course_id int(11) DEFAULT NULL,
380 order_id int(11) DEFAULT NULL,
381 order_status varchar(50) DEFAULT NULL,
382 course_price_total decimal(16,2) DEFAULT NULL,
383 course_price_grand_total decimal(16,2) DEFAULT NULL,
384 instructor_amount decimal(16,2) DEFAULT NULL,
385 instructor_rate decimal(16,2) DEFAULT NULL,
386 admin_amount decimal(16,2) DEFAULT NULL,
387 admin_rate decimal(16,2) DEFAULT NULL,
388 commission_type varchar(20) DEFAULT NULL,
389 deduct_fees_amount decimal(16,2) DEFAULT NULL,
390 deduct_fees_name varchar(250) DEFAULT NULL,
391 deduct_fees_type varchar(20) DEFAULT NULL,
392 process_by varchar(20) DEFAULT NULL,
393 created_at datetime DEFAULT NULL,
394 PRIMARY KEY (earning_id)
395 ) $charset_collate;";
396
397 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
398 withdraw_id int(11) NOT NULL AUTO_INCREMENT,
399 user_id int(11) DEFAULT NULL,
400 amount decimal(16,2) DEFAULT NULL,
401 method_data text DEFAULT NULL,
402 status varchar(50) DEFAULT NULL,
403 updated_at datetime DEFAULT NULL,
404 created_at datetime DEFAULT NULL,
405 PRIMARY KEY (withdraw_id)
406 ) $charset_collate;";
407
408 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
409 dbDelta( $quiz_attempts_sql );
410 dbDelta( $quiz_attempt_answers );
411 dbDelta( $tutor_quiz_questions );
412 dbDelta( $tutor_quiz_question_answers );
413 dbDelta( $earning_table );
414 dbDelta( $withdraw_table );
415 }
416
417 public static function manage_tutor_roles_and_permissions(){
418 /**
419 * Add role for instructor
420 */
421 $instructor_role = tutor()->instructor_role;
422
423 remove_role($instructor_role);
424 add_role( $instructor_role, __('Tutor Instructor', 'tutor'), array() );
425
426 $custom_post_type_permission = array(
427 //Manage Instructor
428 'manage_tutor_instructor',
429
430 //Tutor Posts Type Permission
431 'edit_tutor_course',
432 'read_tutor_course',
433 'delete_tutor_course',
434 'delete_tutor_courses',
435 'edit_tutor_courses',
436 'edit_others_tutor_courses',
437 'read_private_tutor_courses',
438 'edit_tutor_courses',
439
440 'edit_tutor_lesson',
441 'read_tutor_lesson',
442 'delete_tutor_lesson',
443 'delete_tutor_lessons',
444 'edit_tutor_lessons',
445 'edit_others_tutor_lessons',
446 'read_private_tutor_lessons',
447 'edit_tutor_lessons',
448 'publish_tutor_lessons',
449
450 'edit_tutor_quiz',
451 'read_tutor_quiz',
452 'delete_tutor_quiz',
453 'delete_tutor_quizzes',
454 'edit_tutor_quizzes',
455 'edit_others_tutor_quizzes',
456 'read_private_tutor_quizzes',
457 'edit_tutor_quizzes',
458 'publish_tutor_quizzes',
459
460 'edit_tutor_question',
461 'read_tutor_question',
462 'delete_tutor_question',
463 'delete_tutor_questions',
464 'edit_tutor_questions',
465 'edit_others_tutor_questions',
466 'publish_tutor_questions',
467 'read_private_tutor_questions',
468 'edit_tutor_questions',
469 );
470
471 $instructor = get_role( $instructor_role );
472 if ( $instructor ) {
473 $instructor_cap = array (
474 'edit_posts',
475 'read',
476 'upload_files',
477 );
478
479 $instructor_cap = array_merge($instructor_cap, $custom_post_type_permission);
480
481 $can_publish_course = (bool) tutor_utils()->get_option('instructor_can_publish_course');
482 if ($can_publish_course){
483 $instructor_cap[] = 'publish_tutor_courses';
484 }
485
486 foreach ($instructor_cap as $cap){
487 $instructor->add_cap( $cap );
488 }
489 }
490
491 $administrator = get_role( 'administrator' );
492 if ( $administrator ) {
493
494 $administrator_cap = array (
495 'manage_tutor',
496 );
497 $administrator_cap = array_merge($administrator_cap, $custom_post_type_permission);
498 $administrator_cap[] = 'publish_tutor_courses';
499
500 foreach ($administrator_cap as $cap){
501 $administrator->add_cap( $cap );
502 }
503 }
504
505 /**
506 * Add Instructor role to administrator
507 */
508 if (current_user_can('administrator')){
509 tutor_utils()->add_instructor_role(get_current_user_id());
510 }
511
512 }
513
514 /**
515 * Save data like page
516 */
517 public static function save_data(){
518 $student_dashboard_args = array(
519 'post_title' => __('Dashboard', 'tutor'),
520 'post_content' => '',
521 'post_type' => 'page',
522 'post_status' => 'publish',
523 );
524 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
525 tutor_utils()->update_option('tutor_dashboard_page_id', $student_dashboard_page_id);
526
527 $student_registration_args = array(
528 'post_title' => __('Student Registration', 'tutor'),
529 'post_content' => '[tutor_student_registration_form]',
530 'post_type' => 'page',
531 'post_status' => 'publish',
532 );
533 $student_register_page_id = wp_insert_post( $student_registration_args );
534 tutor_utils()->update_option('student_register_page', $student_register_page_id);
535
536 $instructor_registration_args = array(
537 'post_title' => __('Instructor Registration', 'tutor'),
538 'post_content' => '[tutor_instructor_registration_form]',
539 'post_type' => 'page',
540 'post_status' => 'publish',
541 );
542 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
543 tutor_utils()->update_option('instructor_register_page', $instructor_registration_id);
544 }
545
546 public static function default_options(){
547 $options = array (
548 'pagination_per_page' => '20',
549 'course_allow_upload_private_files' => '1',
550 'display_course_instructors' => '1',
551 'enable_q_and_a_on_course' => '1',
552 'courses_col_per_row' => '3',
553 'courses_per_page' => '12',
554 'lesson_permalink_base' => 'lesson',
555 'quiz_time_limit' =>
556 array (
557 'value' => '0',
558 'time' => 'minutes',
559 ),
560 'quiz_when_time_expires' => 'autosubmit',
561 'quiz_attempts_allowed' => '10',
562 'quiz_grade_method' => 'highest_grade',
563 'enable_public_profile' => '1',
564 'email_to_students' =>
565 array (
566 'quiz_completed' => '1',
567 'completed_course' => '1',
568 ),
569 'email_to_instructors' =>
570 array (
571 'a_student_enrolled_in_course' => '1',
572 'a_student_completed_course' => '1',
573 'a_student_completed_lesson' => '1',
574 'a_student_placed_question' => '1',
575 ),
576 'email_from_name' => get_option('blogname'),
577 'email_from_address' => get_option('admin_email'),
578 'email_footer_text' => '',
579 'earning_admin_commission' => '20',
580 'earning_admin_commission' => '20',
581 'earning_instructor_commission' => '80'
582 );
583 return $options;
584 }
585
586
587 /**
588 * Create withdraw database
589 *
590 * @since v.1.2.0
591 */
592 public static function create_withdraw_database(){
593 global $wpdb;
594
595 $charset_collate = $wpdb->get_charset_collate();
596
597 /**
598 * Table SQL
599 *
600 * {$wpdb->prefix}tutor_earnings
601 * {$wpdb->prefix}tutor_withdraws
602 *
603 * @since v.1.2.0
604 */
605
606 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
607 earning_id int(11) NOT NULL AUTO_INCREMENT,
608 user_id int(11) DEFAULT NULL,
609 course_id int(11) DEFAULT NULL,
610 order_id int(11) DEFAULT NULL,
611 order_status varchar(50) DEFAULT NULL,
612 course_price_total decimal(16,2) DEFAULT NULL,
613 course_price_grand_total decimal(16,2) DEFAULT NULL,
614 instructor_amount decimal(16,2) DEFAULT NULL,
615 instructor_rate decimal(16,2) DEFAULT NULL,
616 admin_amount decimal(16,2) DEFAULT NULL,
617 admin_rate decimal(16,2) DEFAULT NULL,
618 commission_type varchar(20) DEFAULT NULL,
619 deduct_fees_amount decimal(16,2) DEFAULT NULL,
620 deduct_fees_name varchar(250) DEFAULT NULL,
621 deduct_fees_type varchar(20) DEFAULT NULL,
622 process_by varchar(20) DEFAULT NULL,
623 created_at datetime DEFAULT NULL,
624 PRIMARY KEY (earning_id)
625 ) $charset_collate;";
626
627 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
628 withdraw_id int(11) NOT NULL AUTO_INCREMENT,
629 user_id int(11) DEFAULT NULL,
630 amount decimal(16,2) DEFAULT NULL,
631 method_data text DEFAULT NULL,
632 status varchar(50) DEFAULT NULL,
633 updated_at datetime DEFAULT NULL,
634 created_at datetime DEFAULT NULL,
635 PRIMARY KEY (withdraw_id)
636 ) $charset_collate;";
637
638 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
639 dbDelta( $earning_table );
640 dbDelta( $withdraw_table );
641
642 /**
643 * Setting previous dashboard to new dashboard
644 */
645 $previous_dashboard_page_id = (int) tutor_utils()->get_option('student_dashboard');
646 tutor_utils()->update_option('tutor_dashboard_page_id', $previous_dashboard_page_id);
647 }
648
649 /**
650 * @param $bool
651 *
652 * @return bool
653 *
654 * Filter the wp_doing_ajax from tutor requests to get advanced advantages from Tutor
655 *
656 * @since v.1.3.4
657 */
658 public function wp_doing_ajax($bool){
659 if (isset($_REQUEST['tutor_ajax_action'])){
660 return true;
661 }
662 return $bool;
663 }
664
665
666 }