Skip to content
Open
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
24 changes: 24 additions & 0 deletions classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@

add_filter( 'template_include', array( $this, 'handle_password_protected' ) );
add_action( 'login_form_postpass', array( $this, 'handle_password_submit' ) );
add_filter( 'post_password_required', array( $this, 'bypass_password_for_enrolled' ), 10, 2 );
add_filter( 'the_preview', array( $this, 'handle_schedule_courses' ) );
}

Expand All @@ -315,7 +316,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 319 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 All @@ -342,6 +343,29 @@
}
}

/**
* Bypass password protection for enrolled users.
*
* @since 3.0.0
*
* @param bool $required Whether the password is required.
* @param WP_Post $post The post object.
*
* @return bool false if the current user is enrolled, original value otherwise.
*/
public function bypass_password_for_enrolled( $required, $post ) {
if ( ! $required ) {
return $required;
}

$post_types = array( tutor()->course_post_type, tutor()->bundle_post_type );
if ( in_array( $post->post_type, $post_types, true ) && tutor_utils()->is_enrolled( $post->ID ) ) {
return false;
}

return $required;
}

/**
* Handle password protected course/bundle.
*
Expand Down Expand Up @@ -623,7 +647,7 @@
} else {
$errors['pricing'] = __( 'Invalid product', 'tutor' );
}
} else {

Check failure on line 650 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 @@ -760,7 +784,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 787 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 @@ -2265,7 +2289,7 @@
}

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

Check failure on line 2292 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 @@ -2309,7 +2333,7 @@
/**
* Only admin can change main author
*/
if ( $courses_post_type === $post_type && ! current_user_can( 'administrator' ) ) {

Check failure on line 2336 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()
global $wpdb;
$post_ID = (int) tutor_utils()->avalue_dot( 'ID', $postarr );
$post_author = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_author FROM {$wpdb->posts} WHERE ID = %d ", $post_ID ) );
Expand Down
2 changes: 1 addition & 1 deletion templates/single/password-protected.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<?php ( isset( $is_enrolled ) && $is_enrolled ) ? tutor_course_enrolled_lead_info() : tutor_course_lead_info(); ?>
<?php tutor_utils()->has_video_in_single() ? tutor_course_video() : get_tutor_course_thumbnail(); ?>

<div id="tutor-password-protected-modal" class="tutor-modal tutor-is-active" role="dialog" aria-modal="true" aria-labelledby="tutor-password-protected-title" aria-hidden="false">
<div id="tutor-password-protected-modal" class="tutor-modal tutor-is-active" role="dialog" aria-modal="true" aria-labelledby="tutor-password-protected-title" aria-hidden="false" data-tutor-modal-no-dismiss>
<div class="tutor-modal-overlay"></div>
<div class="tutor-modal-window" style="max-width: 834px;">
<div class="tutor-modal-content tutor-bg-white tutor-p-40">
Expand Down
13 changes: 11 additions & 2 deletions v2-library/src/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@

if (e.key === 'Escape' || e.key === 'Esc') {
e.preventDefault();
closeModal(activeModal);
if (!activeModal.hasAttribute('data-tutor-modal-no-dismiss')) {
closeModal(activeModal);
}
} else if (e.key === 'Tab') {
trapFocus(e);
}
Expand All @@ -159,7 +161,14 @@
if (e.target.hasAttribute(closeAttr) || e.target.classList.contains(overlay) || e.target.closest(`[${closeAttr}]`)) {
e.preventDefault();
const modal = e.target.closest('.tutor-modal.tutor-is-active');
if (modal) closeModal(modal);
if (modal && !modal.hasAttribute('data-tutor-modal-no-dismiss')) {
closeModal(modal);
} else if (modal && !e.target.classList.contains(overlay) && !e.target.closest(`.${overlay}`)) {
// Allow explicit close buttons even on no-dismiss modals
if (e.target.hasAttribute(closeAttr) || e.target.closest(`[${closeAttr}]`)) {
closeModal(modal);
}
}
}
});

Expand Down
Loading