' => 'page', 'post_status' => 'publish', ); $student_dashboard_page_id = wp_insert_post( $student_dashboard_args ); tutor_utils()->update_option( 'tutor_dashboard_page_id', $student_dashboard_page_id ); $student_registration_args = array( 'post_title' => __( 'Student Registration', 'tutor' ), 'post_content' => '[tutor_student_registration_form]', 'post_type' => 'page', 'post_status' => 'publish', ); $student_register_page_id = wp_insert_post( $student_registration_args ); tutor_utils()->update_option( 'student_register_page', $student_register_page_id ); $instructor_registration_args = array( 'post_title' => __( 'Instructor Registration', 'tutor' ), 'post_content' => '[tutor_instructor_registration_form]', 'post_type' => 'page', 'post_status' => 'publish', ); $instructor_registration_id = wp_insert_post( $instructor_registration_args ); tutor_utils()->update_option( 'instructor_register_page', $instructor_registration_id ); } /** * Default options * * @since 1.0.0 * * @since 3.4.1 Supported video sources added * * @return array */ public static function default_options() { $options = array( 'pagination_per_page' => '20', 'course_allow_upload_private_files' => '1', 'display_course_instructors' => '1', 'enable_q_and_a_on_course' => '1', 'courses_col_per_row' => '3', 'courses_per_page' => '12', 'course_permalink_base' => 'courses', 'lesson_permalink_base' => 'lessons', 'quiz_when_time_expires' => 'autosubmit', 'quiz_attempts_allowed' => '10', 'quiz_grade_method' => 'highest_grade', 'enable_public_profile' => '1', 'email_to_students' => array( 'quiz_completed' => '1', 'completed_course' => '1', ), 'email_to_instructors' => array( 'a_student_enrolled_in_course' => '1', 'a_student_completed_course' => '1', 'a_student_completed_lesson' => '1', 'a_student_placed_question' => '1', ), 'email_from_name' => get_option( 'blogname' ), 'email_from_address' => get_option( 'admin_email' ), 'email_footer_text' => '', 'earning_admin_commission' => '20', 'earning_instructor_commission' => '80', 'color_preset_type' => 'default', // Default options for tutor ecommerce. 'monetize_by' => Ecommerce::MONETIZE_BY, 'currency_code' => 'USD', 'currency_position' => 'left', 'thousand_separator' => ',', 'decimal_separator' => '.', 'number_of_decimals' => '2', 'is_coupon_applicable' => 'on', 'supported_video_sources' => array( 'html5', 'external_url', 'youtube', 'vimeo', 'embedded', 'shortcode', ), ); return $options; } /** * Create withdraw database * * @since 1.2.0 */ public static function create_withdraw_database() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); /** * Table SQL * * {$wpdb->prefix}tutor_earnings * {$wpdb->prefix}tutor_withdraws * * @since 1.2.0 */ $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings ( earning_id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) DEFAULT NULL, course_id bigint(20) DEFAULT NULL, order_id bigint(20) DEFAULT NULL, order_status varchar(50) DEFAULT NULL, course_price_total decimal(16,2) DEFAULT NULL, course_price_grand_total decimal(16,2) DEFAULT NULL, instructor_amount decimal(16,2) DEFAULT NULL, instructor_rate decimal(16,2) DEFAULT NULL, admin_amount decimal(16,2) DEFAULT NULL, admin_rate decimal(16,2) DEFAULT NULL, commission_type varchar(20) DEFAULT NULL, deduct_fees_amount decimal(16,2) DEFAULT NULL, deduct_fees_name varchar(250) DEFAULT NULL, deduct_fees_type varchar(20) DEFAULT NULL, process_by varchar(20) DEFAULT NULL, created_at datetime DEFAULT NULL, PRIMARY KEY (earning_id) ) $charset_collate;"; $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws ( withdraw_id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) DEFAULT NULL, amount decimal(16,2) DEFAULT NULL, method_data text DEFAULT NULL, status varchar(50) DEFAULT NULL, updated_at datetime DEFAULT NULL, created_at datetime DEFAULT NULL, PRIMARY KEY (withdraw_id) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $earning_table ); dbDelta( $withdraw_table ); /** * Setting previous dashboard to new dashboard */ $previous_dashboard_page_id = (int) tutor_utils()->get_option( 'student_dashboard' ); tutor_utils()->update_option( 'tutor_dashboard_page_id', $previous_dashboard_page_id ); } /** * Filter the wp_doing_ajax from tutor requests to get advanced * advantages from Tutor * * @since 1.3.4 * * @param bool $bool default value. * * @return bool */ public function wp_doing_ajax( $bool ) { // Don't use Input::has helper to avoid conflict. if ( isset( $_REQUEST['tutor_ajax_action'] ) ) { return true; } return $bool; } /** * Handle plugin un-installation * * @since 2.6.2 * * @return void */ public static function tutor_uninstall() { self::erase_tutor_data(); } /** * Erase tutor data * * @since 2.6.2 * * @return void */ public static function erase_tutor_data() { global $wpdb; $is_erase_data = tutor_utils()->get_option( 'delete_on_uninstall' ); // Deleting Data. if ( $is_erase_data ) { /** * Deleting Post Type, Meta Data, taxonomy */ $course_post_type = tutor()->course_post_type; $lesson_post_type = tutor()->lesson_post_type; $post_types = array( $course_post_type, $lesson_post_type, 'tutor_quiz', 'tutor_enrolled', 'topics', 'tutor_enrolled', 'tutor_announcements', ); $in_clause = QueryHelper::prepare_in_clause( $post_types ); $tutor_posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID from {$wpdb->posts} WHERE post_type IN({$in_clause}) ;" ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared if ( is_array( $tutor_posts ) && count( $tutor_posts ) ) { foreach ( $tutor_posts as $post_id ) { // Delete categories. $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_CATEGORY ); foreach ( $terms as $term ) { wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_CATEGORY ); } // Delete tags if available. $terms = wp_get_object_terms( $post_id, CourseModel::COURSE_TAG ); foreach ( $terms as $term ) { wp_remove_object_terms( $post_id, array( $term->term_id ), CourseModel::COURSE_TAG ); } // Delete All Meta. $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $post_id ) ); $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); } } /** * Deleting Comments (reviews, questions, quiz_answers, etc) */ $tutor_comments = $wpdb->get_col( "SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;" ); if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) { $in_clause = QueryHelper::prepare_in_clause( $tutor_comments ); $wpdb->query( $wpdb->prepare( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$in_clause}) " ) ); //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } $wpdb->delete( $wpdb->comments, array( 'comment_agent' => 'comment_agent' ) ); /** * Delete Options */ delete_option( 'tutor_option' ); $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_student' ) ); $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_approved' ) ); $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_tutor_instructor_status' ) ); $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => '_is_tutor_instructor' ) ); $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_tutor_completed_lesson_id_%' " ); // Deleting Table. $prefix = $wpdb->prefix; //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $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 " ); } } }