Quiz Notifications Documentation

A content tab, or simply a ‘tab’, is an additional panel of information that appears when you click on something related in your course. This could include notes about the lesson topic or helpful tools and links for students.

LearnDash’s ‘Learn Dash Content Tabs Filter’ snippet makes it easy to add these extra resources to your course. Instead of using the materials tab in your course settings, you can use code to dynamically add content tabs. With just a few small adjustments, you can customize the code to fit your needs and streamline the process.

Enhance your quizzes with the ‘Quiz Results’ tab using the modified code below. This snippet, designed for use with the ‘Quiz Notifications for LearnDash Plugin‘, will insert the [elc_last_quiz …] shortcode into every course, lesson, topic, and quiz page, providing an easy way to access quiz results.

When will the ‘Quiz Results’ tab displayed?

After successfully completing a quiz, proceed to the next step and return later to find the ‘Quiz Results’ tab now visible.

  • Insert the following code in your themes custom functions.php file or use a plugin called “Code snippets”.
  • A basic knowledge of PHP is required to modify the code.              
/**
 * Example usage for learndash_content_tabs filter.
 * @SEE: https://developers.learndash.com/hook/learndash_content_tabs/
 *
 * This snippet will add the tab with Last Quiz shortcode output on all: course, lesson, topic pages,
 * provided there are quiz results. 
 */
add_filter(
    'learndash_content_tabs',
    function ( $tabs = array(), $context = '', $course_id = 0, $user_id = 0 ) {

        // Add optional logic to show the custom tab only on certain courses.
//        if( 123 !== $course_id ) {
//            return $tabs;
//        }

        // Check if Quiz Notifications for LearnDash plugin is actived.
        if( ! function_exists( 'elc_ldquiz_last_quiz_callback' ) ){
            return $tabs;
        }

        // List of content types to show the Tab and the Last Quiz. 
        // You can comment or uncomment content types for which the tab will be shown. 
        // Below will show the tab on lesson and topic pages only. 
        $elc_context = array(
//            'course',
            'lesson',
            'topic',
        //    'quiz',
        );

        // If this is a post type we want to show Last Quiz, test if there is quiz results to render.
        if( in_array( $context, $elc_context ) ) {
            // Test for timespent only.
            $shortcode_atts = array(
                'show' => "timespent",
            );
            $elc_test = elc_ldquiz_last_quiz_callback( $shortcode_atts );
        }

        // Add our Custom Last Quiz Tab.
        if( ! empty( $elc_test ) && ! isset( $tabs[ 'lastquiz' ] ) ) {
            // show attribute values.
            // The quiz results will be printed in the order as in array.
            $show_ar = array(
                'custom_fields',
                'quiz_title',
                'breadcrumbs',
                'timespent',
                'cat_score',
                'overall_score',
                'result_message',
                'questions_answers',
            );

            // Last Quiz shortcode attributes.
            // Default values for parameters: 
            //             'collapsible'     => false,
            //             'show_essay'      => false,
            //             'comments'        => false,
            //             'show_correct'    => true,
            //             'show_points'     => true,
            //             'answer_feedback' => false,
            //             'question_cat'    => false,
            //             'breadcrumbs'     => false,
            //             'print_button'    => false,
            //
            $shortcode_atts = array(
                'show' => implode( ',', $show_ar ),
                'question_cat',
                'show_essay',
                'comments',
                'answer_feedback' => true,
                'show_points' => false,
            );

            // Get the HTML Last Quiz results.
            $elc_content = elc_ldquiz_last_quiz_callback( $shortcode_atts );

            // For print button uncomment line below.
            $elc_content = elc_ldquiz_print_callback( '', $elc_content );

            $tabs[ 'lastquiz' ] = array(
                'id'      => 'lastquiz',
                // The value here is to a CSS class you control to show an icon.
                'icon'    => 'ld-downloads-icon',
                'label'   => 'Quiz Results',
                'content' => $elc_content,
            );
        }

        // Always return $tabs.
        return $tabs;
    },
    30,
    4
);

Notifications Shortcode

[elc_ldquiz_notifications]

Notifications shortcode is to be used only in ‘quiz related notifications’, created with ‘LearnDash LMS Notifications’ addon. The shortcode enables to output additional information that is not supported by ‘LearnDash LMS Notifications’. In addition to ‘questions and answers’ the shortcode can output other information described in Quiz Results Display LearnDash documentation. 

Example:

[elc_ldquiz_notifications show=”questions_answers” question_cat=”true” show_essay]

For description of attributes and values refer to Common Shortcode Attributes section.

Above example will generate the html output of questions and user answers, including indication of correct/incorrect, points scored, question category.
The essay text is included – refer to show_essay attribute documentation for limitations.
Because the requirement is to generate html for the email, the CSS and JS scripts cannot be used. The output uses inline CSS styles for decorations.

Last Quiz Shortcode

 [elc_last_quiz]

Last Quiz shortcode – added by popular demand.

The ‘last quiz’ shortcode can be inserted into the content of any post (with exception of the LearnDash LMS Notifications).
As per name ‘last quiz’, the shortcode will output quiz results for the last attempt taken by the user.
The shortcode does query results from LearnDash statistics within the scope of LearnDash course, lesson, topic and/or global scope. 

The ‘last quiz’ provides the same functionality as ‘notifications shortcodes’.
Because the shortcode is to generate html for site pages, it provides extra functionality.
The html tags have ‘class’ attribute to allow use of the CSS stylesheets for decorations.
In addition the shortcode output can be collapsible and printed by itself rather than printing the entire page (see print_button attribute). 

Because the ‘last quiz’ shortcode is executed after the quiz has been completed by the user, it does not require the LearnDash LMS Notifications addon. Instead we did provide the attributes (course, lesson, topic and quiz ID) in order to create adequate scope using the same logic as creating notification in LearnDash LMS Notifications addon. Refer to: Notifications Add-On – LearnDash Support, Email Trigger
If the shortcode is inserted in LearnDash course, lesson, topic and/or quiz it is not necessary to use course_id, lesson_id, topic_id or quiz_id attributes. The scope will be defined by the context of the post where the shortcode is inserted. 

The user ID is assumed to be the ID of the currently logged-in user. For security and privacy reasons we do not include the attribute for the user ID. 

Example:

[elc_last_quiz show=”questions_answers” question_cat=”true” show_essay collapsible]

For shortcode attributes, description and values refer to Common Shortcode Attributes and Additional Attributes: Last Quiz Shortcode section. (use anchor)

Last Quiz Print Shortcode

[elc_last_quiz_print] … [/elc_last_quiz_print]

Last Quiz Print shortcode – a helper shortcode to facilitate printing a part of the post (quiz results) rather than entire post or page. This shortcode is an alternative to print_button attribute.

The shortcode can be used on any page or post (with exception of the LearnDash LMS Notifications).

The shortcode inserts a printer icon. Clicking the icon opens browser print dialog. Only content between opening and closing shortcode will be printed.

Example:

[elc_last_quiz_print] The text and or shortcode(s) to be printed [/elc_last_quiz_print] This shortcode has no attributes.   

Shortcode Attributes

The attributes supported in both [elc_ldquiz_notifications] and [elc_last_quiz] shortcode:

  • show (required)
    This attribute must be set to one of following values: 
    • custom_fields
      Custom Fields are set in quiz settings. See LeadnDash documentation: Quiz Custom Fields
    • overall_score
      Overall Score – message displayed at quiz results after user clicks ‘Finish Quiz’ button,
      e.g.: You have reached 10 of 20 point(s), (50%)
      See LeadnDash documentation: Custom Results Display
    • result_message
      Result Message(s) are configured in quiz settings.
      See LeadnDash documentation: Quiz Result Message(s)
    • cat_score
      Category Score is configured at quiz settings.
      See LeadnDash documentation: Custom Results Display
    • timespent
      Time Spent by user while taking the quiz.
      See LeadnDash documentation: Custom Results Display
    • questions_answers
      Itemized list of questions and user answers.
  • answer_feedback (default false) (NEW)
    Show Correct / Incorrect Messages for the questions.
    See LeadnDash documentation: Correct / Incorrect Messages
    NOTE: This attribute does take effect only when show questions_answers is present.
  • show_essay (default false)
    This attribute takes effect when using show=”questions_answers”.
    By default the essay responses entered by the user are not added, instead the ‘view’ link to the post with user response will be included. If show essay attribute is present the essay test will be included if the essay question is set to type of Text Box’,
    See LeadnDash documentation: Essay / Open Answer
  • comments (default false) (NEW)
    Show comments for the essay post.
    NOTE: This attribute does take effect only when show_essay is present.
  • show_correct (default true)
    This attribute takes effect when using show=”questions_answers”. By default the user answers will be marked as correct or incorrect (wherever applicable). If show_correct attribute is included and is set to false or 0, the indication of correct/incorrect will not be visible.
    For reference see: Correct / Incorrect Answer Marks
  • show_points (default true)
    This attribute takes effect when using show=”questions_answers”. By default the ‘Points %, Points scored’ will be included under every question and answer. If the show_points attribute is included and is set to false or 0, the ‘Points %, Points scored’ will not be visible.
  • question_cat (default false)
    This attribute takes effect when using show=”questions_answers”. If a attribute is present then the question category will be visible.

Additional Attributes: Last Quiz Shortcode

The attributes supported only in [[elc_last_quiz]] shortcode.

  • course_id (default 0)
    Sets or overrides the course ID for the scope. Value must be a valid course post ID. If not present or value is 0 ‘all courses’ will be included in the scope.
  • lesson_id (default 0)
    Sets or overrides the lesson ID for the scope. Value must be a valid lesson post ID. If not present or value is 0 ‘all lessons’ will be included in the scope.
  • topic_id (default 0)
    Sets or overrides the topic ID for the scope. Value must be a valid topic post ID. If not present or value is 0 ‘all topics’ will be included in the scope.
  • quiz_id (default 0)
    Sets or overrides the quiz ID for the scope. Value must be a valid quiz post ID. If not present or value is 0 ‘all quizzes’ will be included in the scope.
  • collapsible (default false)
    Wrap the shortcode output in a collapsible element ‘<details>’.
    Refer to: W3Schools  HTML details Tag
    If present the shortcode content will be collapsible. The default label for visible heading ‘<summary>’ of the collapsible element is: View Quiz Statistics. You can specify different label by setting the attribute value, e.g.:
    collapsible=”Click to expand”
  • print_button (default false)
    Insert the printer icon to the right of the summary label (see above). Clicking the printer icon will open the browser’s print dialog. The print preview will show only the content included in the collapsible element. If present the print icon will be visible.
  • show

Breadcrumbs

This value is supported only in [[elc_last_quiz]] shortcode. Output path to the ‘last quiz’ in the form of breadcrumbs.

quiz_title This value is supported only in [[elc_last_quiz]] shortcode. Output the quiz title.

Note: When using the [elc_last_quiz] shortcode the ‘show’ attribute value can be comma (,) delimited list of any combination of allowed values. The list must be enclosed in double-quote characters (“). The sequence of the values will order output vertically (top-to-bottom).

Example: [elc_last_quiz show=”breadcrumbs, timespent, overall_score, questions_answers”]

Reporting Shortcode

To begin using the new reporting option, add the following shortcode below to any page or post. Only “Admin” and “Group Leaders” will be able to see and use the new reporting tool.

Shortcode: [elc_last_quiz_admin_filter]

Reporting Form

When viewing the form on the front-end you will see a search table. After making your selections, Click “Submit” to print a report. Click the settings “Icon” to show or hide specific information from the report. The form displays the quiz results for the last attempt by the student and it returns the result within the scope of course/lesson and/or topic.

Reporting Settings

By default all options are checked and will output all quiz data for a user. If you make any changes, click “Submit” to save your changes. Click the settings “Icon” again if you wish to collapse the settings. In the “Filtering options”, we recommend leaving the “Filter only users who took a quiz” active. This is especially useful to save the load on your server.

If you wish to display the users quiz results in a specific order. Drag and Drop the options in the order you wish. Click “Submit” to save your settings.

Quiz Results Tab

A content tab, or simply a ‘tab’, is an additional panel of information that appears when you click on something related in your course. This could include notes about the lesson topic or helpful tools and links for students.

LearnDash’s ‘Learn Dash Content Tabs Filter’ snippet makes it easy to add these extra resources to your course. Instead of using the materials tab in your course settings, you can use code to dynamically add content tabs. With just a few small adjustments, you can customize the code to fit your needs and streamline the process.

Enhance your quizzes with the ‘Quiz Results’ tab using the modified code below. This snippet, designed for use with the ‘Quiz Notifications for LearnDash Plugin‘, will insert the [elc_last_quiz …] shortcode into every course, lesson, topic, and quiz page, providing an easy way to access quiz results.

When will the ‘Quiz Results’ tab displayed?

After successfully completing a quiz, proceed to the next step and return later to find the ‘Quiz Results’ tab now visible.

How to use the code?

  • Insert the following code in your themes custom functions.php file or use a plugin called “Code snippets”.
  • A basic knowledge of PHP is required to modify the code.                       
/**
 * Example usage for learndash_content_tabs filter.
 * @SEE: https://developers.learndash.com/hook/learndash_content_tabs/
 *
 * This snippet will add the tab with Last Quiz shortcode output on all: course, lesson, topic pages,
 * provided there are quiz results. 
 */
add_filter(
    'learndash_content_tabs',
    function ( $tabs = array(), $context = '', $course_id = 0, $user_id = 0 ) {

        // Add optional logic to show the custom tab only on certain courses.
//        if( 123 !== $course_id ) {
//            return $tabs;
//        }

        // Check if Quiz Notifications for LearnDash plugin is actived.
        if( ! function_exists( 'elc_ldquiz_last_quiz_callback' ) ){
            return $tabs;
        }

        // List of content types to show the Tab and the Last Quiz. 
        // You can comment or uncomment content types for which the tab will be shown. 
        // Below will show the tab on lesson and topic pages only. 
        $elc_context = array(
//            'course',
            'lesson',
            'topic',
        //    'quiz',
        );

        // If this is a post type we want to show Last Quiz, test if there is quiz results to render.
        if( in_array( $context, $elc_context ) ) {
            // Test for timespent only.
            $shortcode_atts = array(
                'show' => "timespent",
            );
            $elc_test = elc_ldquiz_last_quiz_callback( $shortcode_atts );
        }

        // Add our Custom Last Quiz Tab.
        if( ! empty( $elc_test ) && ! isset( $tabs[ 'lastquiz' ] ) ) {
            // show attribute values.
            // The quiz results will be printed in the order as in array.
            $show_ar = array(
                'custom_fields',
                'quiz_title',
                'breadcrumbs',
                'timespent',
                'cat_score',
                'overall_score',
                'result_message',
                'questions_answers',
            );

            // Last Quiz shortcode attributes.
            // Default values for parameters: 
            //             'collapsible'     => false,
            //             'show_essay'      => false,
            //             'comments'        => false,
            //             'show_correct'    => true,
            //             'show_points'     => true,
            //             'answer_feedback' => false,
            //             'question_cat'    => false,
            //             'breadcrumbs'     => false,
            //             'print_button'    => false,
            //
            $shortcode_atts = array(
                'show' => implode( ',', $show_ar ),
                'question_cat',
                'show_essay',
                'comments',
                'answer_feedback' => true,
                'show_points' => false,
            );

            // Get the HTML Last Quiz results.
            $elc_content = elc_ldquiz_last_quiz_callback( $shortcode_atts );

            // For print button uncomment line below.
            $elc_content = elc_ldquiz_print_callback( '', $elc_content );

            $tabs[ 'lastquiz' ] = array(
                'id'      => 'lastquiz',
                // The value here is to a CSS class you control to show an icon.
                'icon'    => 'ld-downloads-icon',
                'label'   => 'Quiz Results',
                'content' => $elc_content,
            );
        }

        // Always return $tabs.
        return $tabs;
    },
    30,
    4
);
Scroll to Top