Upgrading wplms version from 1.9 or less to 2.0

UPDATE : NO LONGER REQUIRED. SIMPLY UPDATE THE THEME & PLUGINS AND GO TO WP ADMIN – LMS – SETTINGS – FUNCTIONS – RESYNC ALL THE OPTIONS

Please update your wplms theme,all its plugins (alongwith buddypress) ,modern child theme to latest version 2.0.7 or above.
Latest Modern child theme  is available in wplms package .

Now after upgrade you may face issue with the course admin -> members tab .
It will not list the members of course (users who are subscribed to course) .

this issue appears due to the change in architecture of wplms from 1.9 or less to 2.0 .
Now we set a user meta for the course and check this user meta to check if user is added to course or not  .
Previously this new user meta was not set and therefore users who migrate from 1.9 or less to 2.0 may face this issue  .

To get it resolved please add the given code in your wplms-customizer.php file at the end before ” ?> ” in wplms customizer plugin :

add_action('init','wplms_course_migration');
function wplms_course_migration(){

    global $wpdb;
    $ids=$wpdb->get_results("SELECT ID from {$wpdb->posts} WHERE post_type='course'");
    foreach($ids as $id){
    	
       $results = $wpdb->get_results($wpdb->prepare("Select p.meta_key as user_id, p.meta_value as user_status from {$wpdb->postmeta} as p LEFT JOIN {$wpdb->usermeta} as u ON p.post_id = u.meta_key WHERE p.post_id='%d' AND u.meta_key='%d' AND p.meta_key = u.user_id AND p.meta_value REGEXP '^[0-9]+$'",$id->ID,$id->ID));
    if(!empty($results)){
        foreach($results as $result){
        	//print_r($result->user_id.'#');
            switch($result->user_status){
                case 0:
                    update_user_meta($result->user_id,'course_status'.$id->ID,1);
                break;
                case 1:
                    update_user_meta($result->user_id,'course_status'.$id->ID,2);
                break;
                case 2:
                    update_user_meta($result->user_id,'course_status'.$id->ID,3);
                break;
                default:
                    update_user_meta($result->user_id,'course_status'.$id->ID,4);
                break;
            }
        }
    }
    }
   
}

And then load you any course page .

This will set the user meta for all your user and user will begin to show in members tab in course admin :
http://prntscr.com/aie1ji

After loading the course page in your site please remove the code from wplms-customizer.php file .

NOTE : Please note that the above code executes a heavy query on server and this may crash your site .
So please test this at your staging site or test site first .

If your site is crashing due to the above code then please ask your students to login and then open thier courses that they are added .
this will also set usermeta for them in that course which they will open if they are subscribed to that course already .

 

Leave a Reply

Your email address will not be published. Required fields are marked *