Tips on how to debug LearnDash - createIT
Get a free advice now!

    Pick the topic
    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.

    Tips on how to debug LearnDash

    January 17, 2023
    Last update: February 10, 2023
    4 min read
    30
    0
    0
    Tips on how to debug LearnDash

    Challenge: see the logs of all events triggered by the LearnDash e-learning WordPress plugin

    Solution: enable LEARNDASH_QUIZ_DEBUG in wp-config.php

    LMS (Learning Management System) WordPress plugins have gained popularity in the last few years. The most popular one is LearnDash, a premium plugin for creating e-learning courses. The administrator can create lessons, topics, quizzes, assignments and certificates.

    The plugin has so many configuration options that first-time users can be overwhelmed with the initial setup. If we take into consideration the installed add-ons that extend the capability of LearnDash, it’s useful to know which events are triggered.

    LearnDash problems

    Website owners that have e-learning courses running sometimes experience issues with configuration or have difficulties with fixing bugs. Common problems reported by plugin users are:

    – users are not enrolled to new courses

    – completing a quiz does not save lesson progress

    – the leaderboard contains incorrect date format

    – scheduled courses do not start

    – installed add-on displays an error

    LearnDash Debug Mode

    The recommended first step is to enable the LearnDash debug mode. You will see all the events in the system with additional parameters. Logs of events are saved in the file and updated in real time.

    To enable reporting and saving logs to a file, we need to add one line to wp-config.php :

    /* wp-config.php */
    
    define('LEARNDASH_QUIZ_DEBUG', true);

    The log file will be saved in: /wp-content/uploads/learndash/debug/

    Log file names will look like this: ld_debug_quiz_DATE_USERID_QUIZID.log

    where:

    DATE – date of log creation

    USERID – user_id that is logged to the session and is taking the course

    QUIZID – quiz_id of the quiz that the user is trying to solve

    example: ld_debug_quiz_20220714_438215_392032.log

    LearnDash Development

    The LearnDash plugin is a really powerful Learning Management System. The WordPress site with a properly configured plugin becomes an e-learning platform. Owners of LMS websites sometimes struggle with proper configuration or need help with customization.

    We have supported several projects with LearnDash integration. Some of the problems we helped solved where:

    • user X can’t complete the course. We need to check what the issue is
    • user Y can’t generate a certificate after completing a course
    • we have over 10000 questions in quizzes, and over 2000 of them have missing answers. We need to check old backups and retrieve the missing answers.
    • A WordPress user has been deleted, which caused some LearnDash content to be erased. We need to reimport the missing content
    • SCORM quiz does not work with LearnDash, we need custom integration
    • the date saved in quiz progress is incorrect, we need a fix
    • the LearnDash plugin slows down the entire website, we need to improve speed performance
    • we have an old LearnDash version and need to migrate data to the newest version
    • we have a multisite LearnDash installation, and we decided to migrate it to a single WordPress site
    • a third-party plugin for LearnDash does not work correctly, we need to figure out how to set it up correctly / fix the plugin source code
    • our theme is not compatible with the current version of LearnDash, we need to introduce new template layouts and styling
    • usermeta _sfwd-quizzes is malformed, we need to find the cause and fix the data
    • we need to prepare a custom report with a list of all questions and answers (multisite installation)
    • when submitting quiz answers, nonce validation is failing, causing results to be not saved in the database

    In most issues, having the ability to read LearnDash logs is really helpful. When fixing a bug, seeing the list of all quiz events can save a lot of time.

    Debugging LearnDash

    The ability to debug Quizzes in LearnDash has been introduced in version 3.2.3. It shows a lot of useful information, including events that are triggered when the user is trying to solve the quiz.

    The Quiz is the most complicated part of the LMS system. The logic for saving scores, grading answers and applying quiz settings logic is really advanced. Seeing logs can be a life saver and can help a lot during custom LearnDash development or during bug fixing.

    Here is an example log with triggers’ details:

    2022-07-14 14:06:42 - 0 - Browser version: WordPress/5.9.3; http://www.example.com
    2022-07-14 14:06:42 - 0 - ---------------------------------
    2022-07-14 14:06:42 - 0 - in completedQuiz
    2022-07-14 14:06:42 - 0 - _POST<pre>Array
    (
        [action] => wp_pro_quiz_completed_quiz
        [course_id] => 392013
        [lesson_id] => 392024
        [topic_id] => 392030
        [quiz] => 392032
        [quizId] => 435
        [results] => Array
            (
                [3082] => Array
                    (
                        [time] => 7
                        [points] => 0
                        [p_nonce] => ae9b00618f
                        [correct] => 0
                        [data] => Array
                            (
                                [0] => 0
                                [1] => 1
                                [2] => 0
                            )
                        [a_nonce] => 356652bd55
                        [possiblePoints] => 1
                    )
                [3083] => Array
                    (
                        [time] => 2
                        [points] => 1
                        [p_nonce] => 14d3614922
                        [correct] => 1
                        [data] => Array
                            (
                                [0] => 0
                                [1] => 1
                                [2] => 0
                            )
                        [a_nonce] => e67535fdb2
                        [possiblePoints] => 1
                    )
                [3084] => Array
                    (
                        [time] => 2
                        [points] => 0
                        [p_nonce] => db070f0878
                        [correct] => 0
                        [data] => Array
                            (
                                [0] => 0
                                [1] => 1
                                [2] => 0
                            )
                        [a_nonce] => 9aefb645c2
                        [possiblePoints] => 1
                    )
                [3085] => Array
                    (
                        [time] => 2
                        [points] => 1
                        [p_nonce] => f7787a3126
                        [correct] => 1
                        [data] => Array
                            (
                                [0] => 0
                                [1] => 1
                                [2] => 0
                            )
                        [a_nonce] => 9066ac7d49
                        [possiblePoints] => 1
                    )
                [3086] => Array
                    (
                        [time] => 10
                        [points] => 1
                        [p_nonce] => 57ae3a90ce
                        [correct] => 1
                        [data] => Array
                            (
                                [0] => 0
                                [1] => 1
                                [2] => 0
                            )
                        [a_nonce] => c44f624ac6
                        [possiblePoints] => 1
                    )
                [3087] => Array
                    (
                        [time] => 2
                        [points] => 0
                        [p_nonce] => 97bbc8ac03
                        [correct] => 0
                        [data] => Array
                            (
                                [0] => 0
                                [1] => 1
                                [2] => 0
                            )
                        [a_nonce] => 14279751cd
                        [possiblePoints] => 1
                    )
                [comp] => Array
                    (
                        [points] => 3
                        [correctQuestions] => 3
                        [quizTime] => 37
                        [quizEndTimestamp] => 1657800422119
                        [quizStartTimestamp] => 1657800402118
                        [result] => 50
                        [cats] => Array
                            (
                                [0] => 50
                            )
                    )
            )
        [timespent] => 36.791
        [quiz_nonce] => b5ba1d4544
    )
    </pre>
    2022-07-14 14:06:42 - 0 - user_id 0
    2022-07-14 14:06:42 - 0 - quiz id 435
    2022-07-14 14:06:42 - 0 - quiz_post_id 392032
    2022-07-14 14:06:42 - 0 - Verifying submitted results
    2022-07-14 14:06:42 - 0 - [3082] result<pre>Array
    (
        [time] => 7
        [points] => 0
        [p_nonce] => ae9b00618f
        [correct] => 0
        [data] => Array
            (
                [0] => 0
                [1] => 1
                [2] => 0
            )
        [a_nonce] => 356652bd55
        [possiblePoints] => 1
    )
    </pre>
    2022-07-14 14:06:42 - 0 - invalid points nonce (p_nonce). Clearing points values.
    2022-07-14 14:06:42 - 0 - response_str [a:3:{i:0;s:1:"0";i:1;s:1:"1";i:2;s:1:"0";}]
    2022-07-14 14:06:42 - 0 - invalid answer nonce (a_nonce). Clearing answer/response values.
    2022-07-14 14:06:42 - 0 - [3083] result<pre>Array
    (
        [time] => 2
        [points] => 1
        [p_nonce] => 14d3614922
        [correct] => 1
        [data] => Array
            (
                [0] => 0
                [1] => 1
                [2] => 0
            )
        [a_nonce] => e67535fdb2
        [possiblePoints] => 1
    )
    </pre>
    

    That’s it for today’s guidelines. Be sure to subscribe to our newsletter to stay up to date on other useful tips and tutorials.

    Support – Tips and Tricks
    All tips in one place, and the database keeps growing. Stay up to date and optimize your work!

    Contact us