Using this tip we can record unit time for a student in a custom post meta field.
We’re going to use the action hook : wplms_before_every_unit for this purpose.
Add following code in WPLMS Customizer plugin -> customizer_class.php file:
1. Go to WP Admin -> Plugins -> editor -> wplms customizer -> customizer_class.php
2. Add following line of code in _construct file:
PHP Code:
add_action('wplms_before_every_unit',array($this,'track_unit_start_time'),10,1);
3. Add this function in class :
PHP Code:
function track_unit_start_time($unit_id){ if(is_user_logged_in()){ $user_id = get_current_user_id(); $key = 'unit_start_time'.$unit_id; $check_exists = get_user_meta($user_id, $key,true); if(!isset($check_exists) || !is_numeric($check_exists)) add_user_meta($user_id,$key,time()); } }
Above code records the timestamp when the user “First” views a unit.