Skip to content

Update logic for lesson completion check#8025

Open
markcummins wants to merge 2 commits into
Automattic:trunkfrom
markcummins:fix/hpps-issue-with-user_completed_lesson
Open

Update logic for lesson completion check#8025
markcummins wants to merge 2 commits into
Automattic:trunkfrom
markcummins:fix/hpps-issue-with-user_completed_lesson

Conversation

@markcummins

@markcummins markcummins commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Resolves #

Proposed Changes

  • Fix user_completed_lesson() incorrectly returning false for lessons manually marked complete when using HPPS (tables-based progress storage).

In the comments-based system a single sensei_lesson_status comment serves as both lesson progress and quiz progress. In HPPS these are stored as separate rows (type = 'lesson' and type = 'quiz' in sensei_lms_progress). When a lesson is manually marked complete (bypassing the normal quiz submission flow) only a type = 'lesson' row is created but no type = 'quiz' row exists.

Previously, when _pass_required was true and quiz_progress_repository->get() returned null, the code unconditionally returned false, even when the lesson progress row already held status = 'complete'. The fix adds an elseif so that if a lesson is marked as complete, the function continues rather than returning early.

Testing Instructions

  1. Enable HPPS (tables-based student progress storage) in Sensei settings.
  2. Create a lesson that has a quiz with Pass Required enabled.
  3. Manually mark the lesson as complete for a student (e.g. via the Sensei admin learner management screen) without the student submitting the quiz.
  4. Confirm that Sensei_Utils::user_completed_lesson( $lesson_id, $user_id ) returns true for that student.
  5. Confirm the student's course progress reflects the lesson as complete.

Before fix: step 4 returns false with HPPS enabled; the same scenario returns true with comments-based storage.
After fix: step 4 returns true in both storage modes.

New/Updated Hooks

Deprecated Code

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • Code is tested on the minimum supported PHP and WordPress versions

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch - Backwards-compatible bug fixes
  • Minor - Added or deprecated functionality in a backwards-compatible manner
  • Major - Broke backwards compatibility in some way

Type

  • Added - Adds new functionality
  • Changed - Changes existing functionality
  • Fixed - Fixes a bug
  • Deprecated - Marks functionality as deprecated
  • Removed - Removes functionality
  • Security - Security-related change
  • Development - Development or internal task

Message

Fix user_completed_lesson() returning false for manually-completed lessons when using HPPS (tables-based progress storage) with Pass Required enabled.

Copilot AI review requested due to automatic review settings June 19, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Sensei_Utils::user_completed_lesson() incorrectly returning false in HPPS (tables-based progress) when a lesson is manually marked complete for a quiz that has Pass Required enabled, but no corresponding quiz progress row exists.

Changes:

  • Updates the Pass Required logic to only return early when quiz progress is missing and the lesson progress is not already complete.
  • Adds an explanatory inline comment describing why lesson completion can be authoritative when quiz progress is missing (manual completions / migrated data).
  • Tweaks an existing inline comment (but it still contains a typo after this PR).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// In the comments-based progress we use one entry to store both the lesson progress and the quiz progress.
// In the tables-based progress we split them. Here is important to use the quiz proress if the quiz pass is required.
// In the tables-based progress we split them. Here is important to use the quiz progess if the quiz pass is required.
Comment on lines 1828 to 1835
$quiz_progress = Sensei()->quiz_progress_repository->get( $lesson_quiz_id, $user_id );
if ( $quiz_progress ) {
$user_lesson_status = $quiz_progress->get_status();
} else {
} elseif ( $user_lesson_status !== 'complete' ) {
// A lesson already marked complete is authoritative: no quiz row exists for manual
// completions and lessons migrated from the comments-based system.
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants