was successfully added to your cart.

Password Protecting LearnDash Generated Elements – A Client Case Study

By 2nd June 2017 June 7th, 2017 Learning Management System Development

At Discover eLearning, we work with clients based all around the world to help them fit the robust LearnDash LMS platform into their workflows.

We recently had the pleasure of working with a US based client who were looking to develop a platform for both the delivery of course content and the facilitation of formal examinations at the end of each course.

Because of the vast array of features that are built into LearnDash’s Quizzing options, we were able to create the exact environment that the client were looking to build at the time, but due to the strict rules regarding exam facilitation (for home-based learners), it was necessary for a third-party proctoring organisation to be involved during the month that exams were scheduled to run…

It was decided that the best way to protect the exam was to password protect access so that it could only be started as soon as the online proctor had performed their initial checks and were satisfied that the learner was ready to start. As a side note, the timed release feature of Lesson/Topic pages was also considered, but because each learner may be taking the exam on a different date and time it seemed best to give the power to commence the examination completely to the Proctor.

At first this didn’t seem to be a big issue, as there is already a Password Protected option when it comes to publishing a post/page in WordPress. What we discovered in the case of our client’s theme however, and also our own demo site theme which I have used to take the screenshots below, was that the LearnDash generated elements such as the link to access the quiz on the lesson page was being rendered separately from the page content, and by default it appeared that the password protect option is designed to only protect everything governed by ‘the_content()’ WordPress function. Things like LearnDash link boxes, assignment upload boxes and Mark Complete buttons do not always fall under this function:

Password Protected

The Password Protected option also works for Custom Post Types in WP

This screenshot shows how the quiz associated with this Lesson page is still visible despite the fact the page content has been Password Protected. Apparently this will not be the case in every theme, as some may render LD elements as part of ‘the_content()’.

The Solution

In order to fix this problem we need to go into the PHP files of the LearnDash LMS plugin in order to make some changes, but first we would make a copy of the LearnDash plugin Template folder into the root folder of our theme, so that if we update LearnDash in the future we will not lose any of our changes. The file that we are working with in this case is the lesson.php file contained within the Templates folder (that we just copied over). This file contains the code block that renders the quiz link box onto the page if there is a quiz associated to that lesson:

The new code required is highlight in the red box.

As you can see, there is already an IF statement associated with this code block to say that the learndash_quizzes div tag should not be rendered if there is no quiz associated with the lesson. Thankfully WordPress already provides a function that we can use to check whether the Password Protected option has been set within the publishing options of the page, this is post_password_required(). So all we need to do is include this function as part of the IF statement! So if we now return to our page, this is what we see:

Job Done! The thing to remember is that if you also want to password protect the same element on Course and Topic pages then you would also need to open the course.php and topic.php files and look for the same code block.

Chris Hodgson

About Chris Hodgson

Chris Hodgson is a Digital learning Solutions Developer and Director of Discover eLearning Ltd. He supports SMEs and large firms through the process of integrating eLearning into their organisation. Chris has over 10 years experience working in Higher Education, Independent Training Provider Sector and Charity Sector learning and development.

2 Comments

  • Finn says:

    Interesting.

    I tried to use this in order to force entry of password when accessing a quiz directly via a URL. However, I couldn’t make it work.

    I entered the above code snip in course.php, but that didn’t really change a bit. The question about the password was presented, but you could start the quiz even without entering the password.

    • Chris Hodgson says:

      Finn,
      The purpose of this post was to highlight how the LearnDash generated course contents box can be hidden from view using the password protected post feature, if the theme that you are using does not automatically hide this block when the password protected option is turned on.
      What you have described is a different issue that would need to be mitigated separately – If a user has the direct URL to a quiz within LearnDash there would be nothing stopping that person from navigating to that page, but you would be able to restrict access to starting the quiz if the user has not already conducted the prerequisites. So for example, if you were to assign the quiz to a course with so many lessons then the user could not gain access to that quiz until all lessons had been completed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.