Last active
September 6, 2018 06:38
-
-
Save arsalan13nov/bd3c8e5aa074b89d43669efc958b1642 to your computer and use it in GitHub Desktop.
Reset Course Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fetch the users from the CSV | |
$file = fopen('report.csv', 'r'); | |
while(! feof($file)) | |
{ | |
$v = fgetcsv($file); //print_r(fgetcsv($file)); | |
$user_ids[] = $v[0]; | |
} | |
// Remove duplicates | |
$user_ids = array_unique( $user_ids ); | |
// Remove 1st records which contains column name | |
array_shift($user_ids); | |
fclose($file); | |
//var_export( $user_ids ); | |
// Loop through all the users | |
foreach( $user_ids as $u_id ){ | |
$user_meta = get_user_meta( $u_id, '_sfwd-course_progress', true ); | |
// Remove course history of "Service Advisor Traning" | |
if( isset( $user_meta[1472] ) ) | |
unset( $user_meta[1472] ); | |
// Remove course history of "Service Manager University" | |
if( isset( $user_meta[1473] ) ) | |
unset( $user_meta[1473] ); | |
delete_user_meta( $u_id, 'course_completed_1472' ); | |
delete_user_meta( $u_id, 'course_completed_1473' ); | |
// Reset user progress | |
update_user_meta( $u_id, '_sfwd-course_progress', $user_meta ); | |
$user_quiz_meta = get_user_meta( $u_id, '_sfwd-quizzes', true ); | |
foreach( $user_quiz_meta as $key => $quiz_meta ){ | |
if( $quiz_meta['course'] == 1472 || $quiz_meta['course'] == 1473 ) | |
unset( $user_quiz_meta[$key] ); | |
} | |
// Reset Quiz progress | |
update_user_meta( $u_id, '_sfwd-quizzes', $user_quiz_meta ); | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment