Fix fatal when fetching questions for a lesson with no quiz#8000
Merged
Conversation
A lesson without a quiz yields an empty quiz ID, which lesson_quiz_questions() passed as a string to the quiz submission repository's get( int, int ). The non-numeric empty string could not coerce to int, throwing a TypeError. This surfaced via usage tracking iterating published quiz-less lessons. Cast the quiz and user IDs to int at the call site. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents a PHP TypeError when Sensei_Lesson::lesson_quiz_questions() attempts to fetch a quiz submission for lessons where the resolved quiz ID (and/or user ID) can be empty, which can surface during usage tracking.
Changes:
- Cast
$quiz_idand$user_idtointwhen callingquiz_submission_repository->get()to avoid passing a non-numeric string. - Add a changelog entry documenting the fatal fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| includes/class-sensei-lesson.php | Ensures typed repository call receives ints to avoid TypeError when IDs are empty/non-numeric. |
| changelog/fix-lesson-quiz-questions-empty-quiz-id | Documents the fix as a patch-level “fixed” change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
…ssons Address review feedback: short-circuit the quiz submission lookup when the quiz or user ID is empty so usage tracking skips an unnecessary query per quiz-less lesson, and add a regression test for lesson_quiz_questions() on a lesson with no quiz. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
donnapep
added a commit
that referenced
this pull request
Jun 9, 2026
Fold the #8000 fix into the 4.26.0 changelog.txt and readme.txt sections and remove the now-consumed loose changelog entry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A lesson without a quiz makes
Sensei_Lesson::lesson_quizzes()returnnull.lesson_quiz_questions()casts that to the empty string''and passes it toSensei()->quiz_submission_repository->get( int $quiz_id, int $user_id ). The non-numeric''cannot coerce toint, throwing:All four submission repositories type-hint
int, so this is independent of the HPPS (tables vs. comments) configuration.The crash surfaces through usage tracking (
Sensei_Usage_Tracking_Data::get_quiz_stats()), which loops over every published lesson — any published lesson with no quiz triggers it. Latent since the 4.7.2 refactor that swapped the legacyquestions_askedcomment-meta lookup (implicitly guarded by an existing user status) for the typed repository call.Fix
Cast the quiz and user IDs to
intat the call site. For a quiz-less lesson this yieldsget( 0, 0 ), which returnsnulland falls through to the existing no-submission branch — behaviour for real quizzes is unchanged.Test plan
sensei_core_jpo_sendcron / page load) and confirm noTypeErroris logged.🤖 Generated with Claude Code