Skip to content

Fix fatal when fetching questions for a lesson with no quiz#8000

Merged
donnapep merged 2 commits into
trunkfrom
fix/lesson-quiz-questions-empty-quiz-id
Jun 9, 2026
Merged

Fix fatal when fetching questions for a lesson with no quiz#8000
donnapep merged 2 commits into
trunkfrom
fix/lesson-quiz-questions-empty-quiz-id

Conversation

@donnapep

@donnapep donnapep commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

A lesson without a quiz makes Sensei_Lesson::lesson_quizzes() return null. lesson_quiz_questions() casts that to the empty string '' and passes it to Sensei()->quiz_submission_repository->get( int $quiz_id, int $user_id ). The non-numeric '' cannot coerce to int, throwing:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to ...Submission_Repository::get() must be of the type int, string given

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 legacy questions_asked comment-meta lookup (implicitly guarded by an existing user status) for the typed repository call.

Fix

Cast the quiz and user IDs to int at the call site. For a quiz-less lesson this yields get( 0, 0 ), which returns null and falls through to the existing no-submission branch — behaviour for real quizzes is unchanged.

Test plan

  • On a fresh install with a published lesson that has no quiz, trigger usage tracking (sensei_core_jpo_send cron / page load) and confirm no TypeError is logged.
  • Confirm quizzes with submissions still render the questions in the order they were asked.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 9, 2026 16:30
@donnapep donnapep added this to the 4.26.0 milestone Jun 9, 2026
@donnapep donnapep self-assigned this Jun 9, 2026

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

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_id and $user_id to int when calling quiz_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.

Comment thread includes/class-sensei-lesson.php Outdated
Comment thread includes/class-sensei-lesson.php Outdated
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

WordPress Playground Preview

The changes in this pull request can previewed and tested using a WordPress Playground instance.

Open WordPress Playground Preview

…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 donnapep merged commit 14393c8 into trunk Jun 9, 2026
25 checks passed
@donnapep donnapep deleted the fix/lesson-quiz-questions-empty-quiz-id branch June 9, 2026 16:46
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>
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