Forked from tradesouthwest/learndash-code-in-answer.php
Created
July 13, 2020 03:45
-
-
Save danielmcclure/e62f46268bdeb0a0ca04a1fb9276f554 to your computer and use it in GitHub Desktop.
LearnDash cloze answer accept case sensitive
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
<?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