Below, you’ll find a detailed guide on how to add the Watu Quiz Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Watu Quiz Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Watu Quiz Plugin and the shortcodes it provides:
"Watu Quiz is a powerful WordPress plugin designed to create and manage quizzes. With its user-friendly interface, it makes the process of creating engaging and interactive quizzes effortless."
- [WATU]
- [watu-basic-chart]
- [watu-takings]
Watu Quiz [WATU] Shortcode
The Watu shortcode is responsible for rendering exams on your WordPress site. It takes an exam ID as an attribute and displays the corresponding exam. The shortcode checks if the ID is numeric. If not, it returns an empty string. It then includes the ‘show_exam.php’ file from Watu’s path, which contains the logic for displaying the exam. If AJAX isn’t used, it directly requires the ‘show_exam.php’ file. The contents are then returned after applying any filters. Shortcode: [WATU]
Shortcode: [WATU]
Examples and Usage
Basic example – A simple usage of the Watu shortcode to display an exam based on its ID.
[WATU 1 /]
Advanced examples
Displaying an exam by passing the ID as an attribute to the shortcode. If the ID is not found, the shortcode will return an empty string.
[WATU id="2" /]
Using the shortcode to display an exam based on its ID, and disabling AJAX for the submission of the exam. This can be useful if you’re experiencing issues with AJAX on your site.
[WATU id="3" no_ajax="true" /]
Note: The ‘id’ attribute in the shortcode corresponds to the ‘exam_id’ in the PHP function and the ‘no_ajax’ attribute corresponds to the ‘$_POST[‘no_ajax’]’ in the PHP function.
PHP Function Code
In case you have difficulties debugging what causing issues with [WATU]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'WATU', 'watu_shortcode' );
Shortcode PHP function:
function watu_shortcode( $attr ) {
$exam_id = $attr[0] ?? 0;
$contents = '';
if(!is_numeric($exam_id)) return $contents;
watu_vc_scripts();
// submitting without ajax?
if(!empty($_POST['no_ajax']) and !empty($exam->no_ajax)) {
require(WATU_PATH."/show_exam.php");
$contents = ob_get_clean();
$contents = apply_filters('watu_content', $contents);
return $contents;
}
ob_start();
include(WATU_PATH . '/controllers/show_exam.php');
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
Code file location:
watu/watu/watu.php
Watu Quiz [watu-basic-chart] Shortcode
The Watu Basic Chart shortcode is a function that creates a bar chart based on the user’s quiz results. This shortcode takes the global variable ‘watu_taking_id’, converts it into an integer, and uses it to generate a bar chart. The chart visually represents the user’s performance in the quiz, offering an engaging and easy-to-understand overview of the results.
Shortcode: [watu-basic-chart]
Examples and Usage
Basic example – The following code illustrates a basic usage of the watu_basic_chart shortcode. Here, we are passing the taking_id as a parameter to the shortcode.
[watu-basic-chart taking_id=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [watu-basic-chart]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'watu-basic-chart', 'watu_basic_chart' );
Shortcode PHP function:
function watu_basic_chart($atts) {
$taking_id = intval($GLOBALS['watu_taking_id']);
$content = watu_barchart($taking_id, $atts);
return $content;
}
Code file location:
watu/watu/watu.php
Watu Quiz [watu-takings] Shortcode
The Watu Takings shortcode is a function that captures and returns the output of the watu_takings function. This shortcode, when inserted into a post or page, will execute the watu_takings function with the given attributes. It captures the output into a buffer, cleans it, and then returns the content.
Shortcode: [watu-takings]
Examples and Usage
Basic example – Utilizing the shortcode to display the Watu takings without any specific parameters.
[watu-takings /]
PHP Function Code
In case you have difficulties debugging what causing issues with [watu-takings]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'watu-takings', 'watu_shortcode_takings' );
Shortcode PHP function:
function watu_shortcode_takings($atts) {
ob_start();
watu_takings(true, $atts);
$content = ob_get_clean();
return $content;
}
Code file location:
watu/watu/watu.php
Conclusion
Now that you’ve learned how to embed the Watu Quiz Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply