llms_get_restriction_message( array $restriction )

Retrieve a message describing the reason why content is restricted Accepts an associative array of restriction data that can be retrieved from llms_page_restricted()


Description Description

This function doesn’t handle all restriction types but it should in the future Currently it’s being utilized for tooltips on lesson previews and some messages output during LLMS_Template_Loader handling redirects


Parameters Parameters

$restriction

(array) (Required) array of data from llms_page_restricted()


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/functions/llms.functions.access.php

function llms_get_restriction_message( $restriction ) {

	$msg = __( 'You do not have permission to access this content', 'lifterlms' );

	switch ( $restriction['reason'] ) {

		case 'course_prerequisite':
			$lesson = new LLMS_Lesson( $restriction['content_id'] );
			$course_id = $restriction['restriction_id'];
			$prereq_link = '<a href="' . get_permalink( $course_id ) . '">' . get_the_title( $course_id ) . '</a>';
			$msg = sprintf( _x( 'The lesson "%1$s" cannot be accessed until the required prerequisite course "%2$s" is completed.', 'restricted by course prerequisite message', 'lifterlms' ), $lesson->get( 'title' ), $prereq_link );
		break;

		case 'course_track_prerequisite':
			$lesson = new LLMS_Lesson( $restriction['content_id'] );
			$track = new LLMS_Track( $restriction['restriction_id'] );
			$prereq_link = '<a href="' . $track->get_permalink() . '">' . $track->term->name . '</a>';
			$msg = sprintf( _x( 'The lesson "%1$s" cannot be accessed until the required prerequisite track "%2$s" is completed.', 'restricted by course track prerequisite message', 'lifterlms' ), $lesson->get( 'title' ), $prereq_link );
		break;

		// this particular case is only utilized by lessons, courses do the check differently in the template
		case 'course_time_period':
			$course = new LLMS_Course( $restriction['restriction_id'] );
			// if the start date hasn't passed yet
			if ( ! $course->has_date_passed( 'start_date' ) ) {
				$msg = $course->get( 'course_opens_message' );
			} // End if().
			elseif ( $course->has_date_passed( 'end_date' ) ) {
				$msg = $course->get( 'course_closed_message' );
			}
		break;

		case 'enrollment_lesson':
			$course = new LLMS_Course( $restriction['restriction_id'] );
			$msg = $course->get( 'content_restricted_message' );
		break;

		case 'lesson_drip':
			$lesson = new LLMS_Lesson( $restriction['restriction_id'] );
			$msg = sprintf( _x( 'The lesson "%1$s" will be available on %2$s', 'lesson restricted by drip settings message', 'lifterlms' ), $lesson->get( 'title' ), $lesson->get_available_date() );
		break;

		case 'lesson_prerequisite':
			$lesson = new LLMS_Lesson( $restriction['content_id'] );
			$prereq_lesson = new LLMS_Lesson( $restriction['restriction_id'] );
			$prereq_link = '<a href="' . get_permalink( $prereq_lesson->get( 'id' ) ) . '">' . $prereq_lesson->get( 'title' ) . '</a>';
			$msg = sprintf( _x( 'The lesson "%1$s" cannot be accessed until the required prerequisite "%2$s" is completed.', 'lesson restricted by prerequisite message', 'lifterlms' ), $lesson->get( 'title' ), $prereq_link );
		break;

		default:

	}// End switch().

	return apply_filters( 'llms_get_restriction_message', do_shortcode( $msg ), $restriction );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.2.4 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.