Below, you’ll find a detailed guide on how to add the Quiz Maker 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 Quiz Maker Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Quiz Maker Plugin and the shortcodes it provides:
"Quiz Maker is a dynamic WordPress plugin, designed to create engaging quizzes. With Quiz Maker, effortlessly design, manage, and implement interactive quizzes on your website."
- [vc_quizmaker]
- [ays_quiz]
- [ays_all_results]
- [ays_quiz_cat]
- [ays_quiz_cat_title]
- [ays_quiz_cat_description]
- [ays_display_questions]
- [ays_quiz_avg_score]
- [ays_quiz_passed_users_count]
- [ays_quiz_failed_users_count_by_score]
- [ays_quiz_passed_users_count_by_score]
- [ays_quiz_user_passed_quizzes_count]
- [ays_quiz_user_all_passed_quizzes_count]
- [ays_quiz_user_first_name]
- [ays_quiz_user_last_name]
- [ays_quiz_user_nickname]
- [ays_quiz_user_display_name]
- [ays_quiz_user_email]
- [ays_quiz_user_duration]
- [ays_quiz_creation_date]
- [ays_quiz_current_author]
- [ays_quiz_questions_count]
- [ays_quiz_category_title]
- [ays_quiz_category_description]
- [ays_quiz_question_categories_title]
- [ays_quiz_question_categories_description]
- [ays_quiz_user_roles]
- []
- [ays_quiz_read_results_count]
- [ays_quiz_quizzes_count]
- [ays_quiz_user_website]
- [ays_quiz_all_results_count]
- [ays_quiz_question_categories_count]
- [ays_quiz_avg_rate]
- [ays_quiz_all_questions_count]
- [ays_quiz_most_popular]
- [ays_quiz_all_results]
Quiz Maker [vc_quizmaker] Shortcode
The VC Quizmaker shortcode is designed to embed a specific quiz into your WordPress site. It extracts the ‘quiz’ parameter from the shortcode’s attributes and uses it to generate the quiz’s HTML.
Shortcode: [vc_quizmaker]
Parameters
Here is a list of all possible vc_quizmaker shortcode parameters and attributes:
quiz
– The unique identifier of the quiz to be displayed
Examples and Usage
Basic example – A fundamental usage of the vc_quizmaker shortcode to display a specific quiz by referencing its ID.
[vc_quizmaker quiz=1 /]
For more advanced usage, you can use the shortcode within other shortcodes or elements to customize the display of your quizzes.
Advanced example – Embedding the vc_quizmaker shortcode within a page builder element to style and position the quiz on the page.
[vc_row][vc_column][vc_quizmaker quiz=1 /][/vc_column][/vc_row]
In this example, the vc_quizmaker shortcode is nested within vc_row and vc_column shortcodes, which are part of the Visual Composer page builder plugin. This allows you to position and style the quiz as part of a more complex layout. The quiz ID is still referenced in the same way.
Please note that the specific shortcodes and parameters available will depend on your theme and plugins, and you should consult their documentation for detailed information.
PHP Function Code
In case you have difficulties debugging what causing issues with [vc_quizmaker]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'vc_quizmaker', array( $this, 'vc_quizmaker_html' ) );
Shortcode PHP function:
function vc_quizmaker_html( $atts ) {
// Params extraction
extract(
shortcode_atts(
array(
'quiz' => null
),
$atts
)
);
// Fill $html var with data
// Fill $html var with data
$html = do_shortcode("[ays_quiz id={$quiz}]");
return $html;
}
Code file location:
quiz-maker/quiz-maker/pb_templates/quiz_maker_wpbvc.php
Quiz Maker [ays_quiz] Shortcode
The ‘ays_quiz’ shortcode is a function in the quiz-maker plugin that generates quizzes. It accepts an ‘id’ attribute that identifies the specific quiz to be generated. If the ‘id’ is not provided or incorrect, it returns a message indicating a wrong shortcode initialization. It sets quiz texts, enqueues necessary styles and scripts, and finally displays the quiz.
Shortcode: [ays_quiz]
Parameters
Here is a list of all possible ays_quiz shortcode parameters and attributes:
id
– The unique identifier for the specific quiz
Examples and Usage
Basic example – A simple way to use the ‘ays_quiz’ shortcode is to use an id parameter to specify the quiz you want to display. The id should be the unique identifier of the quiz.
[ays_quiz id=1 /]
Advanced examples
For more complex usage, you can combine the ‘ays_quiz’ shortcode with other WordPress shortcodes or HTML tags to customize the display of your quiz. For instance, you can wrap the ‘ays_quiz’ shortcode with a ‘div’ tag to apply custom CSS styling to the quiz container.
<div style="background-color: #f9f9f9; padding: 20px;">
[ays_quiz id=1 /]
</div>
You can also use the ‘ays_quiz’ shortcode within a WordPress post or page to display a quiz as part of your content. Just insert the shortcode where you want the quiz to appear.
<p>Here is a fun quiz for you:</p>
[ays_quiz id=1 /]
<p>Hope you enjoyed the quiz!</p>
Remember, the ‘ays_quiz’ shortcode will output the quiz specified by the id parameter. If the id is not valid or not provided, it will display a ‘Wrong shortcode initialized’ message.
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz', array($this, 'ays_generate_quiz_method'));
Shortcode PHP function:
function ays_generate_quiz_method($attr){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint(intval($attr['id'])) : null;
if (is_null($id)) {
$quiz_content = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_content);
}
$this->buttons_texts = $this->ays_set_quiz_texts($id);
$this->enqueue_styles();
$this->enqueue_scripts();
$quiz_content = $this->show_quiz($id);
return str_replace(array("\r\n", "\n", "\r"), '', $quiz_content);
}
Code file location:
quiz-maker/quiz-maker/public/class-quiz-maker-public.php
Quiz Maker [ays_all_results] Shortcode
The ‘ays_all_results’ shortcode from the Quiz Maker plugin generates a list of all quiz results. It enqueues necessary styles and scripts, and returns an HTML string of all results.
Shortcode: [ays_all_results]
Examples and Usage
Basic example – Display all results of a specific quiz by referencing its ID.
[ays_all_results id=1 /]
Advanced examples include:
Using the shortcode to display all results of a specific quiz by referencing its ID and limiting the number of results to 5.
[ays_all_results id=1 limit=5 /]
Using the shortcode to display all results of a specific quiz by referencing its ID, limiting the number of results to 5 and ordering them by the highest score.
[ays_all_results id=1 limit=5 order_by="score" /]
Using the shortcode to display all results of a specific quiz by referencing both ID and title. The results will first try to load by ID, but if not found, it will try to load by title.
[ays_all_results id=1 title="Quiz 1" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_all_results]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_all_results', array($this, 'ays_generate_all_results_method'));
Shortcode PHP function:
function ays_generate_all_results_method( $attr ) {
$this->enqueue_styles();
$this->enqueue_scripts();
$all_results_html = $this->ays_all_results_html( $attr );
return str_replace(array("\r\n", "\n", "\r"), '', $all_results_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-all-results-shortcode.php
Quiz Maker [ays_quiz_cat] Shortcode
The Quiz Maker shortcode is used to generate quizzes based on categories. It allows you to set display type, count, and layout of quizzes. The shortcode fetches quizzes from a specific category ID. If the ‘display’ attribute is set to ‘random’, it fetches a set number of random quizzes. The ‘layout’ attribute can be set to ‘list’ or ‘grid’. It then generates a quiz layout according to the set parameters.
Shortcode: [ays_quiz_cat]
Parameters
Here is a list of all possible ays_quiz_cat shortcode parameters and attributes:
id
– Unique identifier of the quiz categorydisplay
– Determines how quizzes are displayed, ‘all’ or ‘random’count
– Limits the number of quizzes displayedlayout
– Defines how quizzes are arranged, ‘list’ or ‘grid’
Examples and Usage
Basic example – Displaying a quiz category by referencing its ID.
[ays_quiz_cat id=3 /]
Advanced examples
Displaying a quiz category by its ID, with a specific layout and a set number of quizzes.
[ays_quiz_cat id=3 layout='grid' count=5 /]
Displaying a random quiz from a specific category by its ID.
[ays_quiz_cat id=3 display='random' /]
Displaying a random quiz from a specific category by its ID, with a specific layout and a set number of quizzes.
[ays_quiz_cat id=3 display='random' layout='grid' count=5 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_cat]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_cat', array($this, 'ays_generate_quiz_categories_method'));
Shortcode PHP function:
function ays_generate_quiz_categories_method($attr){
global $wpdb;
$id = (isset($attr['id'])) ? absint(intval($attr['id'])) : null;
if (is_null($id)) {
$display_questions_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), '', $display_questions_html);
}
$display = ( isset($attr['display']) && $attr['display'] != '' ) ? sanitize_text_field($attr['display']) : 'all';
$count = ( isset($attr['count']) && $attr['count'] != '' ) ? absint(sanitize_text_field($attr['count'])) : 5;
$layout = ( isset($attr['layout']) && $attr['layout'] != '' ) ? sanitize_text_field($attr['layout']) : 'list';
$category = Quiz_Maker_Public::get_quiz_category_by_id($id);
if (isset($category['published']) && $category['published'] == 0) {
$display_questions_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), '', $display_questions_html);
}
$sql = "SELECT id FROM {$wpdb->prefix}aysquiz_quizes WHERE quiz_category_id = ". $id ." AND published=1 ";
$content = "";
$random_quiz_id = array();
if ($display === 'random') {
$sql .= " ORDER BY RAND() LIMIT ".$count;
$result = $wpdb->get_results($sql, 'ARRAY_A');
$all_quiz_count = count($result);
foreach ($result as $val) {
$val = absint(intval($val['id']));
$random_quiz_id[] = $val;
}
}else{
$result = $wpdb->get_results($sql, 'ARRAY_A');
$all_quiz_count = count($result);
foreach ($result as $val) {
$val = absint(intval($val['id']));
$random_quiz_id[] = $val;
}
}
$conteiner_flex_class = '';
if ($layout == 'grid') {
$conteiner_flex_class = 'ays-quiz-category-container-flex';
}
$category_title = (isset($category['title']) && $category['title'] != '') ? stripslashes($category['title']) : "";
$content .= "<h2 class='ays-quiz-category-title' style='text-align:center;'>
<span style='font-size:3rem;'>". __( "Category", $this->plugin_name) .":</span>
<em>". $category_title ."</em>
</h2>";
if(isset($category['description']) && $category['description'] != ''){
$content .= "<div class='ays-quiz-category-description'>". do_shortcode(stripslashes(wpautop($category['description']))) ."</div>";
}
$content .= "<div class='ays-quiz-category-container ". $conteiner_flex_class ."'>";
foreach ($random_quiz_id as $quiz_id) {
$content .= "<div class='ays-quiz-category-item'>";
$shortcode = "[ays_quiz id='".$quiz_id."']";
$content .= do_shortcode($shortcode);
$content .= "</div>";
}
$content .= "</div>";
return str_replace(array("\r\n", "\n", "\r"), '', $content);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-category-shortcode.php
Quiz Maker [ays_quiz_cat_title] Shortcode
The AYS Quiz Maker shortcode is a powerful tool that generates quiz category titles. It takes an ID as an attribute and returns the corresponding quiz category title. The PHP function ‘ays_generate_quiz_categories_title_method’ is responsible for this operation. If the ID is null or zero, it returns an empty string. If the ID is valid, it generates a unique ID and utilizes it to retrieve the quiz category title.
Shortcode: [ays_quiz_cat_title]
Parameters
Here is a list of all possible ays_quiz_cat_title shortcode parameters and attributes:
id
– Specifies the unique identifier for the quiz category
Examples and Usage
Basic example – A simple usage of the shortcode to display the title of a quiz category using its ID.
[ays_quiz_cat_title id=1 /]
Advanced examples
Using the shortcode without specifying an ID. In this case, the shortcode will return an empty string.
[ays_quiz_cat_title /]
Using the shortcode with a non-existent ID. Similar to the previous example, the shortcode will return an empty string if the category does not exist.
[ays_quiz_cat_title id=9999 /]
Using the shortcode with an ID that’s not a number. In this case, the shortcode will sanitize the ID and return an empty string.
[ays_quiz_cat_title id="not a number" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_cat_title]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_cat_title', array($this, 'ays_generate_quiz_categories_title_method'));
Shortcode PHP function:
function ays_generate_quiz_categories_title_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_category_title = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_title);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_category_title = $this->ays_generate_cat_title_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_title);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-category-shortcode.php
Quiz Maker [ays_quiz_cat_description] Shortcode
The AYS Quiz Maker shortcode is used to generate a description for quiz categories. It first checks if an ID is set, then generates a unique ID. The description is then created and returned.
Shortcode: [ays_quiz_cat_description]
Parameters
Here is a list of all possible ays_quiz_cat_description shortcode parameters and attributes:
id
– The unique identifier code for the quiz category
Examples and Usage
Basic example – A shortcode to generate and display the description of a quiz category by its ID.
[ays_quiz_cat_description id=1 /]
Advanced examples
Generating and displaying the description of a quiz category by its ID, while also defining a unique ID for the shortcode instance. The unique ID can be used for CSS styling or JavaScript targeting.
[ays_quiz_cat_description id=2 unique_id="my_unique_id" /]
Using the shortcode without any ID. In this case, the shortcode will return an empty string. This can be useful if you want to conditionally display a quiz category description, and you know that there might be cases where the ID is not available or valid.
[ays_quiz_cat_description /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_cat_description]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_cat_description', array($this, 'ays_generate_quiz_categories_description_method'));
Shortcode PHP function:
function ays_generate_quiz_categories_description_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_category_description = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_description);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_category_description = $this->ays_generate_cat_description_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_description);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-category-shortcode.php
Quiz Maker [ays_display_questions] Shortcode
The ‘ays_display_questions’ shortcode from the Quiz Maker plugin is designed to generate and display quiz questions. The shortcode retrieves a specific question ID. If the ID is invalid or not provided, it displays an error message. It then generates the HTML for displaying the questions, removing any line breaks for clean formatting.
Shortcode: [ays_display_questions]
Parameters
Here is a list of all possible ays_display_questions shortcode parameters and attributes:
id
– The unique identifier for the specific set of questions
Examples and Usage
Basic example – A shortcode that displays the questions of a quiz by referencing the ID of the quiz.
[ays_display_questions id=1 /]
Advanced examples
Using the shortcode to display the questions of a quiz by referencing the ID. If the ID is not found or not valid, it will display a message saying “Wrong shortcode initialized”.
[ays_display_questions id="quiz1" /]
Using the shortcode without any ID, it will also display the “Wrong shortcode initialized” message, as the ID is a required field.
[ays_display_questions /]
Note that the shortcode is case-sensitive, so using ‘ID’ instead of ‘id’ will not work and will also return the “Wrong shortcode initialized” message.
[ays_display_questions ID=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_display_questions]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_display_questions', array($this, 'ays_generate_display_questions_method'));
Shortcode PHP function:
function ays_generate_display_questions_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint(intval($attr['id'])) : null;
if (is_null($id)) {
$display_questions_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), '', $display_questions_html);
}
$display_questions_html = $this->ays_display_questions_html( $attr );
return str_replace(array("\r\n", "\n", "\r"), '', $display_questions_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-display-questions-shortcode.php
Quiz Maker [ays_quiz_avg_score] Shortcode
The AYS Quiz shortcode is a handy tool that generates the average score of a specific quiz. This shortcode fetches the ‘id’ attribute and checks its validity. If the ‘id’ is null or 0, it returns an error message. Otherwise, it generates a unique id for the quiz and returns the average quiz score.
Shortcode: [ays_quiz_avg_score]
Parameters
Here is a list of all possible ays_quiz_avg_score shortcode parameters and attributes:
id
– Unique identifier for the specific quiz
Examples and Usage
Basic example – A shortcode to display the average score of a specific quiz by referencing the quiz ID
[ays_quiz_avg_score id=1 /]
Advanced examples
Using the shortcode to display the average score of a specific quiz by referencing the quiz ID and customizing the text color when wrong shortcode initialized.
[ays_quiz_avg_score id=1 wrong_shortcode_text_color="blue" /]
Using the shortcode to display the average score of a specific quiz by referencing the quiz ID and customizing the unique ID to ensure the uniqueness of the shortcode in case of multiple usage in the same page.
[ays_quiz_avg_score id=1 unique_id="quiz123" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_avg_score]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_avg_score', array($this, 'ays_generate_avg_score_method'));
Shortcode PHP function:
function ays_generate_avg_score_method( $attr ){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$user_progress_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_progress_html);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;
$avg_score_quiz_html = $this->ays_quiz_avg_score_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $avg_score_quiz_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_passed_users_count] Shortcode
The AYS Quiz shortcode is designed to generate a count of users who have successfully passed a specific quiz. This shortcode takes an ‘id’ attribute, representing the quiz ID. If the ID is valid, it returns the count of users who passed the quiz. If the ID is invalid or not provided, it returns an error message. The shortcode also generates a unique ID for each instance, ensuring no conflicts occur.
Shortcode: [ays_quiz_passed_users_count]
Parameters
Here is a list of all possible ays_quiz_passed_users_count shortcode parameters and attributes:
id
– The specific identification number of the quiz
Examples and Usage
Basic example – A straightforward use of the shortcode to display the count of users who passed the quiz with a specified ID.
[ays_quiz_passed_users_count id=1 /]
Advanced examples
Using the shortcode with an invalid or non-existent ID. In this case, the shortcode will return an error message indicating that the shortcode was initialized incorrectly.
[ays_quiz_passed_users_count id=9999 /]
Using the shortcode without an ID attribute. This will also result in an error message, as the ID is a required parameter for the shortcode to function properly.
[ays_quiz_passed_users_count /]
Using the shortcode with a non-integer ID. This will also return an error message, as the ID must be an integer.
[ays_quiz_passed_users_count id="abc" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_passed_users_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_passed_users_count', array($this, 'ays_generate_passed_users_count_method'));
Shortcode PHP function:
function ays_generate_passed_users_count_method( $attr ){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$passed_users_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;
$passed_users_count_html = $this->ays_quiz_passed_users_count_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_failed_users_count_by_score] Shortcode
The AYS Quiz shortcode is a custom function that displays the count of users who failed a specific quiz based on their scores. It takes the ‘id’ attribute to identify the quiz. If no ‘id’ is provided or it’s incorrect, an error message is displayed. The shortcode generates a unique id for each instance, ensuring no conflicts occur. Finally, it returns the count of failed users in HTML format, replacing any line breaks with a single newline character for cleaner output.
Shortcode: [ays_quiz_failed_users_count_by_score]
Parameters
Here is a list of all possible ays_quiz_failed_users_count_by_score shortcode parameters and attributes:
id
– A unique number that identifies the specific quiz.
Examples and Usage
Basic example – Show the count of failed users by score for a specific quiz.
[ays_quiz_failed_users_count_by_score id=1 /]
Advanced examples
Display the count of failed users by score for a specific quiz, and if the quiz id is not found or incorrect, it will show a warning message.
[ays_quiz_failed_users_count_by_score id=9999 /]
Note: In this case, ‘9999’ is an id that does not exist, so the shortcode will return a warning message. Replace ‘9999’ with the actual id of the quiz you want to display the failed users count for.
Another advanced usage could be to use this shortcode within PHP code. This is useful when you want to include the failed users count in a custom template or within a theme file. Here’s how to do it:
<?php echo do_shortcode('[ays_quiz_failed_users_count_by_score id=1 /]'); ?>
In this example, the shortcode is wrapped in a ‘do_shortcode’ function, which allows it to be executed within a PHP file. Replace ‘1’ with the id of the quiz you want to display the failed users count for.
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_failed_users_count_by_score]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_failed_users_count_by_score', array($this, 'ays_generate_failed_users_count_by_score_method'));
Shortcode PHP function:
function ays_generate_failed_users_count_by_score_method( $attr ){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$failed_users_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $failed_users_count_html);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;
$failed_users_count_html = $this->ays_quiz_failed_users_count_by_score_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $failed_users_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_passed_users_count_by_score] Shortcode
The ‘ays_quiz_passed_users_count_by_score’ shortcode from the Quiz Maker plugin generates a count of users who have passed a specific quiz based on their score. It takes a quiz ‘id’ as an attribute and returns an error message if the ‘id’ is not provided, invalid, or equals to 0. It then generates a unique id for each quiz and returns a count of passed users in HTML format.
Shortcode: [ays_quiz_passed_users_count_by_score]
Parameters
Here is a list of all possible ays_quiz_passed_users_count_by_score shortcode parameters and attributes:
id
– The unique identifier of the quiz.
Examples and Usage
Basic example – A shortcode to display the count of passed users by score for a specific quiz, which is identified by its ID.
[ays_quiz_passed_users_count_by_score id=1 /]
Advanced examples
Using the shortcode to display the count of passed users by score for multiple quizzes. Here, the IDs of the quizzes are separated by commas.
[ays_quiz_passed_users_count_by_score id="1,2,3" /]
Using the shortcode to display the count of passed users by score for a specific quiz, with an additional parameter to customize the message displayed when the shortcode is incorrectly initialized.
[ays_quiz_passed_users_count_by_score id=1 wrong_shortcode_text="Please check the shortcode." /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_passed_users_count_by_score]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_passed_users_count_by_score', array($this, 'ays_generate_passed_users_count_by_score_method'));
Shortcode PHP function:
function ays_generate_passed_users_count_by_score_method( $attr ){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$passed_users_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;
$passed_users_count_html = $this->ays_quiz_passed_users_count_by_score_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_passed_quizzes_count] Shortcode
The ‘ays_quiz_user_passed_quizzes_count’ shortcode from Quiz Maker plugin displays the count of quizzes passed by a logged-in user. It generates a unique ID for each instance and returns the count in HTML format.
Shortcode: [ays_quiz_user_passed_quizzes_count]
Examples and Usage
Basic example – displays the count of quizzes passed by the current logged-in user.
[ays_quiz_user_passed_quizzes_count /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_passed_quizzes_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_passed_quizzes_count', array($this, 'ays_generate_user_passed_quizzes_count_method'));
Shortcode PHP function:
function ays_generate_user_passed_quizzes_count_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$passed_quizzes_count_html = "";
if(is_user_logged_in()){
$passed_quizzes_count_html = $this->ays_generate_user_passed_quizzes_count_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_quizzes_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_all_passed_quizzes_count] Shortcode
The ‘ays_quiz_user_all_passed_quizzes_count’ shortcode is a function in the Quiz Maker plugin. It generates a unique count of all quizzes a user has successfully completed. This shortcode works when a user is logged in, returning a list of passed quizzes. It replaces all types of line breaks with a newline character in the returned HTML.
Shortcode: [ays_quiz_user_all_passed_quizzes_count]
Examples and Usage
Basic example – A shortcode that displays the count of all passed quizzes by a logged-in user.
[ays_quiz_user_all_passed_quizzes_count]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_all_passed_quizzes_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_all_passed_quizzes_count', array($this, 'ays_generate_user_all_passed_quizzes_count_method'));
Shortcode PHP function:
function ays_generate_user_all_passed_quizzes_count_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$all_passed_quizzes_count_html = "";
if(is_user_logged_in()){
$all_passed_quizzes_count_html = $this->ays_generate_user_all_passed_quizzes_count_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $all_passed_quizzes_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_first_name] Shortcode
The Ays Quiz shortcode is designed to generate a unique user’s first name. When implemented, it checks if the user is logged in and then generates the user’s first name in HTML format. Functionality is ensured by the PHP function ays_generate_user_first_name_method(). This function creates a unique ID, checks if the user is logged in, and then calls the ays_generate_user_first_name_html() method. The result is a user-friendly way to personalize content for logged-in users.
Shortcode: [ays_quiz_user_first_name]
Examples and Usage
Basic example – Generate the logged-in user’s first name with the shortcode.
[ays_quiz_user_first_name /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_first_name]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_first_name', array($this, 'ays_generate_user_first_name_method'));
Shortcode PHP function:
function ays_generate_user_first_name_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_first_name_html = "";
if(is_user_logged_in()){
$user_first_name_html = $this->ays_generate_user_first_name_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_first_name_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_last_name] Shortcode
The AYS Quiz Maker shortcode generates a unique ID for logged-in users and returns their last name. It uses PHP’s uniqid() function for the unique ID generation. This shortcode displays the last name of the current user, provided they are logged in. It’s useful for personalizing quiz experiences.
Shortcode: [ays_quiz_user_last_name]
Examples and Usage
Basic example – A simple usage of the shortcode to generate and display the last name of the currently logged in user.
[ays_quiz_user_last_name]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_last_name]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_last_name', array($this, 'ays_generate_user_last_name_method'));
Shortcode PHP function:
function ays_generate_user_last_name_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_last_name_html = "";
if(is_user_logged_in()){
$user_last_name_html = $this->ays_generate_user_last_name_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_last_name_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_nickname] Shortcode
The ‘ays_quiz_user_nickname’ shortcode is a unique feature of the Quiz Maker plugin. It generates a unique nickname for logged-in users participating in quizzes. The PHP code behind this creates a unique ID for each user and checks if they are logged in. If they are, it generates a custom nickname HTML for them. This unique nickname enhances user interaction and personalization.
Shortcode: [ays_quiz_user_nickname]
Examples and Usage
Basic example – A simple shortcode that displays the user’s nickname if the user is logged in.
[ays_quiz_user_nickname]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_nickname]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_nickname', array($this, 'ays_generate_user_nickname_method'));
Shortcode PHP function:
function ays_generate_user_nickname_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_nickname_html = "";
if(is_user_logged_in()){
$user_nickname_html = $this->ays_generate_user_nickname_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_nickname_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_display_name] Shortcode
The AYS Quiz Maker shortcode is designed to generate a unique user display name. This shortcode creates a unique ID for each user and checks if the user is logged in. If so, it generates a user display name HTML. This HTML is then returned after replacing all types of line breaks with a newline character.
Shortcode: [ays_quiz_user_display_name]
Examples and Usage
Basic example – The shortcode displays the username of the currently logged-in user. If no user is logged in, it will not display anything.
[ays_quiz_user_display_name]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_display_name]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_display_name', array($this, 'ays_generate_user_display_name_method'));
Shortcode PHP function:
function ays_generate_user_display_name_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_display_name_html = "";
if(is_user_logged_in()){
$user_display_name_html = $this->ays_generate_user_display_name_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_display_name_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_email] Shortcode
The ‘ays_quiz_user_email’ shortcode is used to generate unique IDs and user email HTML for logged-in users. This shortcode is part of a quiz-maker plugin. In the PHP code, the shortcode function ‘ays_generate_user_email_method’ creates a unique ID for each instance. If a user is logged in, it generates an HTML string for the user’s email.
Shortcode: [ays_quiz_user_email]
Examples and Usage
Basic Example – A shortcode to generate a unique user email in a quiz plugin.
[ays_quiz_user_email /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_email]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_email', array($this, 'ays_generate_user_email_method'));
Shortcode PHP function:
function ays_generate_user_email_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_email_html = "";
if(is_user_logged_in()){
$user_email_html = $this->ays_generate_user_email_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_email_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_duration] Shortcode
The AYS Quiz shortcode is a unique function that generates a user quiz duration method. It creates a unique ID for each user and checks if the user is logged in. The shortcode then generates a user quiz duration HTML, which is returned after replacing any kind of line breaks with a new line. This ensures smooth formatting.
Shortcode: [ays_quiz_user_duration]
Examples and Usage
Basic example – The shortcode generates the duration of a user’s quiz when the user is logged in.
[ays_quiz_user_duration]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_duration]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_duration', array($this, 'ays_generate_user_quiz_duration_method'));
Shortcode PHP function:
function ays_generate_user_quiz_duration_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_quiz_duration = "";
if(is_user_logged_in()){
$user_quiz_duration = $this->ays_generate_user_quiz_duration_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_quiz_duration);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_creation_date] Shortcode
The ‘ays_quiz_creation_date’ shortcode is a part of the Quiz Maker plugin. It generates the date when the quiz was created. This shortcode first checks if a valid ‘id’ is provided. If not, it returns an empty string. If a valid ‘id’ is present, it generates a unique id for the quiz. The shortcode then checks if the user is logged in. If the user is logged in, it calls the ‘ays_generate_quiz_creation_date_html’ function with the ‘id’ as an argument, which will return the quiz creation date.
Shortcode: [ays_quiz_creation_date]
Parameters
Here is a list of all possible ays_quiz_creation_date shortcode parameters and attributes:
id
– The unique identifier of the quiz
Examples and Usage
Basic example – The shortcode below is used to generate the creation date of a quiz by referencing its ID.
[ays_quiz_creation_date id=1 /]
Advanced examples
Using the shortcode to generate the creation date of a quiz by referencing its ID, but only if the user is logged in. If the user is not logged in, the shortcode will return an empty string.
[ays_quiz_creation_date id=1 /]
Using the shortcode to generate the creation date of a quiz by referencing its ID. If the ID is not provided or is 0, the shortcode will return an empty string.
[ays_quiz_creation_date /]
Using the shortcode to generate the creation date of a quiz by referencing its ID. If the ID is not valid (not an integer or less than 1), the shortcode will return an empty string.
[ays_quiz_creation_date id='invalid' /]
Note: The ‘ays_quiz_creation_date’ shortcode requires the ‘id’ attribute to function properly. The ‘id’ attribute should be the ID of the quiz for which you want to generate the creation date.
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_creation_date]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_creation_date', array($this, 'ays_generate_quiz_creation_date_method'));
Shortcode PHP function:
function ays_generate_quiz_creation_date_method( $attr ){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_creation_date = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_creation_date);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_creation_date = "";
if(is_user_logged_in()){
$quiz_creation_date = $this->ays_generate_quiz_creation_date_html( $id );
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_creation_date);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_current_author] Shortcode
The AYS Quiz shortcode is a feature that generates the name of the current quiz author. It checks if a user is logged in and if so, it returns the author’s name. This shortcode uses the PHP function ‘ays_generate_current_quiz_author_method’ to sanitize the ‘id’ attribute and generate a unique id for each instance.
Shortcode: [ays_quiz_current_author]
Parameters
Here is a list of all possible ays_quiz_current_author shortcode parameters and attributes:
id
– Unique ID used to identify the specific quiz
Examples and Usage
Basic example – Showcases a straightforward usage of the shortcode to generate the current quiz author. The shortcode requires the ‘id’ attribute which represents the quiz id.
[ays_quiz_current_author id=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_current_author]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_current_author', array($this, 'ays_generate_current_quiz_author_method'));
Shortcode PHP function:
function ays_generate_current_quiz_author_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_author = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_author);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_author = "";
if(is_user_logged_in()){
$quiz_author = $this->ays_generate_current_quiz_author_html( $id );
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_author);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_questions_count] Shortcode
The Ays Quiz Questions Count shortcode is used to generate the count of questions in a quiz. It takes an ‘id’ attribute specifying the quiz and returns the question count. This shortcode uses a PHP function ‘ays_generate_questions_count_method’ which sanitizes the ‘id’ input and checks its validity. If the ‘id’ is null or zero, it returns an empty string. If valid, it generates a unique id and calls the ‘ays_generate_questions_count_html’ function to get the count of questions in the specified quiz.
Shortcode: [ays_quiz_questions_count]
Parameters
Here is a list of all possible ays_quiz_questions_count shortcode parameters and attributes:
id
– The unique identifier for the specific quiz.
Examples and Usage
Basic example – A shortcode to display the total question count in a specific quiz by referencing the quiz ID.
[ays_quiz_questions_count id=1 /]
Advanced examples
Using the shortcode to display the total question count in a specific quiz by referencing the quiz ID. If the quiz with the given ID is not found, it will return an empty string.
[ays_quiz_questions_count id=5 /]
Using the shortcode without any id. In this case, it will return an empty string because the id is a required parameter.
[ays_quiz_questions_count /]
Using the shortcode with a non-numeric id. Again, it will return an empty string because the id must be a positive integer.
[ays_quiz_questions_count id="quiz1" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_questions_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_questions_count', array($this, 'ays_generate_questions_count_method'));
Shortcode PHP function:
function ays_generate_questions_count_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_author = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_author);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_author = $this->ays_generate_questions_count_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_author);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_category_title] Shortcode
The ‘ays_quiz_category_title’ shortcode from Quiz Maker plugin generates the title of a specific quiz category. It sanitizes and validates the ‘id’ attribute, ensuring it’s a non-zero integer. If the ‘id’ is null or zero, it returns an empty string. Otherwise, it generates a unique id and retrieves the quiz category title based on the ‘id’. It then returns this title, replacing any carriage returns with a newline character.
Shortcode: [ays_quiz_category_title]
Parameters
Here is a list of all possible ays_quiz_category_title shortcode parameters and attributes:
id
– Identifier for the specific quiz category.
Examples and Usage
Basic example – A straightforward usage of the shortcode to display a quiz category title by referencing the ID.
[ays_quiz_category_title id=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_category_title]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_category_title', array($this, 'ays_generate_category_title_method'));
Shortcode PHP function:
function ays_generate_category_title_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_category_title = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_title);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_category_title = $this->ays_generate_category_title_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_title);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_category_description] Shortcode
The Ays Quiz Category Description shortcode is designed to generate a description for a specific quiz category. It uses the category ID as an attribute. If the ID is not provided or is zero, it returns an empty string. The function also generates a unique ID for each instance. The shortcode then calls another function to generate the HTML content for the category description, replacing any line breaks with a single newline character.
Shortcode: [ays_quiz_category_description]
Parameters
Here is a list of all possible ays_quiz_category_description shortcode parameters and attributes:
id
– The unique identifier of the quiz category
Examples and Usage
Basic example – A shortcode that displays the description of a quiz category using its ID.
[ays_quiz_category_description id=3 /]
Advanced examples
Using the shortcode to display the description of a quiz category by referencing the ID. If the ID is not found or is null, it will return an empty string.
[ays_quiz_category_description id=5 /]
Using the shortcode without an ID attribute. In this case, it will return an empty string as the ID is null.
[ays_quiz_category_description /]
Using the shortcode with an invalid ID. If the ID is not a valid number, it will be sanitized and the function will return an empty string.
[ays_quiz_category_description id="invalid" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_category_description]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_category_description', array($this, 'ays_generate_category_description_method'));
Shortcode PHP function:
function ays_generate_category_description_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_category_title = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_title);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_category_title = $this->ays_generate_category_description_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_category_title);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_question_categories_title] Shortcode
The Ays Quiz Question Categories Title shortcode is used to generate the title of a specific quiz question category. It uses the ID attribute to identify the category. The shortcode sanitizes the ID, ensuring it’s an integer, and returns an empty string if no valid ID is provided. It then generates a unique ID for each instance and calls a function to generate the HTML for the category title. The result is a clean, formatted category title, replacing any line breaks with a single “\n” character for consistency.
Shortcode: [ays_quiz_question_categories_title]
Parameters
Here is a list of all possible ays_quiz_question_categories_title shortcode parameters and attributes:
id
– Unique ID assigned to the quiz question category.
Examples and Usage
Basic example – A shortcode that generates a title for a specific quiz category by referencing its ID.
[ays_quiz_question_categories_title id=1 /]
Advanced examples
A shortcode that generates a title for a quiz category, but if the category is not found by its ID, it will return an empty string.
[ays_quiz_question_categories_title id=999 /]
A shortcode that generates a title for a quiz category. If the category is not found by its ID, it will return an empty string. In this example, we are using a non-existent category ID (0) to demonstrate this functionality.
[ays_quiz_question_categories_title id=0 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_question_categories_title]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_question_categories_title', array($this, 'ays_generate_question_categories_title_method'));
Shortcode PHP function:
function ays_generate_question_categories_title_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_question_category_title = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_question_category_title);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_question_category_title = $this->ays_generate_question_categories_title_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_question_category_title);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_question_categories_description] Shortcode
The AYS Quiz Question Categories Description shortcode is used to generate a unique description for each quiz category. It checks whether the ‘id’ attribute is set and valid, and if so, it generates a unique ID and uses it to create the description.
Shortcode: [ays_quiz_question_categories_description]
Parameters
Here is a list of all possible ays_quiz_question_categories_description shortcode parameters and attributes:
id
– Unique ID for the specific quiz question category
Examples and Usage
Basic example – A straightforward application of the shortcode to generate the description of a question category by its ID.
[ays_quiz_question_categories_description id=1 /]
Advanced examples
Utilizing the shortcode to generate the description of a question category by its ID and replacing newline characters with a space. If the category ID does not exist, it will return an empty string.
[ays_quiz_question_categories_description id=1 replace_newlines_with=" " /]
Using the shortcode to generate the description of a question category by its ID and replacing newline characters with a specified string. If the category ID does not exist, it will return the string ‘No description available’.
[ays_quiz_question_categories_description id=1 replace_newlines_with=" " empty_description="No description available" /]
Please note that in the provided PHP code, there is no handling for the ‘replace_newlines_with’ and ’empty_description’ attributes. You would need to modify the ‘ays_generate_question_categories_description_method’ function to support these features.
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_question_categories_description]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_question_categories_description', array($this, 'ays_generate_question_categories_description_method'));
Shortcode PHP function:
function ays_generate_question_categories_description_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$quiz_question_category_description = "";
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_question_category_description);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$quiz_question_category_description = $this->ays_generate_question_categories_description_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_question_category_description);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_roles] Shortcode
The ‘ays_quiz_user_roles’ shortcode is a feature of the Quiz Maker plugin. It generates a unique ID for each user session and checks if a user is logged in. If the user is logged in, the shortcode will generate and return the user roles in HTML format. It also replaces all types of line breaks with “\n” for uniformity.
Shortcode: [ays_quiz_user_roles]
Examples and Usage
Basic example – Allows to generate user roles based on the logged-in status of the user.
[ays_quiz_user_roles /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_roles]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_roles', array($this, 'ays_generate_user_roles_method'));
Shortcode PHP function:
function ays_generate_user_roles_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_email_html = "";
if(is_user_logged_in()){
$user_email_html = $this->ays_generate_user_roles_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_email_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [null] Shortcode
The Ays Quiz Unread Results Count shortcode is designed to generate a count of unread quiz results. It uses the shortcode: [ays_quiz_unread_results_count]. The shortcode checks if a quiz ID is provided and valid. If not, it displays an error message. If the ID is valid, it generates a unique ID and calls a function to create HTML for displaying the count of unread results. The final HTML is returned with all carriage returns replaced by new lines for better readability.
Shortcode: [null]
Parameters
Here is a list of all possible null shortcode parameters and attributes:
id
– Unique ID used to identify the specific quiz.
Examples and Usage
Basic example – A basic usage of the shortcode to display the count of unread results for a specific quiz by referencing its ID.
[ays_quiz_unread_results_count id=1 /]
Advanced examples
Using the shortcode to display the count of unread results for a specific quiz by referencing its ID. If the ID is not found or not provided, it will return a message indicating that the shortcode is initialized incorrectly.
[ays_quiz_unread_results_count id=0 /]
Using the shortcode without providing any ID. It will return a message indicating that the shortcode is initialized incorrectly.
[ays_quiz_unread_results_count /]
Using the shortcode with an ID that does not exist. It will return a message indicating that the shortcode is initialized incorrectly.
[ays_quiz_unread_results_count id=999 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [null]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_unread_results_count', array($this, 'ays_generate_unread_results_count_method'));
Shortcode PHP function:
function ays_generate_unread_results_count_method( $attr ){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$passed_users_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;
$passed_users_count_html = $this->ays_quiz_unread_results_count_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_read_results_count] Shortcode
The AYS Quiz Maker shortcode is designed to generate read results count. It fetches the results of a specific quiz based on its ID. If the ID is incorrect, it displays an error message. The shortcode then generates a unique ID for each instance, ensuring no conflicts occur. It finally returns the HTML for the read results count.
Shortcode: [ays_quiz_read_results_count]
Parameters
Here is a list of all possible ays_quiz_read_results_count shortcode parameters and attributes:
id
– Specifies the unique identifier of the quiz
Examples and Usage
Basic example – Displays the read results count of a quiz by referencing its ID.
[ays_quiz_read_results_count id=1 /]
Advanced examples
Displays the read results count of a quiz by referencing its ID. If the ID is not found, it will display an error message.
[ays_quiz_read_results_count id=100 /]
Displays the read results count of a quiz by referencing its ID. If the ID is not valid or null, it will display a custom error message.
[ays_quiz_read_results_count id=null /]
Please note that the ‘id’ attribute in the shortcode is necessary and it should match the ID of the quiz that you want to display the read results count for. If the ‘id’ attribute is not provided or if it does not match any existing quiz, the shortcode will not function as expected.
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_read_results_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_read_results_count', array($this, 'ays_generate_read_results_count_method'));
Shortcode PHP function:
function ays_generate_read_results_count_method( $attr ){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$read_results_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $read_results_count_html);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;
$read_results_count_html = $this->ays_quiz_read_results_count_html( $id );
return str_replace(array("\r\n", "\n", "\r"), "\n", $read_results_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_quizzes_count] Shortcode
The AYS Quiz shortcode is designed to generate a unique count of quizzes. It utilizes a unique ID for each count and replaces any potential line breaks in the HTML output.
Shortcode: [ays_quiz_quizzes_count]
Examples and Usage
Basic example – Displays the total count of quizzes on your website.
[ays_quiz_quizzes_count]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_quizzes_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_quizzes_count', array($this, 'ays_generate_quizzes_count_method'));
Shortcode PHP function:
function ays_generate_quizzes_count_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = 'count' . "-" . $unique_id;
$read_results_count_html = $this->ays_quiz_quizzes_count_html();
return str_replace(array("\r\n", "\n", "\r"), "\n", $read_results_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_user_website] Shortcode
The AYS Quiz Maker shortcode is used to generate a unique ID for a user’s website. When a user is logged in, it activates the HTML generator for the user’s website.
Shortcode: [ays_quiz_user_website]
Examples and Usage
Basic example – A simple usage of the ‘ays_quiz_user_website’ shortcode without any additional parameters.
[ays_quiz_user_website]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_user_website]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_user_website', array($this, 'ays_generate_user_website_method'));
Shortcode PHP function:
function ays_generate_user_website_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$user_email_html = "";
if(is_user_logged_in()){
$user_email_html = $this->ays_generate_user_website_html();
}
return str_replace(array("\r\n", "\n", "\r"), "\n", $user_email_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_all_results_count] Shortcode
The ‘ays_quiz_all_results_count’ shortcode is part of the Quiz Maker plugin. It generates a unique ID and outputs the total count of all quiz results. This shortcode is useful for displaying user-specific quiz statistics.
Shortcode: [ays_quiz_all_results_count]
Examples and Usage
Basic example – A straightforward usage of the shortcode to generate a count of all quiz results. This does not require any additional parameters.
[ays_quiz_all_results_count /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_all_results_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_all_results_count', array($this, 'ays_generate_quiz_all_results_count_method'));
Shortcode PHP function:
function ays_generate_quiz_all_results_count_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $unique_id;
$html = "";
// if(is_user_logged_in()){
$html = $this->ays_generate_quiz_all_results_count_html();
// }
return str_replace(array("\r\n", "\n", "\r"), "\n", $html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_question_categories_count] Shortcode
The AYS Quiz shortcode is a unique feature that generates a count of quiz question categories. It uses a unique ID for each count and replaces any line breaks in the HTML output with a newline character.
Shortcode: [ays_quiz_question_categories_count]
Examples and Usage
Basic example – The shortcode provided displays the count of quiz question categories. This is a simple usage example where no additional parameters are needed.
[ays_quiz_question_categories_count /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_question_categories_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_question_categories_count', array($this, 'ays_generate_quiz_question_categories_count_method'));
Shortcode PHP function:
function ays_generate_quiz_question_categories_count_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = 'count' . "-" . $unique_id;
$read_results_count_html = $this->ays_quiz_question_categories_count_html();
return str_replace(array("\r\n", "\n", "\r"), "\n", $read_results_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_avg_rate] Shortcode
The AYS Quiz Average Rate shortcode is designed to display the average rating of a specific quiz. It takes the quiz ID as an attribute and generates a unique ID. If the quiz ID is invalid, it returns an error message. The shortcode then calls the function ‘ays_quiz_avg_rate_html’ to create the HTML for displaying the average quiz rating.
Shortcode: [ays_quiz_avg_rate]
Parameters
Here is a list of all possible ays_quiz_avg_rate shortcode parameters and attributes:
id
– The specific number used to identify each quiz.
Examples and Usage
Basic example – A straightforward usage of the shortcode to generate the average rate of a quiz. This example only requires the ID of the quiz you want to generate the average rate for.
[ays_quiz_avg_rate id=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_avg_rate]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_avg_rate', array($this, 'ays_generate_quiz_avg_rate_method'));
Shortcode PHP function:
function ays_generate_quiz_avg_rate_method($attr){
$id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
if (is_null($id) || $id == 0 ) {
$read_results_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), "\n", $read_results_count_html);
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;
$read_results_count_html = $this->ays_quiz_avg_rate_html($id);
return str_replace(array("\r\n", "\n", "\r"), "\n", $read_results_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_all_questions_count] Shortcode
The AYS Quiz Maker shortcode is designed to generate a unique count of all quiz questions. . It uses a unique ID for each count, ensuring accuracy. The count is then formatted into HTML, removing any unnecessary line breaks for a clean output.
Shortcode: [ays_quiz_all_questions_count]
Examples and Usage
Basic example – Demonstrates the simplest usage of the shortcode, which displays the count of all questions in the quiz.
[ays_quiz_all_questions_count]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_all_questions_count]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_all_questions_count', array($this, 'ays_generate_all_questions_count_method'));
Shortcode PHP function:
function ays_generate_all_questions_count_method(){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = 'count' . "-" . $unique_id;
$all_questions_count_html = $this->ays_quiz_all_questions_count_html();
return str_replace(array("\r\n", "\n", "\r"), "\n", $all_questions_count_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-extra-shortcode.php
Quiz Maker [ays_quiz_most_popular] Shortcode
The ‘ays_quiz_most_popular’ shortcode is a part of the Quiz Maker plugin. This shortcode generates the most popular quizzes on your WordPress site. The PHP function ‘ays_generate_most_popular_method’ is invoked when this shortcode is used. It generates a unique ID and calls the ‘ays_quiz_most_popular_html’ function to create the HTML for the popular quizzes. The output is then formatted and returned.
Shortcode: [ays_quiz_most_popular]
Examples and Usage
Basic example – A straightforward usage of the ‘ays_quiz_most_popular’ shortcode to display the most popular quiz. The plugin will generate a unique id for each quiz, ensuring no conflicts occur.
[ays_quiz_most_popular id=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_most_popular]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_most_popular', array($this, 'ays_generate_most_popular_method'));
Shortcode PHP function:
function ays_generate_most_popular_method( $attr ){
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = "-" . $unique_id;
$quiz_most_popular_html = $this->ays_quiz_most_popular_html( $attr );
return str_replace(array("\r\n", "\n", "\r"), "\n", $quiz_most_popular_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-most-popular-shortcode.php
Quiz Maker [ays_quiz_all_results] Shortcode
The AYS Quiz All Results shortcode is a tool that generates a comprehensive overview of all quiz results. It works by displaying results based on the ID provided. If the ID is missing or incorrect, it will display an error message. The shortcode also ensures that necessary styles and scripts are loaded for the proper display of results.
Shortcode: [ays_quiz_all_results]
Parameters
Here is a list of all possible ays_quiz_all_results shortcode parameters and attributes:
id
– The specific identifier of the quiz results to be displayed.
Examples and Usage
Basic example – A straightforward usage of the shortcode to display the results of a specific quiz by providing the quiz ID.
[ays_quiz_all_results id=3 /]
Advanced examples
Using the shortcode to display the results of a quiz by referencing the ID. If the quiz with the given ID is not found, a message “Wrong shortcode initialized” will be displayed in red text.
[ays_quiz_all_results id=9999 /]
Another example is using the shortcode without providing any ID. This will also result in a “Wrong shortcode initialized” message, as the ID is a required attribute for the shortcode.
[ays_quiz_all_results /]
Please note that the ‘ays_quiz_all_results’ shortcode is designed to work with numerical IDs only. Providing a non-numerical ID will result in the “Wrong shortcode initialized” message.
[ays_quiz_all_results id="quiz1" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ays_quiz_all_results]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('ays_quiz_all_results', array($this, 'ays_generate_quiz_all_results_method'));
Shortcode PHP function:
function ays_generate_quiz_all_results_method( $attr ) {
$id = (isset($attr['id']) && $attr['id'] != '') ? absint(intval($attr['id'])) : null;
if (is_null($id)) {
$quiz_all_results_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
return str_replace(array("\r\n", "\n", "\r"), '', $quiz_all_results_html);
}
$this->enqueue_styles();
$this->enqueue_scripts();
$quiz_all_results_html = $this->ays_quiz_all_results_html( $id );
return str_replace(array("\r\n", "\n", "\r"), '', $quiz_all_results_html);
}
Code file location:
quiz-maker/quiz-maker/public/partials/class-quiz-maker-quiz-all-results-shortcode.php
Conclusion
Now that you’ve learned how to embed the Quiz Maker 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