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