Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmcclure/e62f46268bdeb0a0ca04a1fb9276f554 to your computer and use it in GitHub Desktop.
Save danielmcclure/e62f46268bdeb0a0ca04a1fb9276f554 to your computer and use it in GitHub Desktop.
LearnDash cloze answer accept case sensitive
<?php
/**
* LearnDash filter to prevent converting answer values to lowercase
*
* @possibly use ld_adv_quiz_pro_ajax()
* @uses stripslashes( strtolower( trim( $userResponse ) ) ) Default
* @since 1.0
* @from WpProQuiz_View_FrontQuiz.php
* post_type=sfwd-quiz
*/
//Prevent LearnDash from converting the answer before we get it
add_filter('learndash_quiz_question_cloze_answers_to_lowercase', '__return_false' );
//Here's our cut
function kiancode_learndash_quiz_recheck_using_original( $checked, $type, $answer, $correctArray, $answerIndex, $questionModel )
{
$shortcode='[code]';
$has_shortcode = strpos($questionModel->getAnswerData(true), $shortcode);
if( $has_shortcode)
{
return in_array( $answer, $correctArray );
}
$lower_correct=array_map('strtolower', $correctArray);
$lower_answer=strtolower($answer);
return in_array($lower_answer, $lower_correct);
}
add_filter( 'learndash_quiz_check_answer', 'kiancode_learndash_quiz_recheck_using_original', 15, 6 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment