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