learndash_ques_single_answer_pts

apply_filters( 'learndash_ques_single_answer_pts',  integer $points,  array $question_data,  int|string $answer_index,  mixed $correct_answer,  array $user_response )

Filters points awarded for a single answer type question.


Description #

LearnDash single answer question, allow points to be allocated for not marking an incorrect answer. Allow all possibility of given answer to be correct answer.


Parameters #

$points

(integer) Points awarded to quiz

$question_data

(array) An array of question data.

$answer_index

(int|string) Index of the answer.

$correct_answer

(mixed) Correct answer for the question.

$user_response

(array) An array of user response data.


Source #

File: includes/quiz/ld-quiz-pro.php


Examples #

 <?php
/**
 * Example usage for learndash_ques_single_answer_pts filter.
 */
add_filter( 'learndash_ques_single_answer_pts', 'learndash_ques_single_answer_pts', 10, 5 );
function learndash_ques_single_answer_pts( $points, $questionData, $answerIndex, $correctAnswer, $userResponse ) {

	// If the Single Question diffMode is enabled then we ignore.
	if ( ( ! isset( $questionData['diffMode'] ) ) || ( empty( $questionData['diffMode'] ) ) ) {
		// If the user provide an answer and is correct...
		if ( ( ! empty( $correctAnswer ) ) && ( ! empty( $userResponse[ $answerIndex ] ) ) ) {
			// ...we give the points for total of all/any answers.
			$points = array_sum( $questionData['points'] );
		} else {
			// ...we give the points for total of all correct answers.
			$points = array_sum( $questionData['correct'] );
		}
	}

	return $points;
}