The lesson access helper
pom_lms_user_can_access_lesson( int $lesson_id, int $course_id = 0 ): bool
Returns whether the current user may access a lesson. This is the helper to call before rendering any lesson content.
The course argument
Optional. Pass it when you already know the course — it saves a lookup. Omit it and the helper reads the lesson's attached course.
pom_lms_user_can_access_lesson( $lesson_id ); // resolves the course
pom_lms_user_can_access_lesson( $lesson_id, $course_id ); // uses the one you pass
What it evaluates
| Step | Condition | Result |
|---|---|---|
| 1 | The lesson has no course | false |
| 2 | The course requires login and the visitor is signed out | false |
| 3 | The lesson has its own permission rule | Whatever that rule says |
| 4 | The course has a permission rule | Whatever that rule says |
| 5 | Otherwise | The course's access decision |
The lesson's own rule replaces the course's rule; it does not add to it. A lesson with a rule ignores the course's rule entirely.
A lesson with no course is never accessible
Step 1 is the reason an unattached lesson returns not found on the front end: with no course, there are no rules to apply, and refusing is the only safe answer.
If your integration creates lessons programmatically, set the attached course before publishing.
Previews
A lesson marked as a preview is accessible to everyone, subject only to the course's setting about whether previews require login.
Expect the helper to return true for anonymous visitors on preview lessons. That is intended behavior — the preview flag is a publishing decision, not a bug.
If you need to know whether a lesson is a preview, pom_lms_is_preview_lesson( $lesson_id ) returns that as a boolean. Use it for labeling, never as a substitute for the access check.
Using it
if ( ! function_exists( 'pom_lms_user_can_access_lesson' ) ) {
return '';
}
foreach ( $lesson_ids as $lesson_id ) {
$accessible = pom_lms_user_can_access_lesson( $lesson_id, $course_id );
// Render the title either way; render the content only if accessible.
}
That pattern — titles always, content conditionally — is what the course outline does. Students see the shape of what they are missing, which is more persuasive than hiding it.
Do not substitute the course helper
Checking the course and then rendering the lesson misses two things: the lesson's permission override, and the preview flag. One of those leaks content, the other hides content you meant to publish.
For lesson content, call the lesson helper.
Current user only
As with the course helper, there is no user-ID parameter, and no supported way to ask on behalf of another user. Check access at render time, in the visitor's own request.
Cost
The lesson helper delegates to the course helper when no lesson-level rule applies, so the same guidance applies: a paid course means a purchase check.
When rendering an outline of many lessons in one course, resolve the course once and pass $course_id to every call.