sdwarwick
Forum Replies Created
-
I’ve confirmed that this new hook works as desired, thanks for the sample code. for those reading this, please look to using the new hook rather than the workaround as described in the initial post
yes, this is all about how “get_next_lesson” works and how you deal with what happens if there isn’t a next lesson.
I am actually surprised that this is not a very common concern, but so be it.
I’d be interested in perhaps chatting sometime to discuss the broader use of custom meta variables as an intermediate approach to providing “post level” special processing. I’m using it a lot now.. my “hide mark complete” is activated from a meta variable in the lesson. it seems like a nice low-overhead mechanism for control at the user-interface level. in addition, it doesn’t require tying special processing to a specific post/lesson ID.
@thomasplevy – I’m always grateful for the work you do to make lifter a great product. I see providing specific opportunities for improvement as the most effective way to support those efforts!
I’ll look at a developing a pull request.
you may run into problems with the above code, as get_the_ID() may return an undefined value when sending an ajax call.
so, I have been using something very similar to these concepts for a while now. essentially hid the “mark complete” button and fired the mark_complete form using a jquery “click”
this does two things nicely – registers completion and serves the “next” lesson.
EXCEPT!! the last lesson in the course gets stuck. rather than a default for end-of-course, you just send back the same url. Of course, the second time, the mark complete button is removed since now it is considered a “completed” lesson. but still, users see the last lesson twice, which is a real bummer when it is a final exam!!
you have a very simple opportunity to add a hook in the following code for get next lesson… I am at a loss right now how to deal with this other than literally removing the mark_complete action from init and adding a custom version that provides an end-of-course option. the approach would be to detect a null on next lesson and provide an alternative
public function get_next_lesson() { $parent_section = $this->get_parent_section(); $current_position = $this->get_order(); $next_position = $current_position + 1; $args = array( 'posts_per_page' => 1, 'post_type' => 'lesson', 'nopaging' => true, 'post_status' => 'publish', 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_llms_parent_section', 'value' => $parent_section, 'compare' => '=', ), array( 'key' => '_llms_order', 'value' => $next_position, 'compare' => '=', ) ), ); $lessons = get_posts( $args ); //return the first one even if there for some crazy reason were more than one. if ( $lessons ) { return $lessons[0]->ID; } else { // See if there is another section after this section and get first lesson there $parent_course = $this->get_parent_course(); $cursection = new LLMS_Section( $this->get_parent_section() ); $current_position = $cursection->get_order(); $next_position = $current_position + 1; $args = array( 'post_type' => 'section', 'posts_per_page' => 500, 'meta_key' => '_llms_order', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_llms_parent_course', 'value' => $parent_course, 'compare' => '=', ), array( 'key' => '_llms_order', 'value' => $next_position, 'compare' => '=', ) ), ); $sections = get_posts( $args ); if ( $sections ) { $newsection = new LLMS_Section( $sections[0]->ID ); $lessons = $newsection->get_children_lessons(); if ( $lessons ) { return $lessons[0]->ID; } else { return false; } } else { return false; // no! no! no!! } } }- This reply was modified 9 years, 2 months ago by sdwarwick.
Lifterlms has an extensive “prerequisite” system so that you can set up a final lesson that acknowledges completion of the prior lessons. Are you using that?
Not sure exactly what you are looking for, however I do believe that if you have the ability to add an additional “lesson” page to your site after the quiz, it is possible to add a very small function that looks for a tag on that page and redirects immediately to another page on the site.
since lifter naturally moves to the next lesson in a course, putting this page at the end would enable the desired behavior.
Forum: Plugins
In reply to: [LifterLMS - WP LMS for eLearning, Online Courses, & Quizzes] Cloning course?Any chance of extending that capability to cloning individual Lessons?
this may not seem a needed item on initial look, however I’ve got lessons with a lot of configuration.
no comments
xapi settings
special variables set
prerequisites
etc..it would be nice to start each lesson off from the last one.
Here is something I came up with – would appreciate a review/comment
add_action( 'llms_user_removed_from_course', 'clear_enrollment_data', 10, 2 ); function clear_enrollment_data($uid, $product_id) { global $wpdb; $course = new LLMS_Course( $product_id); $lessons = $course->get_lessons( 'ids' ); foreach ($lessons as $lesson) { $update = $wpdb->delete( $wpdb->prefix . 'lifterlms_user_postmeta', array( 'user_id' => $uid, 'post_id' => $lesson ), array( '%d', '%d' ) ); } return; };try that again:
// auto-enroll in specific course called Improve IT add_action('lifterlms_user_registered', 'addUserToCourse', 10, 1); function addUserToCourse($personID) { $postTypes = array('post_type'=>'course','meta_key'=>'autoEnroll','meta_value' =>'true'); $postList = get_posts($postTypes); foreach ($postList as $post) { llms_enroll_student( $personID, $post->ID, 'registered' ) ; } };For folks interested in this kind of behavior, here is what I ended up doing. I add a “Custom Field” to courses that I want auto enrolled with the key “autoEnroll” and the value “true”
when someone registers, all courses with that field are auto-enrolled.
the following is added to functions.php :
// auto-enroll in specific course add_action('lifterlms_user_registered', 'addUserToCourse', 10, 1); function addUserToCourse($personID) { $postList = array('post_type'=>'course','meta_key'=>'autoEnroll','meta_value' =>'true'); foreach ($postList as $post) { llms_enroll_student( $personID, $post->ID, 'registered' ) ; } }Note that I do not check to see if the person is already enrolled on the assumption that newly registered people are not enrolled in anything by default.
This is perfect!
Thanks for the recommended hook as well.
For Lifterlms!
Forum: Themes and Templates
In reply to: [Customizr] responsive nav menu behavior broken?Thank you so much for this response. I would not have been able to find this solution without many hours of digging, if at all. If no one has said this recently, your help is so very much appreciated!
I have chosen the second solution, as having the collapsed but active nav is very useful and does not interfere with how the top bar looks.
Is this a bug that ends up as a fix in the next version? if so, how do you handle these two optional behaviors?
Forum: Themes and Templates
In reply to: [Customizr] responsive nav menu behavior broken?Thanks for your response. I am still confused as to how this function should work.
It would seem that under all circumstances when you have scrolled back up and a menu is available, it should function. As it is now, after any scrolling activity the menu never gets reactivated
The only way to get the menu working again is to reload the page, which is not intuitive to users.
Not sure how to even debug this, it would be buried deep in the code