Skip to content

Commit

Permalink
Refactor and change preview lesson notice with self-enrollment not al…
Browse files Browse the repository at this point in the history
…lowed
  • Loading branch information
renatho committed Oct 30, 2023
1 parent 5349118 commit 7cdfb12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions includes/course-theme/class-sensei-course-theme-lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ private function maybe_add_lesson_prerequisite_notice() {
* @return void
*/
private function maybe_add_not_enrolled_notice() {
$lesson_id = \Sensei_Utils::get_current_lesson();
$course_id = Sensei()->lesson->get_course_id( $lesson_id );
$lesson_id = \Sensei_Utils::get_current_lesson();
$course_id = Sensei()->lesson->get_course_id( $lesson_id );
$is_preview = $lesson_id && Sensei_Utils::is_preview_lesson( $lesson_id );

if ( Sensei_Course::is_user_enrolled( $course_id ) ) {
return;
Expand All @@ -262,11 +263,16 @@ private function maybe_add_not_enrolled_notice() {
$notice_title = __( 'You don\'t have access to this lesson', 'sensei-lms' );
$notice_icon = 'lock';

if ( $is_preview ) {
$notice_title = __( 'This is a preview lesson', 'sensei-lms' );
$notice_icon = 'eye';
}

// Check if self-enrollment is allowed.
if ( Sensei_Course::is_self_enrollment_not_allowed( $course_id ) ) {
$notices->add_notice(
$notice_key,
__( 'Please contact the course administrator to access the course content.', 'sensei-lms' ),
__( 'Please contact the course administrator to take this lesson.', 'sensei-lms' ),
$notice_title,
[],
$notice_icon
Expand Down Expand Up @@ -311,10 +317,8 @@ private function maybe_add_not_enrolled_notice() {

$notice_text = __( 'Please register or sign in to access the course content.', 'sensei-lms' );

if ( $lesson_id && Sensei_Utils::is_preview_lesson( $lesson_id ) ) {
$notice_text = __( 'Register or sign in to take this lesson.', 'sensei-lms' );
$notice_title = __( 'This is a preview lesson', 'sensei-lms' );
$notice_icon = 'eye';
if ( $is_preview ) {
$notice_text = __( 'Register or sign in to take this lesson.', 'sensei-lms' );
}

$notices->add_notice(
Expand All @@ -340,10 +344,8 @@ private function maybe_add_not_enrolled_notice() {

$notice_text = __( 'Please register for this course to access the content.', 'sensei-lms' );

if ( $lesson_id && Sensei_Utils::is_preview_lesson( $lesson_id ) ) {
$notice_text = __( 'Register for this course to take this lesson.', 'sensei-lms' );
$notice_title = __( 'This is a preview lesson', 'sensei-lms' );
$notice_icon = 'eye';
if ( $is_preview ) {
$notice_text = __( 'Register for this course to take this lesson.', 'sensei-lms' );
}

$notices->add_notice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function testCourseNotAllowedSelfEnrollmentNotice() {
$html = \Sensei_Context_Notices::instance( 'course_theme_locked_lesson' )->get_notices_html( 'course-theme/locked-lesson-notice.php' );

/* Assert. */
$this->assertStringContainsString( 'Please contact the course administrator to access the course content.', $html, 'Should return not allowed self-enrollment notice' );
$this->assertStringContainsString( 'Please contact the course administrator to take this lesson.', $html, 'Should return not allowed self-enrollment notice' );
}

/**
Expand Down

0 comments on commit 7cdfb12

Please sign in to comment.