Skip to content

Fix/user completed lesson empty lesson quiz - #8240

Open
markcummins wants to merge 2 commits into
Automattic:trunkfrom
markcummins:fix/user-completed-lesson-empty-lesson-quiz
Open

markcummins wants to merge 2 commits into
Automattic:trunkfrom
markcummins:fix/user-completed-lesson-empty-lesson-quiz

Conversation

@markcummins

Copy link
Copy Markdown
Contributor

Resolves #

Proposed Changes

  • Fixes a bug where the lesson incorrectly shows as incomplete when its quiz has a stale in-progress attempt but no actual questions.

Screenshots

Before After

Testing Instructions

  • Viewing the quiz page (not even answering) creates a quiz-type progress
  • If the student never submits, that row never advances past in-progress.
  • Later, an editor removes all the questions from that quiz.
  • Because the quiz now has no questions, Sensei's own lesson template treats it as "no quiz" and shows a plain Complete Lesson button. The student clicks it, and lesson_progress becomes complete.
  • The stale quiz progress row from step 1 is still sitting at in-progress
  • user_completed_lesson() now sees: lesson row complete, but _pass_required = on, and will return false

New/Updated Hooks

Deprecated Code

Changelog entry

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

Significance

  • Patch - Backward-compatible bug fixes
  • Minor - Add or deprecate functionality in a backward-compatible manner
  • Major - Incompatible or breaking API changes

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 a lesson incorrectly showing as incomplete when its quiz has a stale in-progress attempt but no actual questions.

Copilot AI lite review requested due to automatic review settings September 8, 2026 10:10

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.

🟡 Changes recommended

The updated completion behavior is not covered by a regression test for the stale-quiz-progress/no-questions scenario described in the PR.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes an edge-case in lesson completion logic where a stale “in-progress” quiz progress record could cause Sensei_Utils::user_completed_lesson() to return false even after the lesson itself was completed, specifically when the associated quiz no longer has any questions.

Changes:

  • Update Sensei_Utils::user_completed_lesson() to only consult quiz progress (when pass is required) if the lesson’s quiz still has questions.
  • Add a patch-level changelog entry describing the bug fix.
File summaries
File Description
includes/class-sensei-utils.php Avoids using quiz progress to determine completion when the quiz effectively has no questions.
changelog/fix-user-completed-lesson-empty-quiz Documents the fix as a patch “fixed” changelog entry.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// In the tables-based progress we split them. Here is important to use the quiz proress if the quiz pass is required.
$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
if ( $lesson_quiz_id ) {
if ( $lesson_quiz_id && Sensei_Lesson::lesson_quiz_has_questions( $lesson_id ) ) {

This branch has not been deployed

No deployments
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