Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/src/js/front/pages/course-landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ window.jQuery(document).ready(($) => {
data: {
action: 'tutor_reset_course_progress',
course_id: course_id,
context: 'course-landing',
},
beforeSend: () => {
button.prop('disabled', true).addClass('is-loading');
Expand All @@ -35,7 +36,7 @@ window.jQuery(document).ready(($) => {
}
},
error: function(response) {
tutor_toast(__( 'Error', 'tutor' ),(response.responseJSON || {}).message ||__('Something went wrong', 'tutor'));
tutor_toast(__( 'Error', 'tutor' ),(response.responseJSON || {}).message ||__('Something went wrong', 'tutor'), 'error' );
},
complete: function () {
button.prop('disabled', false).removeClass('is-loading');
Expand Down
3 changes: 2 additions & 1 deletion assets/src/js/frontend/learning-area/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface CourseCompletePayload {
}
interface CourseRetakePayload {
course_id: number;
context: string;
}

/**
Expand Down Expand Up @@ -70,7 +71,7 @@ export const courseCompleteHandler = () => {
},

async handleCourseRetake(courseId: number) {
await this.courseRetakeMutation?.mutate({ course_id: courseId });
await this.courseRetakeMutation?.mutate({ course_id: courseId, context: 'learning-area' });
},
};
};
Expand Down
3 changes: 2 additions & 1 deletion assets/src/js/frontend/learning-area/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { type AxiosError } from 'axios';

interface ResetProgressPayload {
course_id: number;
context: string;
}

interface ResetProgressResponse {
Expand Down Expand Up @@ -104,7 +105,7 @@ export const sidebarComponent = ({
},

resetProgress() {
this.resetProgressMutation?.mutate({ course_id: this.courseId });
this.resetProgressMutation?.mutate({ course_id: this.courseId, context: 'learning-area-sidebar' });
},
};
};
Expand Down
8 changes: 7 additions & 1 deletion classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
global $wp_query;
$course_coming_soon_enabled = (int) get_post_meta( $content->ID, '_tutor_course_enable_coming_soon', true );
$is_instructor = tutor_utils()->is_instructor_of_this_course( get_current_user_id(), $content->ID, true );
if ( ! CourseModel::get_post_types( $content ) || current_user_can( 'administrator' ) || $is_instructor || $course_coming_soon_enabled ) {

Check failure on line 335 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found "administrator" in function call to current_user_can()
return $content;
}

Expand Down Expand Up @@ -663,7 +663,7 @@
} else {
$errors['pricing'] = __( 'Invalid product', 'tutor' );
}
} else {

Check failure on line 666 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

If control structure block found as the only statement within an "else" block. Use elseif instead.
/**
* If user does not select WC product
* Then automatic WC product will be create name with course title.
Expand Down Expand Up @@ -800,7 +800,7 @@
update_post_meta( $post_id, self::COURSE_PRICE_TYPE_META, $params['pricing']['type'] );
}
} catch ( \Throwable $th ) {
throw new \Exception( $th->getMessage() );

Check failure on line 803 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$th'.
}
}

Expand Down Expand Up @@ -2365,7 +2365,7 @@
}

// Check if user is only an instructor.
if ( ! current_user_can( 'administrator' ) ) {

Check failure on line 2368 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found "administrator" in function call to current_user_can()
// Check if instructor can trash course.
$can_trash_post = tutor_utils()->get_option( 'instructor_can_delete_course' );

Expand Down Expand Up @@ -3084,10 +3084,16 @@
public function tutor_reset_course_progress() {
tutor_utils()->checking_nonce();
$course_id = Input::post( 'course_id', 0, Input::TYPE_INT );
$context = Input::post( 'context', '' );
$course_reset_progress = tutor_utils()->get_option( 'course_reset_progress', false );
$course_retake_feature = tutor_utils()->get_option( 'course_retake_feature', false );

if ( ! $course_reset_progress || ! $course_retake_feature ) {
if ( ! $course_reset_progress && 'learning-area-sidebar' === $context ) {
$this->response_bad_request( __( 'You are not allowed to reset course progress.', 'tutor' ) );
return;
}

if ( ! $course_retake_feature && ( 'course-landing' === $context || 'learning-area' === $context ) ) {
$this->response_bad_request( __( 'You are not allowed to reset course progress.', 'tutor' ) );
return;
}
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,9 @@ public function pay_now() {
$errors,
sprintf(
// Translators: %s course name.
__( ' Course %s cannot be enrolled right now.', 'tutor' )
__( 'Course %s cannot be enrolled right now.', 'tutor' ),
get_the_title( $course_id ) ?? ''
),
get_the_title( $course_id ) ?? ''
);
}
}
Expand Down
Loading