Skip to content

Instantly share code, notes, and snippets.

@tradesouthwest
Created November 18, 2018 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tradesouthwest/d30ad60710001a24aa1f1e847d3a5028 to your computer and use it in GitHub Desktop.
Save tradesouthwest/d30ad60710001a24aa1f1e847d3a5028 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 );
@ergongervalla
Copy link

Hi, how can this be used. Should the file be added to a certain folder in learndash, or should the code be included inside a particular file?
Does this still work with the latest version of learndash?

Thanks

@tradesouthwest
Copy link
Author

@ergongervalla This was part of a plugin. You can try it inside of a functions file but it has to hook into LD filter... so template location would be important when calling the filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment