PluginProbe
Tutor LMS – eLearning and online course solution / 3.9.2
Tutor LMS – eLearning and online course solution v3.9.2
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 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 All 191 releases
← All changes | classes/Tutor.php +29 -98 trunk3.9.2 View file →
@@ -3,9 +3,9 @@
3 3 * Initialize all the dependency classes
4 4 *
5 5 * @package Tutor
6 6 * @author Themeum <support@themeum.com>
7 - * @link https://www.themeum.com/
7 + * @link https://themeum.com
8 8 * @since 1.0.0
9 9 */
10 10
11 11 namespace TUTOR;
@@ -11,11 +11,10 @@
11 11 namespace TUTOR;
12 12
13 13 use Tutor\Models\CourseModel;
14 14 use Tutor\Ecommerce\Ecommerce;
15 -use Tutor\GDPR\GDPR;
16 -use Tutor\Helpers\QueryHelper;
17 15 use Tutor\Migrations\Migration;
16 +use Tutor\TemplateImport\TemplateImportInit;
18 17
19 18 if ( ! defined( 'ABSPATH' ) ) {
20 19 exit;
21 20 }
@@ -25,9 +24,8 @@
25 24 *
26 25 * @since 1.0.0
27 26 */
28 27 final class Tutor extends Singleton {
29 -
30 28 /**
31 29 * Tutor version
32 30 *
33 31 * @since 1.0.0
@@ -234,17 +232,8 @@
234 232 */
235 233 private $user;
236 234
237 235 /**
238 - * UserPreference class object
239 - *
240 - * @since 4.0.0
241 - *
242 - * @var UserPreference
243 - */
244 - private $user_preference;
245 -
246 - /**
247 236 * Theme_Compatibility class object
248 237 *
249 238 * @since 1.1.0
250 239 *
@@ -485,10 +474,8 @@
485 474 $this->includes();
486 475
487 476 do_action( 'tutor_before_load' );
488 477
489 - GDPR::get_instance();
490 -
491 478 $this->addons = new Addons();
492 479 $this->post_types = new Post_types();
493 480 $this->taxonomies = new Taxonomies();
494 481 $this->assets = new Assets();
@@ -507,9 +494,8 @@
507 494 $this->q_attempt = new Quiz_Attempts_List();
508 495 $this->quiz = new Quiz();
509 496 $this->tools = new Tools();
510 497 $this->user = new User();
511 - $this->user_preference = new UserPreference();
512 498 $this->theme_compatibility = new Theme_Compatibility();
513 499 $this->gutenberg = new Gutenberg();
514 500 $this->course_settings_tabs = new Course_Settings_Tabs();
515 501 $this->withdraw = new Withdraw();
@@ -522,8 +508,11 @@
522 508 $this->private_course_access = new Private_Course_Access();
523 509 $this->course_filter = new Course_Filter();
524 510 $this->permalink = new Permalink();
525 511
512 + // Template import.
513 + new TemplateImportInit();
514 +
526 515 // Integrations.
527 516 $this->woocommerce = new WooCommerce();
528 517 $this->edd = new TutorEDD();
529 518
@@ -571,9 +560,8 @@
571 560
572 561 do_action( 'tutor_loaded' );
573 562
574 563 add_action( 'init', array( $this, 'init_action' ) );
575 - add_action( 'init', array( $this, 'update_instructor_capability' ) );
576 564
577 565 /**
578 566 * Check activated plugin
579 567 *
@@ -587,10 +575,8 @@
587 575 *
588 576 * @since 2.8.0
589 577 */
590 578 add_action( 'admin_init', array( $this, 'redirect_to_setup_page' ) );
591 -
592 - // add_filter( 'rest_request_before_callbacks', array( $this, 'enforce_courses_privacy_rest_api' ), 10, 3 );
593 579 }
594 580
595 581 /**
596 582 * Check activated plugin
@@ -646,22 +632,12 @@
646 632 if ( ! function_exists( 'is_plugin_active' ) ) {
647 633 require_once ABSPATH . 'wp-admin/includes/plugin.php';
648 634 }
649 635
650 - // Only kirki latest has class KirkiMain.
651 - $is_kirki_active = \is_plugin_active( 'kirki-pro/kirki-pro.php' ) && class_exists( 'KirkiProMain' );
652 -
653 - if ( $is_kirki_active ) {
654 - $tutor_kirki_path = $tutor_path . 'includes/kirki/kirki.php';
655 - if ( file_exists( $tutor_kirki_path ) ) {
656 - include $tutor_kirki_path;
657 - }
658 - } else {
659 - $is_droip_active = \is_plugin_active( 'droip/droip.php' );
660 - $tutor_droip_path = $tutor_path . 'includes/droip/droip.php';
661 - if ( $is_droip_active && file_exists( $tutor_droip_path ) ) {
662 - include $tutor_droip_path;
663 - }
636 + $is_droip_active = \is_plugin_active( 'droip/droip.php' );
637 + $tutor_droip_path = $tutor_path . 'includes/droip/droip.php';
638 + if ( $is_droip_active && file_exists( $tutor_droip_path ) ) {
639 + include $tutor_droip_path;
664 640 }
665 641 }
666 642
667 643 /**
@@ -687,15 +663,10 @@
687 663 }
688 664
689 665 /**
690 666 * Do some task during plugin activation
691 - *
692 - * @since 4.0.0 Flush rewrite rules on activation.
693 667 */
694 668 public static function tutor_activate() {
695 - // Rewrite Flush.
696 - Permalink::set_permalink_flag();
697 -
698 669 $version = get_option( 'tutor_version' );
699 670 if ( ! function_exists( 'tutor_time' ) ) {
700 671 include tutor()->path . 'includes/tutor-general-functions.php';
701 672 }
@@ -708,8 +679,10 @@
708 679
709 680 $options = self::default_options();
710 681 update_option( 'tutor_option', $options );
711 682
683 + // Rewrite Flush.
684 + Permalink::set_permalink_flag();
712 685 self::manage_tutor_roles_and_permissions();
713 686
714 687 // Save initial Page.
715 688 self::save_data();
@@ -730,8 +703,10 @@
730 703 */
731 704 self::create_withdraw_database();
732 705 // Update the tutor version.
733 706 update_option( 'tutor_version', '1.2.0' );
707 + // Rewrite Flush.
708 + Permalink::set_permalink_flag();
734 709 }
735 710
736 711 /**
737 712 * Backward Compatibility to < 1.3.1 for make course plural
@@ -742,8 +717,9 @@
742 717 if ( ! get_option( 'is_course_post_type_updated' ) ) {
743 718 $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) );
744 719 update_option( 'is_course_post_type_updated', true );
745 720 update_option( 'tutor_version', '1.3.1' );
721 + Permalink::set_permalink_flag();
746 722 }
747 723 }
748 724
749 725 /**
@@ -1082,8 +1058,10 @@
1082 1058 'read_tutor_course',
1083 1059 'delete_tutor_course',
1084 1060 'delete_tutor_courses',
1085 1061 'edit_tutor_courses',
1062 + 'edit_others_tutor_courses',
1063 + 'read_private_tutor_courses',
1086 1064 'edit_tutor_courses',
1087 1065
1088 1066 'edit_tutor_lesson',
1089 1067 'read_tutor_lesson',
@@ -1089,8 +1067,10 @@
1089 1067 'read_tutor_lesson',
1090 1068 'delete_tutor_lesson',
1091 1069 'delete_tutor_lessons',
1092 1070 'edit_tutor_lessons',
1071 + 'edit_others_tutor_lessons',
1072 + 'read_private_tutor_lessons',
1093 1073 'edit_tutor_lessons',
1094 1074 'publish_tutor_lessons',
1095 1075
1096 1076 'edit_tutor_quiz',
@@ -1097,8 +1077,10 @@
1097 1077 'read_tutor_quiz',
1098 1078 'delete_tutor_quiz',
1099 1079 'delete_tutor_quizzes',
1100 1080 'edit_tutor_quizzes',
1081 + 'edit_others_tutor_quizzes',
1082 + 'read_private_tutor_quizzes',
1101 1083 'edit_tutor_quizzes',
1102 1084 'publish_tutor_quizzes',
1103 1085
1104 1086 'edit_tutor_question',
@@ -1105,9 +1087,11 @@
1105 1087 'read_tutor_question',
1106 1088 'delete_tutor_question',
1107 1089 'delete_tutor_questions',
1108 1090 'edit_tutor_questions',
1091 + 'edit_others_tutor_questions',
1109 1092 'publish_tutor_questions',
1093 + 'read_private_tutor_questions',
1110 1094 'edit_tutor_questions',
1111 1095 );
1112 1096
1113 1097 $instructor = get_role( $instructor_role );
@@ -1209,8 +1193,9 @@
1209 1193 'courses_per_page' => '12',
1210 1194 'course_permalink_base' => 'courses',
1211 1195 'lesson_permalink_base' => 'lessons',
1212 1196 'quiz_when_time_expires' => 'autosubmit',
1197 + 'quiz_attempts_allowed' => '10',
1213 1198 'quiz_grade_method' => 'highest_grade',
1214 1199 'enable_public_profile' => '1',
1215 1200 'email_to_students' =>
1216 1201 array(
@@ -1228,8 +1213,9 @@
1228 1213 'email_from_address' => get_option( 'admin_email' ),
1229 1214 'email_footer_text' => '',
1230 1215 'earning_admin_commission' => '20',
1231 1216 'earning_instructor_commission' => '80',
1217 + 'color_preset_type' => 'default',
1232 1218
1233 1219 // Default options for tutor ecommerce.
1234 1220 'monetize_by' => Ecommerce::MONETIZE_BY,
1235 1221 'currency_code' => 'USD',
@@ -1372,10 +1358,10 @@
1372 1358 'tutor_enrolled',
1373 1359 'tutor_announcements',
1374 1360 );
1375 1361
1376 - $in_clause = QueryHelper::prepare_in_clause( $post_types );
1377 - $tutor_posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID from {$wpdb->posts} WHERE post_type IN({$in_clause}) ;" ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1362 + $post_type_strings = "'" . implode( "','", $post_types ) . "'";
1363 + $tutor_posts = $wpdb->get_col( "SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;" ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1378 1364
1379 1365 if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) {
1380 1366 foreach ( $tutor_posts as $post_id ) {
1381 1367 // Delete categories.
@@ -1398,12 +1384,12 @@
1398 1384
1399 1385 /**
1400 1386 * Deleting Comments (reviews, questions, quiz_answers, etc)
1401 1387 */
1402 - $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" );
1388 + $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" );
1389 + $comments_ids_strings = "'" . implode( "','", $tutor_comments ) . "'";
1403 1390 if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) {
1404 - $in_clause = QueryHelper::prepare_in_clause( $tutor_comments );
1405 - $wpdb->query( $wpdb->prepare( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$in_clause}) " ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1391 + $wpdb->query( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) " ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1406 1392 }
1407 1393 $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) );
1408 1394
1409 1395 /**
@@ -1421,62 +1407,7 @@
1421 1407 $prefix = $wpdb->prefix;
1422 1408 //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1423 1409 $wpdb->query( "DROP TABLE IF EXISTS {$prefix}tutor_quiz_attempts, {$prefix}tutor_quiz_attempt_answers, {$prefix}tutor_quiz_questions, {$prefix}tutor_quiz_question_answers, {$prefix}tutor_earnings, {$prefix}tutor_withdraws " );
1424 1410
1425 - }
1426 - }
1427 -
1428 - /**
1429 - * Update instructor capability
1430 - *
1431 - * Remove other author items permission
1432 - *
1433 - * @since 4.0.5
1434 - *
1435 - * @since 4.0.6 read_private_{items} permissions removed
1436 - */
1437 - public function update_instructor_capability() {
1438 - // Remove edit_others content cap from tutor_instructor role.
1439 - $is_removed_edit_other_items_permissions = get_option( 'tutor_removed_edit_other_items_permission', false );
1440 - $is_removed_private_items_permissions = get_option( 'tutor_removed_read_private_items_permission', false );
1441 -
1442 - $role = get_role( tutor()->instructor_role );
1443 - if ( ! $is_removed_edit_other_items_permissions ) {
1444 - $role = get_role( tutor()->instructor_role );
1445 -
1446 - $caps_to_be_removed = array(
1447 - 'edit_others_tutor_courses',
1448 - 'edit_others_tutor_lessons',
1449 - 'edit_others_tutor_quizzes',
1450 - 'edit_others_tutor_questions',
1451 - 'edit_others_tutor_assignments',
1452 - );
1453 -
1454 - foreach ( $caps_to_be_removed as $cap ) {
1455 - if ( $role->has_cap( $cap ) ) {
1456 - $role->remove_cap( $cap );
1457 - }
1458 - }
1459 -
1460 - update_option( 'tutor_removed_edit_other_items_permission', true, false );
1461 - }
1462 -
1463 - // Removed private items permission @since 4.0.6.
1464 - if ( ! $is_removed_private_items_permissions ) {
1465 - $caps_to_be_removed = array(
1466 - 'read_private_tutor_courses',
1467 - 'read_private_tutor_lessons',
1468 - 'read_private_tutor_quizzes',
1469 - 'read_private_tutor_assignments',
1470 - 'read_private_tutor_questions',
1471 - );
1472 -
1473 - foreach ( $caps_to_be_removed as $cap ) {
1474 - if ( $role->has_cap( $cap ) ) {
1475 - $role->remove_cap( $cap );
1476 - }
1477 - }
1478 -
1479 - update_option( 'tutor_removed_read_private_items_permission', true, false );
1480 1411 }
1481 1412 }
1482 1413 }