Home › Forums › Legacy Support › Support queries › Other issues › Open last viewed unit
- This topic has 34 replies, 5 voices, and was last updated 4 years, 6 months ago by Diana.
-
AuthorPosts
-
October 10, 2019 at 7:41 am #229502LuizBraParticipantHi 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 advanceOctober 10, 2019 at 11:48 am #229563loganMemberHello, 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.October 10, 2019 at 2:22 pm #229627LuizBraParticipantHi Logan, sorry but what if I use it via my child theme? That would do the trick, right?October 11, 2019 at 10:12 am #229717MkModeratorI can add code to your customizer. but we will have to test it again. tell me if you agree. thank you.October 11, 2019 at 10:37 am #229723LuizBraParticipantThanks a lot! Yeah that would be great. You could just provide the code after a testing. How much shall I pay you for that?October 11, 2019 at 1:38 pm #229779MkModeratorThank 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.October 14, 2019 at 9:08 am #230024LuizBraParticipantThank you very much!October 14, 2019 at 11:10 am #230040MkModeratorhey 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.October 18, 2019 at 4:43 am #230531LuizBraParticipantThank you! I put the code to the functions.php and it doesn't have any effect for some reasonOctober 18, 2019 at 1:52 pm #230605MkModeratorThanks for replying. I will need to check it again. it was working on my end. I will reply to you. Thank you.October 21, 2019 at 4:08 am #230732LuizBraParticipantThis reply has been marked as private.October 21, 2019 at 7:14 am #230766MkModeratorPlease 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.October 21, 2019 at 8:32 am #230788LuizBraParticipantHi 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?October 21, 2019 at 12:25 pm #230821MkModeratorHi 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.October 21, 2019 at 12:33 pm #230822LuizBraParticipantThis reply has been marked as private. -
AuthorPosts
- The topic ‘Open last viewed unit’ is closed to new replies.