Skip to content

Commit

Permalink
Merge pull request #756 from themeum/dev
Browse files Browse the repository at this point in the history
v2.7.0
  • Loading branch information
harunollyo authored Apr 25, 2024
2 parents 8f6aa38 + 3adbae1 commit 633957b
Show file tree
Hide file tree
Showing 45 changed files with 858 additions and 468 deletions.
10 changes: 8 additions & 2 deletions assets/react/admin-dashboard/segments/withdraw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { default: sprintf } = require("../../helper/sprintf");

document.addEventListener("DOMContentLoaded", function(){
const { __, _x, _n, _nx } = wp.i18n;
// Approve and Reject button
Expand All @@ -13,7 +15,9 @@ document.addEventListener("DOMContentLoaded", function(){
const amount = e.currentTarget.dataset.amount;
const accountName = e.currentTarget.dataset.name;
const content = document.getElementById('tutor-admin-withdraw-approve-content');
content.innerHTML = `${__( 'You are approving '+ `<strong style="color:#000;">${accountName}</strong>` + ' withdrawal request for '+ `<strong style="color:#000;">${amount}</strong>` +'. Are you sure you want to approve?', 'tutor')}`;
content.innerHTML = `${
sprintf( __( 'You are approving %s withdrawal request for %s. Are you sure you want to approve?', 'tutor'), `<strong style="color:#000;">${accountName}</strong>`, `<strong style="color:#000;">${amount}</strong>` )
}`;
}
}

Expand All @@ -26,7 +30,9 @@ document.addEventListener("DOMContentLoaded", function(){
const amount = e.currentTarget.dataset.amount;
const accountName = e.currentTarget.dataset.name;
const content = document.getElementById('tutor-admin-withdraw-reject-content');
content.innerHTML = `${__( 'You are rejecting '+ `<strong style="color:#000;">${accountName}</strong>` + ' withdrawal request for '+ `<strong style="color:#000;">${amount}</strong>` +'. Are you sure you want to reject?', 'tutor')}`;
content.innerHTML = `${
sprintf( __( 'You are rejecting %s withdrawal request for %s. Are you sure you want to reject?', 'tutor' ), `<strong style="color:#000;">${accountName}</strong>`, `<strong style="color:#000;">${amount}</strong>` )
}`;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions assets/react/front/tutor-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './dashboard/export-csv';
import './pages/course-landing';
import './pages/instructor-list-filter';
import './_select_dd_search';
import sprintf from '../helper/sprintf';
/**
* Codes from this file should be decentralized according to relavent file/folder structure.
* It's a legacy file.
Expand All @@ -22,7 +23,7 @@ readyState_complete(() => {
jQuery(document).ready(function($) {
'use strict';
/**
* wp.i18n translateable functions
* wp.i18n translatable functions
* @since 1.9.0
*/
const { __, _x, _n, _nx } = wp.i18n;
Expand Down Expand Up @@ -153,7 +154,7 @@ jQuery(document).ready(function($) {
// Disallow moving forward
if (newTime > max_seek_time) {
e.preventDefault();
tutor_toast(__('Warning', 'tutor'), __(`Forward seeking is disabled.`, 'tutor'), 'error');
tutor_toast(__('Warning', 'tutor'), __('Forward seeking is disabled', 'tutor'), 'error');
return false;
}
return true;
Expand Down Expand Up @@ -293,7 +294,7 @@ jQuery(document).ready(function($) {
if (completedPercentage < required_percentage) {
const complete_lesson_btn = $('button[name="complete_lesson_btn"]');
complete_lesson_btn.attr('disabled', true);
complete_lesson_btn.wrap('<div class="tooltip-wrap"></div>').after(`<span class="tooltip-txt tooltip-bottom">Watch at least ${video_data.required_percentage}% to complete the lesson.</span>`);
complete_lesson_btn.wrap('<div class="tooltip-wrap"></div>').after(`<span class="tooltip-txt tooltip-bottom">${ sprintf( __( 'Watch at least %s% to complete the lesson.', 'tutor' ), video_data.required_percentage ) }</span>`);
}
},
getPercentage: function(value, total) {
Expand Down
15 changes: 15 additions & 0 deletions assets/react/helper/sprintf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* sprintf helper like as php
*
* @param {string} str string
* @param {...any} args
*
* @returns string
*/
function sprintf(str, ...args) {
return str.replace(/%s/g, function () {
return args.shift();
});
}

export default sprintf;
87 changes: 0 additions & 87 deletions classes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function __construct() {
add_action( 'admin_init', array( $this, 'filter_posts_for_instructors' ) );
add_action( 'load-post.php', array( $this, 'check_if_current_users_post' ) );

add_action( 'admin_action_uninstall_tutor_and_erase', array( $this, 'erase_tutor_data' ) );
add_filter( 'plugin_action_links_' . plugin_basename( TUTOR_FILE ), array( $this, 'plugin_action_links' ) );

// Plugin Row Meta.
Expand Down Expand Up @@ -456,92 +455,6 @@ public static function template_overridden_files() {
return $override_files;
}

/**
* Erase tutor data
*
* @since 1.0.0
* @return void
*/
public function erase_tutor_data() {
global $wpdb;

$is_erase_data = tutor_utils()->get_option( 'delete_on_uninstall' );
// Deleting Data.

$plugin_file = tutor()->basename;
if ( $is_erase_data && current_user_can( 'deactivate_plugin', $plugin_file ) ) {
/**
* 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',
);

$post_type_strings = "'" . implode( "','", $post_types ) . "'";
$tutor_posts = $wpdb->get_col( "SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;" ); //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, 'course-category' );
foreach ( $terms as $term ) {
wp_remove_object_terms( $post_id, array( $term->term_id ), 'course-category' );
}

// Delete tags if available.
$terms = wp_get_object_terms( $post_id, 'course-tag' );
foreach ( $terms as $term ) {
wp_remove_object_terms( $post_id, array( $term->term_id ), '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' ;" );
$comments_ids_strings = "'" . implode( "','", $tutor_comments ) . "'";
if ( is_array( $tutor_comments ) && count( $tutor_comments ) ) {
$wpdb->query( "DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) " ); //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 " );

deactivate_plugins( $plugin_file );
}

wp_redirect( 'plugins.php' );
die();
}

/**
* Plugin activation link
*
Expand Down
Loading

0 comments on commit 633957b

Please sign in to comment.