Addons.php
2 years ago
Admin.php
2 years ago
Ajax.php
2 years ago
Announcements.php
3 years ago
Assets.php
2 years ago
Backend_Page_Trait.php
3 years ago
Course.php
2 years ago
Course_Embed.php
3 years ago
Course_Filter.php
2 years ago
Course_List.php
2 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
2 years ago
Frontend.php
2 years ago
Gutenberg.php
3 years ago
Input.php
3 years ago
Instructor.php
2 years ago
Instructors_List.php
2 years ago
Lesson.php
2 years ago
Options_V2.php
2 years ago
Post_types.php
2 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
2 years ago
Quiz_Attempts_List.php
2 years ago
RestAPI.php
3 years ago
Reviews.php
3 years ago
Rewrite_Rules.php
2 years ago
Shortcode.php
2 years ago
Student.php
2 years ago
Students_List.php
3 years ago
Taxonomies.php
3 years ago
Template.php
2 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
2 years ago
Tutor_Base.php
2 years ago
Tutor_Setup.php
3 years ago
Upgrader.php
2 years ago
User.php
2 years ago
Utils.php
2 years ago
Video_Stream.php
3 years ago
WhatsNew.php
2 years ago
Withdraw.php
2 years ago
Withdraw_Requests_List.php
3 years ago
WooCommerce.php
2 years ago
Tutor.php
1105 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 | public $course_list; |
| 400 | |
| 401 | //phpcs:disable |
| 402 | public $q_and_a_list; |
| 403 | public $q_attempt; |
| 404 | public $rest_api; |
| 405 | public $setup; |
| 406 | public $private_course_access; |
| 407 | public $course_filter; |
| 408 | //phpcs:enable |
| 409 | |
| 410 | /** |
| 411 | * Course Embed |
| 412 | * |
| 413 | * @var $course_embed |
| 414 | * |
| 415 | * @since 2.1.0 |
| 416 | */ |
| 417 | private $course_embed; |
| 418 | |
| 419 | /** |
| 420 | * Rest Authentication |
| 421 | * |
| 422 | * @var $rest_auth |
| 423 | * |
| 424 | * @since 2.1.0 |
| 425 | */ |
| 426 | private $rest_auth; |
| 427 | |
| 428 | /** |
| 429 | * Run the TUTOR |
| 430 | * |
| 431 | * @since 1.2.0 |
| 432 | * |
| 433 | * @return null|Tutor |
| 434 | */ |
| 435 | public static function instance() { |
| 436 | if ( is_null( self::$_instance ) ) { |
| 437 | self::$_instance = new self(); |
| 438 | } |
| 439 | return self::$_instance; |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Initialize props & other dependencies |
| 444 | * |
| 445 | * @since 1.0.0 |
| 446 | */ |
| 447 | public function __construct() { |
| 448 | |
| 449 | $this->path = plugin_dir_path( TUTOR_FILE ); |
| 450 | $this->url = plugin_dir_url( TUTOR_FILE ); |
| 451 | $this->basename = plugin_basename( TUTOR_FILE ); |
| 452 | |
| 453 | /** |
| 454 | * Adding Tutor Database table to $wpdb; |
| 455 | * |
| 456 | * @since 1.4.2 |
| 457 | */ |
| 458 | global $wpdb; |
| 459 | $wpdb->tutor_earnings = $wpdb->prefix . 'tutor_earnings'; |
| 460 | $wpdb->tutor_gradebooks = $wpdb->prefix . 'tutor_gradebooks'; |
| 461 | $wpdb->tutor_gradebooks_results = $wpdb->prefix . 'tutor_gradebooks_results'; |
| 462 | $wpdb->tutor_quiz_attempts = $wpdb->prefix . 'tutor_quiz_attempts'; |
| 463 | $wpdb->tutor_quiz_attempt_answers = $wpdb->prefix . 'tutor_quiz_attempt_answers'; |
| 464 | $wpdb->tutor_quiz_questions = $wpdb->prefix . 'tutor_quiz_questions'; |
| 465 | $wpdb->tutor_quiz_question_answers = $wpdb->prefix . 'tutor_quiz_question_answers'; |
| 466 | $wpdb->tutor_withdraws = $wpdb->prefix . 'tutor_withdraws'; |
| 467 | $wpdb->tutor_email_queue = $wpdb->prefix . 'tutor_email_queue'; |
| 468 | |
| 469 | /** |
| 470 | * Changing default wp doing ajax return based on tutor ajax action |
| 471 | */ |
| 472 | add_filter( 'wp_doing_ajax', array( $this, 'wp_doing_ajax' ) ); |
| 473 | |
| 474 | /** |
| 475 | * Include Files |
| 476 | */ |
| 477 | $this->includes(); |
| 478 | |
| 479 | /** |
| 480 | * Loading Auto loader |
| 481 | */ |
| 482 | spl_autoload_register( array( $this, 'loader' ) ); |
| 483 | |
| 484 | do_action( 'tutor_before_load' ); |
| 485 | |
| 486 | $this->addons = new Addons(); |
| 487 | $this->post_types = new Post_types(); |
| 488 | $this->taxonomies = new Taxonomies(); |
| 489 | $this->assets = new Assets(); |
| 490 | $this->admin = new Admin(); |
| 491 | $this->ajax = new Ajax(); |
| 492 | $this->options = new Options_V2(); |
| 493 | $this->shortcode = new Shortcode(); |
| 494 | $this->course = new Course(); |
| 495 | $this->lesson = new Lesson(); |
| 496 | $this->rewrite_rules = new Rewrite_Rules(); |
| 497 | $this->template = new Template(); |
| 498 | $this->instructor = new Instructor(); |
| 499 | $this->student = new Student(); |
| 500 | $this->q_and_a = new Q_and_A(); |
| 501 | $this->q_and_a_list = new Question_Answers_List(); |
| 502 | $this->q_attempt = new Quiz_Attempts_List(); |
| 503 | $this->quiz = new Quiz(); |
| 504 | $this->tools = new Tools(); |
| 505 | $this->user = new User(); |
| 506 | $this->theme_compatibility = new Theme_Compatibility(); |
| 507 | $this->gutenberg = new Gutenberg(); |
| 508 | $this->course_settings_tabs = new Course_Settings_Tabs(); |
| 509 | $this->withdraw = new Withdraw(); |
| 510 | $this->course_widget = new Course_Widget(); |
| 511 | $this->upgrader = new Upgrader(); |
| 512 | $this->dashboard = new Dashboard(); |
| 513 | $this->form_handler = new FormHandler(); |
| 514 | $this->frontend = new Frontend(); |
| 515 | $this->rest_api = new RestAPI(); |
| 516 | $this->setup = new Tutor_Setup(); |
| 517 | $this->private_course_access = new Private_Course_Access(); |
| 518 | $this->course_filter = new Course_Filter(); |
| 519 | |
| 520 | // Integrations. |
| 521 | $this->woocommerce = new WooCommerce(); |
| 522 | $this->edd = new TutorEDD(); |
| 523 | |
| 524 | /** |
| 525 | * Init obj |
| 526 | * |
| 527 | * @since 2.0.0 |
| 528 | */ |
| 529 | $this->announcements = new Announcements(); |
| 530 | $this->course_list = new Course_List(); |
| 531 | $this->reviews = new Reviews(); |
| 532 | $this->withdraw_list = new Withdraw_Requests_List(); |
| 533 | $this->student_list = new Students_List(); |
| 534 | $this->instructor_list = new Instructors_List(); |
| 535 | $this->course_embed = new Course_Embed(); |
| 536 | $this->rest_auth = new RestAuth(); |
| 537 | |
| 538 | /** |
| 539 | * Run Method |
| 540 | * |
| 541 | * @since v.1.2.0 |
| 542 | */ |
| 543 | $this->run(); |
| 544 | |
| 545 | do_action( 'tutor_loaded' ); |
| 546 | |
| 547 | add_action( 'init', array( $this, 'init_action' ) ); |
| 548 | |
| 549 | /** |
| 550 | * Redirect to the wizard page |
| 551 | * |
| 552 | * @since 1.5.7 |
| 553 | */ |
| 554 | |
| 555 | add_action( 'activated_plugin', array( $this, 'activated_tutor' ), 10, 2 ); |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * Redirect to the wizard page |
| 560 | * |
| 561 | * @since 1.5.7 |
| 562 | * |
| 563 | * @param mixed $plugin plugin. |
| 564 | * @param mixed $network_wide network wide. |
| 565 | * |
| 566 | * @return void |
| 567 | */ |
| 568 | public function activated_tutor( $plugin, $network_wide = null ) { |
| 569 | if ( tutor()->basename === $plugin ) { |
| 570 | if ( ( ! get_option( 'tutor_wizard' ) ) && version_compare( TUTOR_VERSION, '1.5.6', '>' ) ) { |
| 571 | update_option( 'tutor_wizard', 'active' ); |
| 572 | wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) ); |
| 573 | exit; |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * Auto Load class and the files |
| 580 | * |
| 581 | * @since 1.0.0 |
| 582 | * |
| 583 | * @param string $class_name class name to load. |
| 584 | * |
| 585 | * @return void |
| 586 | */ |
| 587 | private function loader( $class_name ) { |
| 588 | if ( ! class_exists( $class_name ) ) { |
| 589 | $class_name = preg_replace( |
| 590 | array( '/([a-z])([A-Z])/', '/\\\/' ), |
| 591 | array( '$1$2', DIRECTORY_SEPARATOR ), |
| 592 | $class_name |
| 593 | ); |
| 594 | |
| 595 | $class_name = str_replace( 'TUTOR' . DIRECTORY_SEPARATOR, 'classes' . DIRECTORY_SEPARATOR, $class_name ); |
| 596 | $file_name = $this->path . $class_name . '.php'; |
| 597 | |
| 598 | if ( file_exists( $file_name ) ) { |
| 599 | require_once $file_name; |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * Include utility functions |
| 606 | * |
| 607 | * @return void |
| 608 | */ |
| 609 | public function includes() { |
| 610 | include tutor()->path . 'includes/tutor-general-functions.php'; |
| 611 | include tutor()->path . 'includes/tutor-template-functions.php'; |
| 612 | include tutor()->path . 'includes/tutor-template-hook.php'; |
| 613 | include tutor()->path . 'includes/translate-text.php'; |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Providing hooks |
| 618 | * |
| 619 | * @return void |
| 620 | */ |
| 621 | public function run() { |
| 622 | do_action( 'tutor_before_run' ); |
| 623 | do_action( 'tutor_after_run' ); |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * Tutor Action Via do_action |
| 628 | * |
| 629 | * @since 1.2.14 |
| 630 | */ |
| 631 | public function init_action() { |
| 632 | $tutor_action = Input::sanitize_request_data( 'tutor_action' ); |
| 633 | if ( '' !== $tutor_action ) { |
| 634 | do_action( 'tutor_action_' . $tutor_action ); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Do some task during plugin activation |
| 640 | */ |
| 641 | public static function tutor_activate() { |
| 642 | $version = get_option( 'tutor_version' ); |
| 643 | if ( ! function_exists( 'tutor_time' ) ) { |
| 644 | include tutor()->path . 'includes/tutor-general-functions.php'; |
| 645 | } |
| 646 | |
| 647 | // Create Database. |
| 648 | self::create_database(); |
| 649 | |
| 650 | // Save Option. |
| 651 | if ( ! $version ) { |
| 652 | |
| 653 | $options = self::default_options(); |
| 654 | update_option( 'tutor_option', $options ); |
| 655 | |
| 656 | // Rewrite Flush. |
| 657 | update_option( 'required_rewrite_flush', tutor_time() ); |
| 658 | self::manage_tutor_roles_and_permissions(); |
| 659 | |
| 660 | // Save initial Page. |
| 661 | self::save_data(); |
| 662 | update_option( 'tutor_version', TUTOR_VERSION ); |
| 663 | } |
| 664 | |
| 665 | // Set Schedule. |
| 666 | if ( ! wp_next_scheduled( 'tutor_once_in_day_run_schedule' ) ) { |
| 667 | wp_schedule_event( tutor_time(), 'twicedaily', 'tutor_once_in_day_run_schedule' ); |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Backward Compatibility for version < 1.2.0 |
| 672 | */ |
| 673 | if ( version_compare( get_option( 'tutor_version' ), '1.2.0', '<' ) ) { |
| 674 | /** |
| 675 | * Creating New Database |
| 676 | */ |
| 677 | self::create_withdraw_database(); |
| 678 | // Update the tutor version. |
| 679 | update_option( 'tutor_version', '1.2.0' ); |
| 680 | // Rewrite Flush. |
| 681 | update_option( 'required_rewrite_flush', tutor_time() ); |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Backward Compatibility to < 1.3.1 for make course plural |
| 686 | */ |
| 687 | if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) { |
| 688 | global $wpdb; |
| 689 | |
| 690 | if ( ! get_option( 'is_course_post_type_updated' ) ) { |
| 691 | $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) ); |
| 692 | update_option( 'is_course_post_type_updated', true ); |
| 693 | update_option( 'tutor_version', '1.3.1' ); |
| 694 | flush_rewrite_rules(); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Save First activation Time |
| 700 | */ |
| 701 | $first_activation_date = get_option( 'tutor_first_activation_time' ); |
| 702 | if ( ! $first_activation_date ) { |
| 703 | update_option( 'tutor_first_activation_time', tutor_time() ); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Run task on deactivation |
| 709 | * |
| 710 | * @since 1.0.0 |
| 711 | * |
| 712 | * @return void |
| 713 | */ |
| 714 | public static function tutor_deactivation() { |
| 715 | wp_clear_scheduled_hook( 'tutor_once_in_day_run_schedule' ); |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * Create database |
| 720 | * |
| 721 | * @return void |
| 722 | */ |
| 723 | public static function create_database() { |
| 724 | global $wpdb; |
| 725 | |
| 726 | $charset_collate = $wpdb->get_charset_collate(); |
| 727 | |
| 728 | /** |
| 729 | * Table SQL |
| 730 | * |
| 731 | * {$wpdb->prefix}tutor_quiz_attempts |
| 732 | * {$wpdb->prefix}tutor_quiz_attempt_answers |
| 733 | * {$wpdb->prefix}tutor_quiz_questions |
| 734 | * {$wpdb->prefix}tutor_quiz_question_answers |
| 735 | * {$wpdb->prefix}tutor_earnings |
| 736 | * {$wpdb->prefix}tutor_withdraws |
| 737 | * |
| 738 | * @since 1.0.0 |
| 739 | */ |
| 740 | $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts ( |
| 741 | attempt_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 742 | course_id bigint(20) DEFAULT NULL, |
| 743 | quiz_id bigint(20) DEFAULT NULL, |
| 744 | user_id bigint(20) DEFAULT NULL, |
| 745 | total_questions int(11) DEFAULT NULL, |
| 746 | total_answered_questions int(11) DEFAULT NULL, |
| 747 | total_marks decimal(9,2) DEFAULT NULL, |
| 748 | earned_marks decimal(9,2) DEFAULT NULL, |
| 749 | attempt_info text, |
| 750 | attempt_status varchar(50) DEFAULT NULL, |
| 751 | attempt_ip varchar(250) DEFAULT NULL, |
| 752 | attempt_started_at datetime DEFAULT NULL, |
| 753 | attempt_ended_at datetime DEFAULT NULL, |
| 754 | is_manually_reviewed int(1) DEFAULT NULL, |
| 755 | manually_reviewed_at datetime DEFAULT NULL, |
| 756 | PRIMARY KEY (attempt_id) |
| 757 | ) $charset_collate;"; |
| 758 | |
| 759 | $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers ( |
| 760 | attempt_answer_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 761 | user_id bigint(20) DEFAULT NULL, |
| 762 | quiz_id bigint(20) DEFAULT NULL, |
| 763 | question_id bigint(20) DEFAULT NULL, |
| 764 | quiz_attempt_id bigint(20) DEFAULT NULL, |
| 765 | given_answer longtext, |
| 766 | question_mark decimal(8,2) DEFAULT NULL, |
| 767 | achieved_mark decimal(8,2) DEFAULT NULL, |
| 768 | minus_mark decimal(8,2) DEFAULT NULL, |
| 769 | is_correct tinyint(4) DEFAULT NULL, |
| 770 | PRIMARY KEY (attempt_answer_id) |
| 771 | ) $charset_collate;"; |
| 772 | |
| 773 | $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions ( |
| 774 | question_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 775 | quiz_id bigint(20) DEFAULT NULL, |
| 776 | question_title text, |
| 777 | question_description longtext, |
| 778 | answer_explanation longtext DEFAULT '', |
| 779 | question_type varchar(50) DEFAULT NULL, |
| 780 | question_mark decimal(9,2) DEFAULT NULL, |
| 781 | question_settings longtext, |
| 782 | question_order int(11) DEFAULT NULL, |
| 783 | PRIMARY KEY (question_id) |
| 784 | ) $charset_collate;"; |
| 785 | |
| 786 | $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers ( |
| 787 | answer_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 788 | belongs_question_id bigint(20) DEFAULT NULL, |
| 789 | belongs_question_type varchar(250) DEFAULT NULL, |
| 790 | answer_title text, |
| 791 | is_correct tinyint(4) DEFAULT NULL, |
| 792 | image_id bigint(20) DEFAULT NULL, |
| 793 | answer_two_gap_match text, |
| 794 | answer_view_format varchar(250) DEFAULT NULL, |
| 795 | answer_settings text, |
| 796 | answer_order int(11) DEFAULT '0', |
| 797 | PRIMARY KEY (answer_id) |
| 798 | ) $charset_collate;"; |
| 799 | |
| 800 | $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings ( |
| 801 | earning_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 802 | user_id bigint(20) DEFAULT NULL, |
| 803 | course_id bigint(20) DEFAULT NULL, |
| 804 | order_id bigint(20) DEFAULT NULL, |
| 805 | order_status varchar(50) DEFAULT NULL, |
| 806 | course_price_total decimal(16,2) DEFAULT NULL, |
| 807 | course_price_grand_total decimal(16,2) DEFAULT NULL, |
| 808 | instructor_amount decimal(16,2) DEFAULT NULL, |
| 809 | instructor_rate decimal(16,2) DEFAULT NULL, |
| 810 | admin_amount decimal(16,2) DEFAULT NULL, |
| 811 | admin_rate decimal(16,2) DEFAULT NULL, |
| 812 | commission_type varchar(20) DEFAULT NULL, |
| 813 | deduct_fees_amount decimal(16,2) DEFAULT NULL, |
| 814 | deduct_fees_name varchar(250) DEFAULT NULL, |
| 815 | deduct_fees_type varchar(20) DEFAULT NULL, |
| 816 | process_by varchar(20) DEFAULT NULL, |
| 817 | created_at datetime DEFAULT NULL, |
| 818 | PRIMARY KEY (earning_id) |
| 819 | ) $charset_collate;"; |
| 820 | |
| 821 | $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws ( |
| 822 | withdraw_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 823 | user_id bigint(20) DEFAULT NULL, |
| 824 | amount decimal(16,2) DEFAULT NULL, |
| 825 | method_data text DEFAULT NULL, |
| 826 | status varchar(50) DEFAULT NULL, |
| 827 | updated_at datetime DEFAULT NULL, |
| 828 | created_at datetime DEFAULT NULL, |
| 829 | PRIMARY KEY (withdraw_id) |
| 830 | ) $charset_collate;"; |
| 831 | |
| 832 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 833 | dbDelta( $quiz_attempts_sql ); |
| 834 | dbDelta( $quiz_attempt_answers ); |
| 835 | dbDelta( $tutor_quiz_questions ); |
| 836 | dbDelta( $tutor_quiz_question_answers ); |
| 837 | dbDelta( $earning_table ); |
| 838 | dbDelta( $withdraw_table ); |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * Manage tutor roles & permission |
| 843 | * |
| 844 | * @return void |
| 845 | */ |
| 846 | public static function manage_tutor_roles_and_permissions() { |
| 847 | /** |
| 848 | * Add role for instructor |
| 849 | */ |
| 850 | $instructor_role = tutor()->instructor_role; |
| 851 | |
| 852 | remove_role( $instructor_role ); |
| 853 | add_role( $instructor_role, __( 'Tutor Instructor', 'tutor' ), array() ); |
| 854 | |
| 855 | $custom_post_type_permission = array( |
| 856 | // Manage Instructor. |
| 857 | 'manage_tutor_instructor', |
| 858 | |
| 859 | // Tutor Posts Type Permission. |
| 860 | 'edit_tutor_course', |
| 861 | 'read_tutor_course', |
| 862 | 'delete_tutor_course', |
| 863 | 'delete_tutor_courses', |
| 864 | 'edit_tutor_courses', |
| 865 | 'edit_others_tutor_courses', |
| 866 | 'read_private_tutor_courses', |
| 867 | 'edit_tutor_courses', |
| 868 | |
| 869 | 'edit_tutor_lesson', |
| 870 | 'read_tutor_lesson', |
| 871 | 'delete_tutor_lesson', |
| 872 | 'delete_tutor_lessons', |
| 873 | 'edit_tutor_lessons', |
| 874 | 'edit_others_tutor_lessons', |
| 875 | 'read_private_tutor_lessons', |
| 876 | 'edit_tutor_lessons', |
| 877 | 'publish_tutor_lessons', |
| 878 | |
| 879 | 'edit_tutor_quiz', |
| 880 | 'read_tutor_quiz', |
| 881 | 'delete_tutor_quiz', |
| 882 | 'delete_tutor_quizzes', |
| 883 | 'edit_tutor_quizzes', |
| 884 | 'edit_others_tutor_quizzes', |
| 885 | 'read_private_tutor_quizzes', |
| 886 | 'edit_tutor_quizzes', |
| 887 | 'publish_tutor_quizzes', |
| 888 | |
| 889 | 'edit_tutor_question', |
| 890 | 'read_tutor_question', |
| 891 | 'delete_tutor_question', |
| 892 | 'delete_tutor_questions', |
| 893 | 'edit_tutor_questions', |
| 894 | 'edit_others_tutor_questions', |
| 895 | 'publish_tutor_questions', |
| 896 | 'read_private_tutor_questions', |
| 897 | 'edit_tutor_questions', |
| 898 | ); |
| 899 | |
| 900 | $instructor = get_role( $instructor_role ); |
| 901 | if ( $instructor ) { |
| 902 | $instructor_cap = array( |
| 903 | 'edit_posts', |
| 904 | 'read', |
| 905 | 'upload_files', |
| 906 | ); |
| 907 | |
| 908 | $instructor_cap = array_merge( $instructor_cap, $custom_post_type_permission ); |
| 909 | |
| 910 | $can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' ); |
| 911 | if ( $can_publish_course ) { |
| 912 | $instructor_cap[] = 'publish_tutor_courses'; |
| 913 | } |
| 914 | |
| 915 | foreach ( $instructor_cap as $cap ) { |
| 916 | $instructor->add_cap( $cap ); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | $administrator = get_role( 'administrator' ); |
| 921 | if ( $administrator ) { |
| 922 | |
| 923 | $administrator_cap = array( |
| 924 | 'manage_tutor', |
| 925 | ); |
| 926 | $administrator_cap = array_merge( $administrator_cap, $custom_post_type_permission ); |
| 927 | $administrator_cap[] = 'publish_tutor_courses'; |
| 928 | |
| 929 | foreach ( $administrator_cap as $cap ) { |
| 930 | $administrator->add_cap( $cap ); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Add Instructor role to administrator |
| 936 | */ |
| 937 | if ( current_user_can( 'administrator' ) ) { |
| 938 | tutor_utils()->add_instructor_role( get_current_user_id() ); |
| 939 | } |
| 940 | |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * On plugin activate save initial data |
| 945 | * Like: generate tutor pages |
| 946 | * |
| 947 | * @since 1.0.0 |
| 948 | * |
| 949 | * @return void |
| 950 | */ |
| 951 | public static function save_data() { |
| 952 | |
| 953 | $student_dashboard_args = array( |
| 954 | 'post_title' => __( 'Dashboard', 'tutor' ), |
| 955 | 'post_content' => '', |
| 956 | 'post_type' => 'page', |
| 957 | 'post_status' => 'publish', |
| 958 | ); |
| 959 | $student_dashboard_page_id = wp_insert_post( $student_dashboard_args ); |
| 960 | tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id ); |
| 961 | |
| 962 | $student_registration_args = array( |
| 963 | 'post_title' => __( 'Student Registration', 'tutor' ), |
| 964 | 'post_content' => '[tutor_student_registration_form]', |
| 965 | 'post_type' => 'page', |
| 966 | 'post_status' => 'publish', |
| 967 | ); |
| 968 | $student_register_page_id = wp_insert_post( $student_registration_args ); |
| 969 | tutor_utils()->update_option( 'student_register_page', $student_register_page_id ); |
| 970 | |
| 971 | $instructor_registration_args = array( |
| 972 | 'post_title' => __( 'Instructor Registration', 'tutor' ), |
| 973 | 'post_content' => '[tutor_instructor_registration_form]', |
| 974 | 'post_type' => 'page', |
| 975 | 'post_status' => 'publish', |
| 976 | ); |
| 977 | $instructor_registration_id = wp_insert_post( $instructor_registration_args ); |
| 978 | tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id ); |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * Default options |
| 983 | * |
| 984 | * @since 1.0.0 |
| 985 | * |
| 986 | * @return array |
| 987 | */ |
| 988 | public static function default_options() { |
| 989 | $options = array( |
| 990 | 'pagination_per_page' => '20', |
| 991 | 'course_allow_upload_private_files' => '1', |
| 992 | 'display_course_instructors' => '1', |
| 993 | 'enable_q_and_a_on_course' => '1', |
| 994 | 'courses_col_per_row' => '3', |
| 995 | 'courses_per_page' => '12', |
| 996 | 'lesson_permalink_base' => 'lesson', |
| 997 | 'quiz_when_time_expires' => 'autosubmit', |
| 998 | 'quiz_attempts_allowed' => '10', |
| 999 | 'quiz_grade_method' => 'highest_grade', |
| 1000 | 'enable_public_profile' => '1', |
| 1001 | 'email_to_students' => |
| 1002 | array( |
| 1003 | 'quiz_completed' => '1', |
| 1004 | 'completed_course' => '1', |
| 1005 | ), |
| 1006 | 'email_to_instructors' => |
| 1007 | array( |
| 1008 | 'a_student_enrolled_in_course' => '1', |
| 1009 | 'a_student_completed_course' => '1', |
| 1010 | 'a_student_completed_lesson' => '1', |
| 1011 | 'a_student_placed_question' => '1', |
| 1012 | ), |
| 1013 | 'email_from_name' => get_option( 'blogname' ), |
| 1014 | 'email_from_address' => get_option( 'admin_email' ), |
| 1015 | 'email_footer_text' => '', |
| 1016 | 'earning_admin_commission' => '20', |
| 1017 | 'earning_admin_commission' => '20', |
| 1018 | 'earning_instructor_commission' => '80', |
| 1019 | 'color_preset_type' => 'default', |
| 1020 | ); |
| 1021 | return $options; |
| 1022 | } |
| 1023 | |
| 1024 | |
| 1025 | /** |
| 1026 | * Create withdraw database |
| 1027 | * |
| 1028 | * @since 1.2.0 |
| 1029 | */ |
| 1030 | public static function create_withdraw_database() { |
| 1031 | global $wpdb; |
| 1032 | |
| 1033 | $charset_collate = $wpdb->get_charset_collate(); |
| 1034 | |
| 1035 | /** |
| 1036 | * Table SQL |
| 1037 | * |
| 1038 | * {$wpdb->prefix}tutor_earnings |
| 1039 | * {$wpdb->prefix}tutor_withdraws |
| 1040 | * |
| 1041 | * @since 1.2.0 |
| 1042 | */ |
| 1043 | |
| 1044 | $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings ( |
| 1045 | earning_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 1046 | user_id bigint(20) DEFAULT NULL, |
| 1047 | course_id bigint(20) DEFAULT NULL, |
| 1048 | order_id bigint(20) DEFAULT NULL, |
| 1049 | order_status varchar(50) DEFAULT NULL, |
| 1050 | course_price_total decimal(16,2) DEFAULT NULL, |
| 1051 | course_price_grand_total decimal(16,2) DEFAULT NULL, |
| 1052 | instructor_amount decimal(16,2) DEFAULT NULL, |
| 1053 | instructor_rate decimal(16,2) DEFAULT NULL, |
| 1054 | admin_amount decimal(16,2) DEFAULT NULL, |
| 1055 | admin_rate decimal(16,2) DEFAULT NULL, |
| 1056 | commission_type varchar(20) DEFAULT NULL, |
| 1057 | deduct_fees_amount decimal(16,2) DEFAULT NULL, |
| 1058 | deduct_fees_name varchar(250) DEFAULT NULL, |
| 1059 | deduct_fees_type varchar(20) DEFAULT NULL, |
| 1060 | process_by varchar(20) DEFAULT NULL, |
| 1061 | created_at datetime DEFAULT NULL, |
| 1062 | PRIMARY KEY (earning_id) |
| 1063 | ) $charset_collate;"; |
| 1064 | |
| 1065 | $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws ( |
| 1066 | withdraw_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 1067 | user_id bigint(20) DEFAULT NULL, |
| 1068 | amount decimal(16,2) DEFAULT NULL, |
| 1069 | method_data text DEFAULT NULL, |
| 1070 | status varchar(50) DEFAULT NULL, |
| 1071 | updated_at datetime DEFAULT NULL, |
| 1072 | created_at datetime DEFAULT NULL, |
| 1073 | PRIMARY KEY (withdraw_id) |
| 1074 | ) $charset_collate;"; |
| 1075 | |
| 1076 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 1077 | dbDelta( $earning_table ); |
| 1078 | dbDelta( $withdraw_table ); |
| 1079 | |
| 1080 | /** |
| 1081 | * Setting previous dashboard to new dashboard |
| 1082 | */ |
| 1083 | $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' ); |
| 1084 | tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id ); |
| 1085 | } |
| 1086 | |
| 1087 | /** |
| 1088 | * Filter the wp_doing_ajax from tutor requests to get advanced |
| 1089 | * advantages from Tutor |
| 1090 | * |
| 1091 | * @since 1.3.4 |
| 1092 | * |
| 1093 | * @param bool $bool default value. |
| 1094 | * |
| 1095 | * @return bool |
| 1096 | */ |
| 1097 | public function wp_doing_ajax( $bool ) { |
| 1098 | // Don't use Input::has helper to avoid conflict. |
| 1099 | if ( isset( $_REQUEST['tutor_ajax_action'] ) ) { |
| 1100 | return true; |
| 1101 | } |
| 1102 | return $bool; |
| 1103 | } |
| 1104 | } |
| 1105 |