llms_can_user_complete_lesson( int $user_id, LLMS_Lesson|int $lesson )
Determine whether a user is authorized to mark a given lesson complete or incomplete.
Description Description
Used both to decide whether to render the front-end mark complete/incomplete buttons and to authorize the form submission server-side, so the two cannot drift apart. Instructors and admins who can edit the lesson are always allowed; everyone else must be enrolled in the lesson’s parent course and the lesson must be available (drip).
Parameters Parameters
- $user_id
-
(int) (Required) WP User ID of the student.
- $lesson
-
(LLMS_Lesson|int) (Required) LLMS_Lesson instance or WP Post ID of a lesson.
Return Return
(bool)
Source Source
File: includes/functions/llms-functions-progression.php
function llms_can_user_complete_lesson( $user_id, $lesson ) {
if ( ! $lesson instanceof LLMS_Lesson ) {
$lesson = llms_get_post( $lesson );
}
if ( ! $lesson || ! is_a( $lesson, 'LLMS_Lesson' ) ) {
$allowed = false;
} elseif ( current_user_can( 'edit_post', $lesson->get( 'id' ) ) ) {
// Instructors / admins able to edit the lesson are always allowed.
$allowed = true;
} else {
// The student must be enrolled in the lesson's parent course and the lesson must be available.
$allowed = ( $user_id && llms_is_user_enrolled( $user_id, $lesson->get( 'parent_course' ) ) && $lesson->is_available() );
}
/**
* Filter whether a user is authorized to mark a lesson complete or incomplete.
*
* @since 10.0.7
*
* @param bool $allowed Whether or not the user is authorized.
* @param int $user_id WP User ID of the student.
* @param LLMS_Lesson|bool $lesson LLMS_Lesson instance, or `false` for an invalid lesson.
*/
return apply_filters( 'llms_can_user_complete_lesson', $allowed, $user_id, $lesson );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 10.0.7 | Introduced. |