Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error when viewing a lesson without a quiz #3057

Closed
jonathanbossenger opened this issue Dec 10, 2024 · 0 comments · Fixed by #3058
Closed

Fatal error when viewing a lesson without a quiz #3057

jonathanbossenger opened this issue Dec 10, 2024 · 0 comments · Fixed by #3058
Assignees
Labels
Priority - Medium Medium priority issue. [Type] Bug Something isn't working on the Learn website.

Comments

@jonathanbossenger
Copy link
Collaborator

While testing #3052 I encountered the following Fatal error when viewing lessons

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Sensei\Internal\Student_Progress\Quiz_Progress\Repositories\Comments_Based_Quiz_Progress_Repository::get() must be of the type int, null given, called in /var/www/html/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php on line 183 and defined in /var/www/html/wp-content/plugins/sensei-lms/includes/internal/student-progress/quiz-progress/repositories/class-comments-based-quiz-progress-repository.php:73
Stack trace:
#0 /var/www/html/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php(183): Sensei\Internal\Student_Progress\Quiz_Progress\Repositories\Comments_Based_Quiz_Progress_Repository->get(NULL, 1)
#1 /var/www/html/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php(119): WordPressdotorg\Theme\Learn_2024\Block_Hooks\is_quiz_ungraded()
#2 /var/www/html/wp-includes/class-wp-hook.php(326): WordPressdotorg\Theme\Learn_2024\Block_Hooks\update_lesson_quiz_notice_text('<div class="wp-...')
#3 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_fil in /var/www/html/wp-content/plugins/sensei-lms/includes/internal/student-progress/quiz-progress/repositories/class-comments-based-quiz-progress-repository.php on line 73

This is happening in the is_quiz_ungraded() function, when a lesson is rendered, but which does not have a quiz attached to it.

A quick fix could be to check if the quiz_id returned from Sensei()->lesson->lesson_quizzes() is null or not, and return false early

/**
 * Check if the quiz is ungraded.
 *
 * @return bool
 */
function is_quiz_ungraded() {
	$lesson_id = Sensei_Utils::get_current_lesson();
	$quiz_id   = Sensei()->lesson->lesson_quizzes( $lesson_id );
	if ( ! $quiz_id ) {
		return false;
	}
	$user_id   = get_current_user_id();
	$quiz_progress = Sensei()->quiz_progress_repository->get( $quiz_id, $user_id );

	if ( $quiz_progress && 'ungraded' === $quiz_progress->get_status() ) {
		return true;
	}

	return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority - Medium Medium priority issue. [Type] Bug Something isn't working on the Learn website.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant