Open last viewed unit

Home Forums Legacy Support Support queries Other issues Open last viewed unit

Viewing 15 posts - 16 through 30 (of 35 total)
  • Author
    Posts
  • #229502
    LuizBra
    Participant
    Hi MK, thanks a lot! I had a vacation, so I didn't use the plugin yet. Can I kindly ask you instead of a plugin to give me a code so I can put it in the functions.php ? Or is it a lot of additional work? Sorry for the confusion, next time I'll try to let you know that in advance
    #229563
    logan
    Member
    Hello, if you put this into the functions.php. after updating the theme, it will be gone forever. that's why we build a plugin. its size is 5kb and it will not increase the server load. this is the sophisticate and significant way to achieve the required desires.
    #229627
    LuizBra
    Participant
    Hi Logan, sorry but what if I use it via my child theme? That would do the trick, right?
    #229717
    Mk
    Moderator
    I can add code to your customizer. but we will have to test it again. tell me if you agree. thank you.
    #229723
    LuizBra
    Participant
    Thanks a lot! Yeah that would be great. You could just provide the code after a testing. How much shall I pay you for that?
    #229779
    Mk
    Moderator
    Thank you for your offer but we charge for logic and time spent. In your case, we have already written logic so no need to pay and in case of time spent I don't think it will take more time to add in customizer.
    I will complete it on monday. thank you.  
    #230024
    LuizBra
    Participant
    Thank you very much!
    #230040
    Mk
    Moderator
    hey this is the code: add_filter('wplms_get_course_unfinished_unit','load_unit'); add_filter('wplms_get_course_unfinished_unit_key','unit_key',10,3); add_action('wp_footer','script_to_save_last_unit'); add_action('wp_ajax_save_last_viewed_unit','save_last_viewed_unit' );   function script_to_save_last_unit(){     //checking its course status page or not     $page_id = vibe_get_option('take_course_page');     if(!is_page($page_id))         return;       ?>             jQuery(document).ready(function($){             $('.unit_content').on('unit_traverse',function(){                 var unit_id = $('.unit_line.active');                 var course_id = $("input[name=no_ajax_course_id]").val();                 if(typeof unit_id !== 'udefined' && unit_id){                     var last_unit = unit_id.find('a').data('unit');                     //make ajax hit to store this current unit id for the user in usermeta for this course                     //meta_key: current_unit.{course_id} meta_value: unit_id                     $.ajax({                         type: "POST",                         url: ajaxurl,                         data: { action: 'save_last_viewed_unit',                                  unit_id:last_unit,                                 course_id:course_id,                                 hash: $('#hash').val(),                         },                         cache: false,                         success: function(response){                             console.log(response);                         }                     });                 }             });         });         <?php }   function save_last_viewed_unit(){          if ( !isset($_POST['hash']) || !wp_verify_nonce($_POST['hash'],'security') || !is_numeric($_POST['unit_id']) || !is_numeric($_POST['course_id'])){         _e('Security check Failed. Contact Administrator.','wplms-last-unit');         die();     }       $user_id = get_current_user_id();     $meta_key = 'current_unit_'.$_POST['course_id'];     $meta_value = $_POST['unit_id'];       update_user_meta( $user_id, $meta_key, $meta_value);     die();   }   function load_unit($unit_id){       $user_id = get_current_user_id();     $course_id = $_POST['no_ajax_course_id'];       $last_viewed_unit = get_user_meta($user_id, 'current_unit_'.$course_id, true);       if(empty($last_viewed_unit))         return $unit_id;       $uid= $last_viewed_unit;     if ( !isset($_POST['hash']) || !wp_verify_nonce($_POST['hash'],'security') || !is_numeric($uid) || !is_numeric($course_id)){         _e('Security check Failed. Contact Administrator.','wplms-last-unit');         die();       }else{           $units = bp_course_get_curriculum_units($course_id);          if(in_array($uid,$units)){               return $uid;           }       }     return $unit_id; }   function unit_key($key,$unit_id,$course_id){     $user_id = get_current_user_id();     $last_viewed_unit = get_user_meta($user_id, 'current_unit_'.$course_id, true);       if(!empty($last_viewed_unit)) {         $unit_id = $last_viewed_unit;     }     $units = bp_course_get_curriculum_units($course_id);     $key = array_search($unit_id,$units);     $key++;       return $key; }
    I already have added code in customizer. please verify code and reply to us its working or not.  
    #230531
    LuizBra
    Participant
    Thank you! I put the code to the functions.php and it doesn't have any effect for some reason
    #230605
    Mk
    Moderator
    Thanks for replying. I will need to check it again. it was working on my end. I will reply to you. Thank you.
    #230732
    LuizBra
    Participant
    This reply has been marked as private.
    #230766
    Mk
    Moderator
    Please check the above plugin is working perfectly. Refer: http://somup.com/cq6r1LeWp5
    If it's not working at your end it means it has some conflict with other plugin or with any custom code in customizer.
    In the above-given code for adding in the customizer, some code was removed by the editor. I am adding a gist for it. https://gist.github.com/99manish/7926f77c1488f7316618f419f94b788a try adding this code to your customizer. if it's not working please try by removing all other customizer codes.
    #230788
    LuizBra
    Participant
    Hi MK, thanks a lot! I'm not talking about the code in the customizer. To be honest we don't even use the customizer plugin in our website. I'm talking about the plugin "wplms-last-unit-addon"  that you created. Let's make it work first and the decide how to implement the code though the functions.php I tried your plugin on my website. Have you seen it yourself?
    #230821
    Mk
    Moderator
    Hi LuizBra, thanks for replying! I checked on my setup and replied in the last video that how my plugin is working. Please have a look: http://prntscr.com/pm7wfg
    If you want me to check in your setup then I will need some help -> please create a new course with a min of 3 4 units and test. if still not working share newly created course details.  
    #230822
    LuizBra
    Participant
    This reply has been marked as private.
Viewing 15 posts - 16 through 30 (of 35 total)
  • The topic ‘Open last viewed unit’ is closed to new replies.