[WatuPRO] How To Display Different Content Depending on Last / Not Last Quiz Attempt

WatuPRO has a setting to limit the number of quiz attempts by IP addres (or by username if your quiz requires user login). Sometimes you may want to display different message to the user depending on whether this is their last quiz attempt or not. For example you may want to conditionally display text like “Try again!” and “Sorry, you have no more attempts!”.

WatuPRO doesn’t yet have such configuration but it’s easy to build a custom filter using our barebone customization plugin.

If you are not interested in the code, read only the following section which also gives download link for the . The third section of this article will show and explain the code.

Customized Filter Download and Usage

In order to use the new filter you need to download and install this plugin:


How to use it? Simply include your conditional content between “tags”:

{last} This content will be shown only after the last user’s attempt on the quiz. {/last}

{notlast} This content will be shown only if the user has more attempts. {/notlast}

You can include these tags in the “Final page / quiz output” tab or in the grade descriptions in case you are showing grade descriptions in your quiz output.

Here’s an example:


You completed quiz %%QUIZ-NAME%%.

You got %%PERCENTAGE%%% correct answers.

{last}You have no more attempts.

Here are your answers: %%ANSWERS%%{/last}

{notlast}You can try again{/notlast}

Programming Code

If you are interested in the code, here’s how we did it. In the watuprocustom_init() function we added a filter for the “watupro_content” filer:

add_filter(‘watupro_content’, array(‘WatuPROCustomFilters’, ‘last_attempt’));

And below is the filter function. It works only by IP but it’s easy to change it to work with quizzes restricted by “user_id” as well.

class WatuPROCustomFilters {
	// replace contents of  &  pseudo-tags
	//   & 
	// currently used for %%ANSWERS%% variable
   static function last_attempt($content) {
   	global $wpdb;
		if(empty($_POST['watupro_current_taking_id'])) return $content;   
		// now get the contents between last-attempts and not-last-attempts tags
		// in case tags are not there return content
		if(!strstr($content, '{last}') and !strstr($content, '{notlast}')) return $content; 	
   	// select taking
		$taking = $wpdb->get_row($wpdb->prepare("SELECT exam_id, ip, user_id 
			FROM ".WATUPRO_TAKEN_EXAMS." WHERE ID=%d", $_POST['watupro_current_taking_id']));
		// select quiz allowed num takings	
		$quiz = $wpdb->get_row($wpdb->prepare("SELECT takings_by_ip FROM ".WATUPRO_EXAMS." 
			WHERE ID=%d", $taking->exam_id));
		$is_last_attempt = false;
		if($quiz->takings_by_ip) {
			// select num takings
			$num_takings = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM ".WATUPRO_TAKEN_EXAMS."
			WHERE exam_id=%d AND ip=%s", $taking->exam_id, $_SERVER['REMOTE_ADDR']));
			if($num_takings >= $quiz->takings_by_ip) $is_last_attempt = true;
		// now replace properly
		if($is_last_attempt) {
			// the content between  and  should be shown. The other should be removed
			$content = str_replace(array('{last}','{/last}'), '', $content);
			$content = preg_replace('#\{notlast\}(.+?)\{\/notlast\}#s', '', $content);
		else {
			echo 'werehere';
			$content = str_replace(array('{notlast}','{/notlast}'), '', $content);
			$content = preg_replace('#\{last\}(.+?)\{\/last\}#s', '', $content);
		return $content;		
   }	// end last_attempt filter

[WatuPRO] How Does The Timer Work?

WatuPRO, the premium version of our WordPress quiz plugin has a timer feature. It’s enabled by a setting in the  Add / Edit Quiz page:

Set time limit of minutes (Leave it blank or enter 0 to not set any time limit.)

When you set anything different than zero, everyone who starts the quiz will see “Start Quiz” button. When started the timer starts running.  Here are several frequently asked questions about the timer and their answers:

Q: What happens when the timer runs out?

A: The user results are automatically submitted. So the questions they already answered will be recorded properly, the other will be marked as unanswered.

Q: What happens if the user refreshes the page from their browser?

A: The timer continues from where they were. No time is lost or added except the few seconds taken for refreshing the page.

Q: What happens if the user closes the browser, their internet connection get lost, power goes down etc?

A: The timer keeps running behind the scene so the time when the user was not online is lost. This is done to prevent cheating of users who can take screenshot of the questions and answer “at home”.

When the user comes back, the timer continues. If all the time ran out, their results are submitted automatically.

If the time ran out before the user returned back to the quiz, their results will be submitted blank. The best for such users is to be given the chance to try again. For the moment we are unable to retrieve the serialized answers they gave before the outage from the database but we are working on this.

Q: How does it work for non logged in users?

A: The same way as of non logged in users except that closing the browser will clear the session and restart the timer. Refreshing the page does not restart the timer – it keeps running from where it was refreshed.

Q: Can users with disabled JavaScript on their browsers cheat the timer?

A: No, they can’t. The start time of their quiz attempt is recorded in the database so even without any javascript they can’t cheat the timer. Results of users who try to cheat the timer this way and exhaust their time will not be accepted. They will remain as “unfinished quiz attempts”.

Q: Is there a place where I can see unfinished quiz attempts?

A: Yes. If there are any quiz attempts that are currently in progress, you will see the following link in your “View results” page (this is the page you get when you click on the “Taken X times” link under “View Results” column on your Quizzes page) :

There are 1 unfinished attempt(s).

You can click on that link to see these attempts and clean them if you wish (be careful, some of these might be of an user currently taking a quiz).

Q: Do search engines index the contents of quizzes with timer?

A: The questions of timed quizzes are hidden before the timer is started. This is to avoid tech-savvy users viewing the questions by using “view source”. For this reason search engines can’t index these questions.

WatuPRO 4.6

Thanks for the useful customers feedback our WordPress quiz plugin WatuPRO keeps improving. Version 4.6 is out, and here are the most important changes, additions, and improvements:

  • Questions can accept user’s comments / feedback.
  • Single-choice questions can be displayed as drop-down selector instead of radio buttons group.
  • You can now specify custom subject for the submitted quiz notification email.
  • You can filter questions by ID in the Manage Questions page. The question IDs can also be displayed to the user using the variable {{{ID}}}
  • Bridge to MailChimp is now available: http://blog.calendarscripts.info/watupro-bridge-to-mailchimp/
  • The shortcodes that list all quizzes and quizzes in category now have additional optional argument “show_status”. It will allow logged in users to see if every quiz is completed, not started, or in progress.
  • “Show numbered pagination” is now available for all types of quizzes
  • Option to reward the collected positive points only when the whole question is answered correctly. This is useful for multiple-choice questions and is similar to “treat this question as a whole” option from the Intelligence module.
  • Quizzes can now be published also in custom fileds as long as you enter the URL in the new box (more info at http://blog.calendarscripts.info/watupro-quizzes-published-in-custom-fields/)
  • [Intelligence module] You can now sell paid quizzes in bundles. More info at http://blog.calendarscripts.info/watupro-intelligence-module-paid-quiz-bundles/
  • [Intelligence module] Sorting questions can now be used in personality quizzes to allow the user assign different weight to different answers. More information at http://blog.calendarscripts.info/using-sorting-questions-in-personality-quizzes-watupro/
  • [Intelligence module] Added option to mark payment as used after each quiz attempt on paid quizzes. This lets you charge users for every quiz attempt.
  • Stats per category are now available in the Reporting module (num and % answered, unanswered, and correct answers)
  • Added “barebone” plugin for API developers: http://blog.calendarscripts.info/wp-content/uploads/2013/06/watupro-custom.zip
  • Advanced setting option lets you switch off the auto-scrolling on multiple-paged quizzes
  • Automatically store user progress as they go from page to page is now available for all pagination types
  • Added ungrouped quiz leaderboards sorting based on individual attempts (Play plugin)
  • Added %%CATDESC%% variable in the “common category grade output” so you can include the category description when showing category grades.
  • Added user groups information in the list of results on a quiz
  • Added option to hide question numbers so you don’t have to deal with CSS
  • Fixed issues with ordering the categories in %%CATGRADES%%
  • Free bridge for myCRED has been added. Please look here for more information.
  • Fixed memory leak issue

The update has been sent via newsletter to all eligible customers. In case your year of free updates has expired you can renew with 60% discount.