Here is a summary of the problems and what I’ve fixed:
Problems
1. Duplicate pre-quiz content
2. Error messages on last page of multi-page quiz which also cause the score not to display and say “quiz can’t be automarked.”
3. Pre and post content displays on all page – not good if the prequiz material is “Start the quiz now!”
Here is what I got done today:
Re-coded the content buffer function so that only one copy of the pre-quiz message is displayed. See below
function callback($buffer) {
// Grabs the actual page content (with shortcodes etc.)
global $post;
$pageContent = get_post($post->ID);
$content = $pageContent->post_content;
//load data to pass through if not a quiz/survey
// Checks if it is a quiz/survey before removing the content and replacing etc.
if (strpos($content, "[wpsqt_")) {
// Splits it to before shortcode and after
$contentSplit = preg_split('$\[wpsqt_(quiz|survey)\sname\=\"(\w|\s)*\"\]$', $content);
// clear out everything in the qcontent ID
$buffer = preg_replace('/<div class="qcontent">(.)*?<\/div>/s', '', $buffer);
// clear out everything in the content and before the pre-div.
$startPoint='<div id="content">';
$endPoint='<div class="pre-content">';
$newText='';
$buffer = replaceTags($startPoint, $endPoint, $newText, $buffer);
// Replaces the pre and post content divs with the content we split above
$buffer = str_replace('<div class="pre-content"></div>', '<div class="pre-content">'.nl2br($contentSplit[0]).'</div>', $buffer);
$buffer = str_replace('<div class="post-content"></div>', '<div class="post-content">'.nl2br($contentSplit[1]).'</div>', $buffer);
}
// Returns the buffer for output
return $buffer;
}
function replaceTags($startPoint, $endPoint, $newText, $source) {
return preg_replace('#('.preg_quote($startPoint).')(.*)('.preg_quote($endPoint).')#si', '$1'.$newText.'$3', $source);
}