| @@ -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,10 +11,8 @@ | ||
| 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; |
| 18 | 16 | |
| 19 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | 18 | exit; |
| @@ -25,9 +23,8 @@ | ||
| 25 | 23 | * |
| 26 | 24 | * @since 1.0.0 |
| 27 | 25 | */ |
| 28 | 26 | final class Tutor extends Singleton { |
| 29 | - | |
| 30 | 27 | /** |
| 31 | 28 | * Tutor version |
| 32 | 29 | * |
| 33 | 30 | * @since 1.0.0 |
| @@ -234,17 +231,8 @@ | ||
| 234 | 231 | */ |
| 235 | 232 | private $user; |
| 236 | 233 | |
| 237 | 234 | /** |
| 238 | - * UserPreference class object | |
| 239 | - * | |
| 240 | - * @since 4.0.0 | |
| 241 | - * | |
| 242 | - * @var UserPreference | |
| 243 | - */ | |
| 244 | - private $user_preference; | |
| 245 | - | |
| 246 | - /** | |
| 247 | 235 | * Theme_Compatibility class object |
| 248 | 236 | * |
| 249 | 237 | * @since 1.1.0 |
| 250 | 238 | * |
| @@ -485,10 +473,8 @@ | ||
| 485 | 473 | $this->includes(); |
| 486 | 474 | |
| 487 | 475 | do_action( 'tutor_before_load' ); |
| 488 | 476 | |
| 489 | - GDPR::get_instance(); | |
| 490 | - | |
| 491 | 477 | $this->addons = new Addons(); |
| 492 | 478 | $this->post_types = new Post_types(); |
| 493 | 479 | $this->taxonomies = new Taxonomies(); |
| 494 | 480 | $this->assets = new Assets(); |
| @@ -507,9 +493,8 @@ | ||
| 507 | 493 | $this->q_attempt = new Quiz_Attempts_List(); |
| 508 | 494 | $this->quiz = new Quiz(); |
| 509 | 495 | $this->tools = new Tools(); |
| 510 | 496 | $this->user = new User(); |
| 511 | - $this->user_preference = new UserPreference(); | |
| 512 | 497 | $this->theme_compatibility = new Theme_Compatibility(); |
| 513 | 498 | $this->gutenberg = new Gutenberg(); |
| 514 | 499 | $this->course_settings_tabs = new Course_Settings_Tabs(); |
| 515 | 500 | $this->withdraw = new Withdraw(); |
| @@ -571,9 +556,8 @@ | ||
| 571 | 556 | |
| 572 | 557 | do_action( 'tutor_loaded' ); |
| 573 | 558 | |
| 574 | 559 | add_action( 'init', array( $this, 'init_action' ) ); |
| 575 | - add_action( 'init', array( $this, 'update_instructor_capability' ) ); | |
| 576 | 560 | |
| 577 | 561 | /** |
| 578 | 562 | * Check activated plugin |
| 579 | 563 | * |
| @@ -587,10 +571,8 @@ | ||
| 587 | 571 | * |
| 588 | 572 | * @since 2.8.0 |
| 589 | 573 | */ |
| 590 | 574 | 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 | 575 | } |
| 594 | 576 | |
| 595 | 577 | /** |
| 596 | 578 | * Check activated plugin |
| @@ -618,12 +600,9 @@ | ||
| 618 | 600 | public function redirect_to_setup_page() { |
| 619 | 601 | if ( ( ! get_option( 'tutor_wizard' ) ) && version_compare( TUTOR_VERSION, '1.5.6', '>' ) ) { |
| 620 | 602 | if ( ! wp_doing_ajax() ) { |
| 621 | 603 | update_option( 'tutor_wizard', 'active' ); |
| 622 | - $is_wp_cli = defined( 'WP_CLI' ) && WP_CLI; | |
| 623 | - if ( ! $is_wp_cli ) { | |
| 624 | - wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) ); | |
| 625 | - } | |
| 604 | + wp_safe_redirect( admin_url( 'admin.php?page=tutor-setup' ) ); | |
| 626 | 605 | exit; |
| 627 | 606 | } |
| 628 | 607 | } |
| 629 | 608 | } |
| @@ -646,22 +625,12 @@ | ||
| 646 | 625 | if ( ! function_exists( 'is_plugin_active' ) ) { |
| 647 | 626 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 648 | 627 | } |
| 649 | 628 | |
| 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 | - } | |
| 629 | + $is_droip_active = \is_plugin_active( 'droip/droip.php' ); | |
| 630 | + $tutor_droip_path = $tutor_path . 'includes/droip/droip.php'; | |
| 631 | + if ( $is_droip_active && file_exists( $tutor_droip_path ) ) { | |
| 632 | + include $tutor_droip_path; | |
| 664 | 633 | } |
| 665 | 634 | } |
| 666 | 635 | |
| 667 | 636 | /** |
| @@ -687,15 +656,10 @@ | ||
| 687 | 656 | } |
| 688 | 657 | |
| 689 | 658 | /** |
| 690 | 659 | * Do some task during plugin activation |
| 691 | - * | |
| 692 | - * @since 4.0.0 Flush rewrite rules on activation. | |
| 693 | 660 | */ |
| 694 | 661 | public static function tutor_activate() { |
| 695 | - // Rewrite Flush. | |
| 696 | - Permalink::set_permalink_flag(); | |
| 697 | - | |
| 698 | 662 | $version = get_option( 'tutor_version' ); |
| 699 | 663 | if ( ! function_exists( 'tutor_time' ) ) { |
| 700 | 664 | include tutor()->path . 'includes/tutor-general-functions.php'; |
| 701 | 665 | } |
| @@ -708,8 +672,10 @@ | ||
| 708 | 672 | |
| 709 | 673 | $options = self::default_options(); |
| 710 | 674 | update_option( 'tutor_option', $options ); |
| 711 | 675 | |
| 676 | + // Rewrite Flush. | |
| 677 | + Permalink::set_permalink_flag(); | |
| 712 | 678 | self::manage_tutor_roles_and_permissions(); |
| 713 | 679 | |
| 714 | 680 | // Save initial Page. |
| 715 | 681 | self::save_data(); |
| @@ -730,8 +696,10 @@ | ||
| 730 | 696 | */ |
| 731 | 697 | self::create_withdraw_database(); |
| 732 | 698 | // Update the tutor version. |
| 733 | 699 | update_option( 'tutor_version', '1.2.0' ); |
| 700 | + // Rewrite Flush. | |
| 701 | + Permalink::set_permalink_flag(); | |
| 734 | 702 | } |
| 735 | 703 | |
| 736 | 704 | /** |
| 737 | 705 | * Backward Compatibility to < 1.3.1 for make course plural |
| @@ -742,8 +710,9 @@ | ||
| 742 | 710 | if ( ! get_option( 'is_course_post_type_updated' ) ) { |
| 743 | 711 | $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) ); |
| 744 | 712 | update_option( 'is_course_post_type_updated', true ); |
| 745 | 713 | update_option( 'tutor_version', '1.3.1' ); |
| 714 | + Permalink::set_permalink_flag(); | |
| 746 | 715 | } |
| 747 | 716 | } |
| 748 | 717 | |
| 749 | 718 | /** |
| @@ -1082,8 +1051,10 @@ | ||
| 1082 | 1051 | 'read_tutor_course', |
| 1083 | 1052 | 'delete_tutor_course', |
| 1084 | 1053 | 'delete_tutor_courses', |
| 1085 | 1054 | 'edit_tutor_courses', |
| 1055 | + 'edit_others_tutor_courses', | |
| 1056 | + 'read_private_tutor_courses', | |
| 1086 | 1057 | 'edit_tutor_courses', |
| 1087 | 1058 | |
| 1088 | 1059 | 'edit_tutor_lesson', |
| 1089 | 1060 | 'read_tutor_lesson', |
| @@ -1089,8 +1060,10 @@ | ||
| 1089 | 1060 | 'read_tutor_lesson', |
| 1090 | 1061 | 'delete_tutor_lesson', |
| 1091 | 1062 | 'delete_tutor_lessons', |
| 1092 | 1063 | 'edit_tutor_lessons', |
| 1064 | + 'edit_others_tutor_lessons', | |
| 1065 | + 'read_private_tutor_lessons', | |
| 1093 | 1066 | 'edit_tutor_lessons', |
| 1094 | 1067 | 'publish_tutor_lessons', |
| 1095 | 1068 | |
| 1096 | 1069 | 'edit_tutor_quiz', |
| @@ -1097,8 +1070,10 @@ | ||
| 1097 | 1070 | 'read_tutor_quiz', |
| 1098 | 1071 | 'delete_tutor_quiz', |
| 1099 | 1072 | 'delete_tutor_quizzes', |
| 1100 | 1073 | 'edit_tutor_quizzes', |
| 1074 | + 'edit_others_tutor_quizzes', | |
| 1075 | + 'read_private_tutor_quizzes', | |
| 1101 | 1076 | 'edit_tutor_quizzes', |
| 1102 | 1077 | 'publish_tutor_quizzes', |
| 1103 | 1078 | |
| 1104 | 1079 | 'edit_tutor_question', |
| @@ -1105,9 +1080,11 @@ | ||
| 1105 | 1080 | 'read_tutor_question', |
| 1106 | 1081 | 'delete_tutor_question', |
| 1107 | 1082 | 'delete_tutor_questions', |
| 1108 | 1083 | 'edit_tutor_questions', |
| 1084 | + 'edit_others_tutor_questions', | |
| 1109 | 1085 | 'publish_tutor_questions', |
| 1086 | + 'read_private_tutor_questions', | |
| 1110 | 1087 | 'edit_tutor_questions', |
| 1111 | 1088 | ); |
| 1112 | 1089 | |
| 1113 | 1090 | $instructor = get_role( $instructor_role ); |
| @@ -1209,8 +1186,9 @@ | ||
| 1209 | 1186 | 'courses_per_page' => '12', |
| 1210 | 1187 | 'course_permalink_base' => 'courses', |
| 1211 | 1188 | 'lesson_permalink_base' => 'lessons', |
| 1212 | 1189 | 'quiz_when_time_expires' => 'autosubmit', |
| 1190 | + 'quiz_attempts_allowed' => '10', | |
| 1213 | 1191 | 'quiz_grade_method' => 'highest_grade', |
| 1214 | 1192 | 'enable_public_profile' => '1', |
| 1215 | 1193 | 'email_to_students' => |
| 1216 | 1194 | array( |
| @@ -1228,8 +1206,9 @@ | ||
| 1228 | 1206 | 'email_from_address' => get_option( 'admin_email' ), |
| 1229 | 1207 | 'email_footer_text' => '', |
| 1230 | 1208 | 'earning_admin_commission' => '20', |
| 1231 | 1209 | 'earning_instructor_commission' => '80', |
| 1210 | + 'color_preset_type' => 'default', | |
| 1232 | 1211 | |
| 1233 | 1212 | // Default options for tutor ecommerce. |
| 1234 | 1213 | 'monetize_by' => Ecommerce::MONETIZE_BY, |
| 1235 | 1214 | 'currency_code' => 'USD', |
| @@ -1372,10 +1351,10 @@ | ||
| 1372 | 1351 | 'tutor_enrolled', |
| 1373 | 1352 | 'tutor_announcements', |
| 1374 | 1353 | ); |
| 1375 | 1354 | |
| 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 | |
| 1355 | + $post_type_strings = "'" . implode( "','", $post_types ) . "'"; | |
| 1356 | + $tutor_posts = $wpdb->get_col( "SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;" ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared | |
| 1378 | 1357 | |
| 1379 | 1358 | if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) { |
| 1380 | 1359 | foreach ( $tutor_posts as $post_id ) { |
| 1381 | 1360 | // Delete categories. |
| @@ -1398,12 +1377,12 @@ | ||
| 1398 | 1377 | |
| 1399 | 1378 | /** |
| 1400 | 1379 | * Deleting Comments (reviews, questions, quiz_answers, etc) |
| 1401 | 1380 | */ |
| 1402 | - $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" ); | |
| 1381 | + $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" ); | |
| 1382 | + $comments_ids_strings = "'" . implode( "','", $tutor_comments ) . "'"; | |
| 1403 | 1383 | 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 | |
| 1384 | + $wpdb->query( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) " ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared | |
| 1406 | 1385 | } |
| 1407 | 1386 | $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) ); |
| 1408 | 1387 | |
| 1409 | 1388 | /** |
| @@ -1421,62 +1400,7 @@ | ||
| 1421 | 1400 | $prefix = $wpdb->prefix; |
| 1422 | 1401 | //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 1423 | 1402 | $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 | 1403 | |
| 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 | 1404 | } |
| 1481 | 1405 | } |
| 1482 | 1406 | } |