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