llms_is_post_restricted_by_time_period( int $post_id, int|null $user_id = null )

Determine if a course (or lesson/quiz) is “open” according to course time period settings.


Parameters Parameters

$post_id

(int) (Required) WP Post ID of a course, lesson, or quiz.

$user_id

(int|null) (Optional) WP User ID (will use get_current_user_id() if none supplied). Default null.

Default value: null


Top ↑

Return Return

(int|false) False if the post is not restricted by course time period, WP Post ID of the course if it is.


Top ↑

Source Source

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

function llms_is_post_restricted_by_time_period( $post_id, $user_id = null ) {

	$post_type = get_post_type( $post_id );

	// if we're on a lesson, get course information.
	if ( 'lesson' === $post_type ) {

		$lesson    = new LLMS_Lesson( $post_id );
		$course_id = $lesson->get( 'parent_course' );

	} elseif ( 'llms_quiz' === $post_type ) {
		$quiz      = llms_get_post( $post_id );
		$lesson_id = $quiz->get( 'lesson_id' );
		if ( ! $lesson_id ) {
			return false;
		}
		$lesson = llms_get_post( $lesson_id );
		if ( ! $lesson_id ) {
			return false;
		}
		$course_id = $lesson->get( 'parent_course' );

	} elseif ( 'course' === $post_type ) {

		$course_id = $post_id;

	} else {

		return false;

	}

	$course = new LLMS_Course( $course_id );
	if ( $course->is_open() ) {
		return false;
	} else {
		return $course_id;
	}

}


Top ↑

Changelog Changelog

Changelog
Version Description
5.7.0 Replaced the call to the deprecated LLMS_Lesson::get_parent_course() method with LLMS_Lesson::get( 'parent_course' ).
3.16.11 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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