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
Return Return
(int|false) False if the post is not restricted by course time period, WP Post ID of the course if it is.
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 ); switch ( $post_type ) { // If we're on a lesson, get course information. case 'lesson': $lesson = new LLMS_Lesson( $post_id ); $course_id = $lesson->get( 'parent_course' ); break; case 'llms_quiz': $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' ); break; case 'course': $course_id = $post_id; break; default: // Don't pass other post types. return false; } $course = new LLMS_Course( $course_id ); return $course->is_open() ? false : $course_id; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
6.5.0 | Improve code readability turning if-elseif into a switch-case. |
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. |